diff options
| -rw-r--r-- | diceparser.cpp | 30 | ||||
| -rw-r--r-- | diceparser.h | 5 | ||||
| -rw-r--r-- | parsingtoolbox.cpp | 17 | ||||
| -rw-r--r-- | parsingtoolbox.h | 1 |
4 files changed, 29 insertions, 24 deletions
diff --git a/diceparser.cpp b/diceparser.cpp index 08f3110..fbf473a 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -123,15 +123,7 @@ DiceParser::~DiceParser() m_start = nullptr; } } -ExecutionNode* DiceParser::getLatestNode(ExecutionNode* node) -{ - ExecutionNode* next = node; - while(nullptr != next->getNextNode() ) - { - next = next->getNextNode(); - } - return next; -} + QString DiceParser::convertAlias(QString str) { for(DiceAlias* cmd : *m_aliasList) @@ -176,13 +168,13 @@ bool DiceParser::parseLine(QString str) if(keepParsing) { m_current->setNextNode(newNode); - m_current = getLatestNode(m_current); + m_current = ParsingToolBox::getLatestNode(m_current); keepParsing =!str.isEmpty(); if(keepParsing) { // keepParsing = readOperator(str,m_current); - m_current = getLatestNode(m_current); + m_current = ParsingToolBox::getLatestNode(m_current); } } @@ -232,10 +224,10 @@ bool DiceParser::readExpression(QString& str,ExecutionNode* & node) } node = operandNode; - operandNode= getLatestNode(operandNode); + operandNode= ParsingToolBox::getLatestNode(operandNode); while(readOperator(str,operandNode)) { - operandNode= getLatestNode(operandNode); + operandNode= ParsingToolBox::getLatestNode(operandNode); }; } else if(readCommand(str,operandNode)) @@ -698,7 +690,7 @@ bool DiceParser::readDice(QString& str,ExecutionNode* & node) ExecutionNode* current = drNode; while(readOption(str,current)) { - current = getLatestNode(current); + current = ParsingToolBox::getLatestNode(current); } return true; } @@ -717,7 +709,7 @@ bool DiceParser::readDice(QString& str,ExecutionNode* & node) ExecutionNode* current = drNode; while(readOption(str,current)) { - current = getLatestNode(current); + current = ParsingToolBox::getLatestNode(current); } return true; } @@ -897,7 +889,7 @@ bool DiceParser::readOperator(QString& str,ExecutionNode* previous) { while(readOption(str,previous)) { - previous = getLatestNode(previous); + previous = ParsingToolBox::getLatestNode(previous); } } return false; @@ -1260,13 +1252,15 @@ bool DiceParser::readOperand(QString& str,ExecutionNode* & node) if(m_parsingToolbox->readDynamicVariable(str,intValue)) { VariableNode* variableNode = new VariableNode(); - variableNode->setIndex(intValue); + variableNode->setIndex(intValue-1); + variableNode->setData(&m_startNodes); + node = variableNode; + return true; } else if(m_parsingToolbox->readNumber(str,intValue)) { NumberNode* numberNode = new NumberNode(); numberNode->setNumber(intValue); - node = numberNode; return true; } diff --git a/diceparser.h b/diceparser.h index 6c9915d..f55d7b6 100644 --- a/diceparser.h +++ b/diceparser.h @@ -256,11 +256,6 @@ private: */ bool readOperator(QString&,ExecutionNode* previous); /** - * @brief setCurrentNode - * @param node - */ - ExecutionNode* getLatestNode(ExecutionNode* node); - /** * @brief DiceParser::readCommand * @param str * @param node diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp index 4c7962e..5da06fc 100644 --- a/parsingtoolbox.cpp +++ b/parsingtoolbox.cpp @@ -295,7 +295,7 @@ Validator* ParsingToolBox::readCompositeValidator(QString& str) bool ParsingToolBox::readLogicOperation(QString& str,CompositeValidator::LogicOperation& op) { QString longKey; - foreach(QString tmp, m_logicOperation->keys()) + for(auto const& tmp : m_logicOperation->keys()) { if(str.startsWith(tmp)) { @@ -350,6 +350,7 @@ bool ParsingToolBox::readDynamicVariable(QString& str, qint64& index) return false; if(str.startsWith('$')) { + str=str.remove(0,1); QString number; int i=0; while(i<str.length() && (str[i].isNumber())) @@ -368,6 +369,20 @@ bool ParsingToolBox::readDynamicVariable(QString& str, qint64& index) } return false; } + +ExecutionNode* ParsingToolBox::getLatestNode(ExecutionNode* node) +{ + if(nullptr == node) + return nullptr; + + ExecutionNode* next = node; + while(nullptr != next->getNextNode() ) + { + next = next->getNextNode(); + } + return next; +} + bool ParsingToolBox::readString(QString &str, QString& strResult) { if(str.isEmpty()) diff --git a/parsingtoolbox.h b/parsingtoolbox.h index 8328dc8..0775003 100644 --- a/parsingtoolbox.h +++ b/parsingtoolbox.h @@ -188,6 +188,7 @@ public: static IfNode::ConditionType readConditionType(QString &str); bool readComment(QString& str, QString &,QString &); + static ExecutionNode *getLatestNode(ExecutionNode *node); private: QMap<QString,BooleanCondition::LogicOperator>* m_logicOp; |