diff options
| author | 2018-12-09 14:37:57 +0100 | |
|---|---|---|
| committer | 2018-12-09 14:37:57 +0100 | |
| commit | 55958fa78624b1bd9c713482337090beb106f8ba (patch) | |
| tree | 4477e29900708700e6864792bbce88168d39d18f /diceparser.cpp | |
| parent | 3109e5e63c01607545cd9f22e375cd7b4f245b85 (diff) | |
| download | OneRoll-55958fa78624b1bd9c713482337090beb106f8ba.tar.gz OneRoll-55958fa78624b1bd9c713482337090beb106f8ba.zip | |
Fix issue on command like this: ((3+4)*2)d6
readOperator method now use ref on pointer (as all the others).
To be TESTED
Diffstat (limited to 'diceparser.cpp')
| -rw-r--r-- | diceparser.cpp | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/diceparser.cpp b/diceparser.cpp index 3e90fe8..2508f41 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -195,10 +195,15 @@ bool DiceParser::readExpression(QString& str,ExecutionNode* & node) if(m_parsingToolbox->readCloseParentheses(str)) { ExecutionNode* diceNode=nullptr; - if(readDice(str,diceNode)) + ExecutionNode* operatorNode=nullptr; + if(readDice(str, diceNode)) { parentheseNode->setNextNode(diceNode); } + else if(readExpression(str,operatorNode)) + { + parentheseNode->setNextNode(operatorNode); + } return true; } } @@ -213,8 +218,10 @@ bool DiceParser::readExpression(QString& str,ExecutionNode* & node) node = operandNode; operandNode= ParsingToolBox::getLatestNode(operandNode); - while(readOperator(str,operandNode)) + ExecutionNode* operatorNode=nullptr; + while(readOperator(str,operatorNode)) { + operandNode->setNextNode(operatorNode); operandNode= ParsingToolBox::getLatestNode(operandNode); }; return true; @@ -234,6 +241,11 @@ bool DiceParser::readExpression(QString& str,ExecutionNode* & node) node = operandNode; return true; } + else if(readOperator(str,operandNode)) + { + node = operandNode; + return true; + } else { ExecutionNode* diceNode=nullptr; @@ -850,7 +862,9 @@ bool DiceParser::readInstructionList(QString& str) keepParsing =!str.isEmpty(); if(keepParsing) { - readOperator(str,latest); + ExecutionNode* operatorNode = nullptr; + if(readOperator(str,operatorNode)) + latest->setNextNode(operatorNode); latest = ParsingToolBox::getLatestNode(latest); } } @@ -878,9 +892,9 @@ bool DiceParser::readInstructionList(QString& str) return hasInstruction; } -bool DiceParser::readOperator(QString& str,ExecutionNode* previous) +bool DiceParser::readOperator(QString& str,ExecutionNode*& nodeResult) { - if(str.isEmpty() || nullptr == previous) + if(str.isEmpty() /*|| nullptr == previous*/) { return false; } @@ -923,8 +937,8 @@ bool DiceParser::readOperator(QString& str,ExecutionNode* previous) nodeExec->setNextNode(nullptr); } - - previous->setNextNode(node); + nodeResult = node; + //previous->setNextNode(node); return true; } @@ -933,13 +947,13 @@ bool DiceParser::readOperator(QString& str,ExecutionNode* previous) delete node; } } - else + /* else { while(readOption(str,previous)) { previous = ParsingToolBox::getLatestNode(previous); } - } + }*/ return false; } bool DiceParser::hasSeparator()const |