aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/diceparser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'diceparser.cpp')
-rw-r--r--diceparser.cpp32
1 files changed, 18 insertions, 14 deletions
diff --git a/diceparser.cpp b/diceparser.cpp
index f3ea3ef..902f6ba 100644
--- a/diceparser.cpp
+++ b/diceparser.cpp
@@ -152,7 +152,6 @@ void DiceParser::insertAlias(DiceAlias* dice, int i)
{
m_aliasList->insert(i, dice);
}
-
}
bool DiceParser::parseLine(QString str)
@@ -190,9 +189,10 @@ bool DiceParser::parseLine(QString str)
{
return true;
}
- else if(!m_errorMap.isEmpty())
+ else
{
- m_errorMap.insert(ExecutionNode::NOTHING_UNDERSTOOD,QObject::tr("Nothing was understood"));
+ m_errorMap.insert(ExecutionNode::NOTHING_UNDERSTOOD,QObject::tr("Nothing was understood. To roll dice: !1d6 - full documation:"
+ "https://github.com/Rolisteam/DiceParser/blob/master/HelpMe.md"));
}
return false;
}
@@ -254,6 +254,8 @@ bool DiceParser::readExpression(QString& str,ExecutionNode* & node)
{
NumberNode* numberNode=new NumberNode();
numberNode->setNumber(1);
+ ExecutionNode* previous = diceNode->getPreviousNode();
+ numberNode->setPreviousNode(previous);
numberNode->setNextNode(diceNode);
node = numberNode;
}
@@ -335,7 +337,7 @@ QString DiceParser::displayResult()
QString resulStr;
quint64 face=0;
- foreach(Die* die, myDiceResult->getResultList())
+ for(Die* die : myDiceResult->getResultList())
{
if(!die->hasBeenDisplayed())
{
@@ -347,7 +349,7 @@ QString DiceParser::displayResult()
if(die->hasChildrenValue())
{
resulStr+=QStringLiteral(" [");
- foreach(qint64 i, die->getListValue())
+ for(qint64 i : die->getListValue())
{
resulStr+=QStringLiteral("%1 ").arg(i);
}
@@ -484,7 +486,7 @@ QStringList DiceParser::getAllDiceResult(bool& hasAlias)
{
if(die->isHighlighted())
{
- foreach (qint64 value, die->getListValue())
+ for(qint64 value : die->getListValue())
{
stringListResult << QString::number(value);
@@ -517,7 +519,7 @@ void DiceParser::getLastDiceResult(QList<ExportedDiceResult>& diceValuesList,boo
}
quint64 face=0;
ListDiceResult listpair;
- foreach(Die* die, diceResult->getResultList())
+ for(Die* die : diceResult->getResultList())
{
if(!die->hasBeenDisplayed())
{
@@ -527,7 +529,7 @@ void DiceParser::getLastDiceResult(QList<ExportedDiceResult>& diceValuesList,boo
face = die->getFaces();
if(die->hasChildrenValue())
{
- foreach(qint64 i, die->getListValue())
+ for(qint64 i : die->getListValue())
{
valuesResult.append(i);
}
@@ -565,7 +567,7 @@ QString DiceParser::getDiceCommand() const
bool DiceParser::hasIntegerResultNotInFirst()
{
- bool result;
+ bool result=false;
for(auto node : m_startNodes)
{
result |= hasResultOfType(Result::SCALAR,node);
@@ -575,7 +577,7 @@ bool DiceParser::hasIntegerResultNotInFirst()
bool DiceParser::hasDiceResult()
{
- bool result;
+ bool result=false;
for(auto node : m_startNodes)
{
result |= hasResultOfType(Result::DICE_LIST,node);
@@ -584,7 +586,7 @@ bool DiceParser::hasDiceResult()
}
bool DiceParser::hasStringResult()
{
- bool result;
+ bool result=false;
for(auto node : m_startNodes)
{
result |= hasResultOfType(Result::STRING,node);
@@ -733,7 +735,7 @@ bool DiceParser::readDice(QString& str,ExecutionNode* & node)
bool DiceParser::readDiceOperator(QString& str,DiceOperator& op)
{
QStringList listKey = m_mapDiceOp->keys();
- foreach(QString key, listKey)
+ for(const QString& key : listKey)
{
if(str.startsWith(key,Qt::CaseInsensitive))
{
@@ -829,8 +831,8 @@ bool DiceParser::readOperator(QString& str,ExecutionNode* previous)
{
parent = nodeExecOrChild;
nodeExecOrChild = nodeExecOrChild->getNextNode();
+ //qDebug() << node->getPriority() << nodeExecOrChild->getPriority() << "###########";
}
-
// management of operator priority
if((nullptr != nodeExecOrChild)&&(nodeExec != nodeExecOrChild))
{
@@ -869,6 +871,7 @@ bool DiceParser::readOperator(QString& str,ExecutionNode* previous)
}
previous->setNextNode(nullptr);
m_startNodes.append(nodeExec);
+ auto test = dynamic_cast<DiceRollerNode*>(nodeExec);
m_currentTreeHasSeparator = true;
return true;
}
@@ -921,17 +924,18 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous)//,
{
str=str.remove(0,tmp.size());
- // option = m_OptionOp->value(tmp);
switch(m_OptionOp->value(tmp))
{
case Keep:
{
qint64 myNumber=0;
bool ascending = m_parsingToolbox->readAscending(str);
+
if(m_parsingToolbox->readNumber(str,myNumber))
{
node = m_parsingToolbox->addSort(previous,ascending);
KeepDiceExecNode* nodeK = new KeepDiceExecNode();
+ //qDebug() << "nodeK " << previous->toString(true) << str;
nodeK->setDiceKeepNumber(myNumber);
node->setNextNode(nodeK);
node = nodeK;