diff options
| -rw-r--r-- | diceparser.cpp | 16 | ||||
| -rw-r--r-- | diceparser.h | 2 |
2 files changed, 15 insertions, 3 deletions
diff --git a/diceparser.cpp b/diceparser.cpp index 4a259b2..c94c2b5 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -81,7 +81,6 @@ bool DiceParser::parseLine(QString str) bool keepParsing = readExpression(str,newNode); - while(keepParsing) { m_current->setNextNode(newNode); @@ -94,6 +93,7 @@ bool DiceParser::parseLine(QString str) m_current = getLatestNode(m_current); } return true; + } return false; @@ -152,6 +152,10 @@ bool DiceParser::readExpression(QString& str,ExecutionNode* & node) numberNode->setNextNode(diceNode); node = numberNode; } + else + { + return false; + } } return true; } @@ -160,7 +164,8 @@ void DiceParser::Start() { m_start->run(); } -void DiceParser::displayResult() + +QString DiceParser::displayResult() { ExecutionNode* next = m_start; @@ -240,6 +245,9 @@ void DiceParser::displayResult() out << str << "you rolled: " <<m_command << endl; out << endl; + + return QString("%1, you rolled:%3").arg(str.simplified()).arg(m_command) ; + // qDebug() << "result count:" << resulCount; } @@ -329,6 +337,10 @@ bool DiceParser::readOperator(QString& str,ExecutionNode* previous) if(readExpression(str,nodeExec)) { node->setInternalNode(nodeExec); + if(NULL==nodeExec) + { + return false; + } if(node->getPriority()>=nodeExec->getPriority()) { node->setNextNode(nodeExec->getNextNode()); diff --git a/diceparser.h b/diceparser.h index fb2c647..cf1bfce 100644 --- a/diceparser.h +++ b/diceparser.h @@ -89,7 +89,7 @@ public: /** * @brief displayResult */ - void displayResult(); + QString displayResult(); bool readExpression(QString& str,ExecutionNode* & node); |