From 19bfac5d61c7e30a1e5bbe115d56908474546052 Mon Sep 17 00:00:00 2001 From: Renaud Guezennec Date: Tue, 26 Jan 2016 15:35:18 +0100 Subject: Implementation of the if node. Work with one if. --- diceparser.cpp | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'diceparser.cpp') diff --git a/diceparser.cpp b/diceparser.cpp index 6e63eec..92cd2e1 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -954,7 +954,15 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous, bool hasDice)/ Validator* validator = m_parsingToolbox->readCompositeValidator(str); if(NULL!=validator) { - + ExecutionNode* trueNode; + ExecutionNode* falseNode; + if(readIfInstruction(str,trueNode,falseNode)) + { + nodeif->setInstructionTrue(trueNode); + nodeif->setInstructionFalse(falseNode); + nodeif->setValidator(validator); + previous->setNextNode(nodeif); + } } } @@ -963,6 +971,33 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous, bool hasDice)/ } return isFine; } +bool DiceParser::readIfInstruction(QString& str,ExecutionNode*& trueNode,ExecutionNode*& falseNode) +{ + if(str.startsWith('{')) + { + str=str.remove(0,1); + ExecutionNode* node; + readExpression(str,node); + if(str.startsWith('}')) + { + trueNode = node; + str=str.remove(0,1); + if(str.startsWith('{')) + { + str=str.remove(0,1); + ExecutionNode* node2; + readExpression(str,node2); + if(str.startsWith('}')) + { + falseNode=node2; + return true; + } + } + return true; + } + } + return false; +} QMap DiceParser::getErrorMap() { -- cgit v1.2.3-70-g09d2