diff options
| author | 2015-03-03 22:57:16 +0100 | |
|---|---|---|
| committer | 2015-03-03 22:57:16 +0100 | |
| commit | 9f57feb3052ef74c9ee6aa08b39f04ee61f6839c (patch) | |
| tree | 7628e1e7138d8314f1d87dc939a991dd5cf039ad | |
| parent | d51884f5c6ea38f3bf06b3a0ef185056fa0a7558 (diff) | |
| download | OneRoll-9f57feb3052ef74c9ee6aa08b39f04ee61f6839c.tar.gz OneRoll-9f57feb3052ef74c9ee6aa08b39f04ee61f6839c.zip | |
-store pointeur to previous node.
| -rw-r--r-- | HelpMe.md | 1 | ||||
| -rw-r--r-- | diceparser.cpp | 22 | ||||
| -rw-r--r-- | diceparser.h | 26 | ||||
| -rw-r--r-- | main.cpp | 16 | ||||
| -rw-r--r-- | node/countexecutenode.cpp | 2 | ||||
| -rw-r--r-- | node/dicerollernode.cpp | 1 | ||||
| -rw-r--r-- | node/executionnode.cpp | 4 | ||||
| -rw-r--r-- | node/executionnode.h | 11 | ||||
| -rw-r--r-- | node/explosedicenode.cpp | 1 | ||||
| -rw-r--r-- | node/helpnode.cpp | 1 | ||||
| -rw-r--r-- | node/keepdiceexecnode.cpp | 2 | ||||
| -rw-r--r-- | node/node.pri | 6 | ||||
| -rw-r--r-- | node/numbernode.cpp | 1 | ||||
| -rw-r--r-- | node/parenthesesnode.cpp | 2 | ||||
| -rw-r--r-- | node/rerolldicenode.cpp | 2 | ||||
| -rw-r--r-- | node/scalaroperatornode.cpp | 1 | ||||
| -rw-r--r-- | node/sortresult.cpp | 2 | ||||
| -rw-r--r-- | node/startingnode.cpp | 2 | ||||
| -rw-r--r-- | parsingtoolbox.h | 30 | ||||
| -rw-r--r-- | result.cpp | 4 | ||||
| -rw-r--r-- | result.h | 3 |
21 files changed, 124 insertions, 16 deletions
@@ -1,5 +1,4 @@ [](http://www.rolisteam.org) - # Documentation: ## Irc and Chat diff --git a/diceparser.cpp b/diceparser.cpp index 8dff994..2be2e08 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -53,6 +53,7 @@ DiceParser::DiceParser() m_OptionOp->insert(QObject::tr("r"),Reroll); m_OptionOp->insert(QObject::tr("e"),Explosing); m_OptionOp->insert(QObject::tr("a"),RerollAndAdd); + m_OptionOp->insert(QObject::tr("@"),JumpBackward); @@ -77,6 +78,17 @@ ExecutionNode* DiceParser::getLatestNode(ExecutionNode* node) } return next; } +QString DiceParser::convertAlias(QString str) +{ + foreach(QString cmd, m_aliasMap->keys()) + { + if(str.contains(cmd)) + { + str.replace(cmd,m_aliasMap->value(cmd)); + } + } + return str; +} bool DiceParser::parseLine(QString str) { @@ -85,6 +97,7 @@ bool DiceParser::parseLine(QString str) ExecutionNode* newNode = NULL; m_current = m_start; + str = convertAlias(str); bool keepParsing = readExpression(str,newNode); while(keepParsing) @@ -566,6 +579,10 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous, bool hasDice) isFine = true; } } + case JumpBackward: + { + + } } } @@ -573,6 +590,11 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous, bool hasDice) return isFine; } +QList<ExecutionNode::ERROR_CODE> DiceParser::getErrorList() +{ + return m_start->getErrorList(); +} + bool DiceParser::readOperand(QString& str,ExecutionNode* & node) { int myNumber=1; diff --git a/diceparser.h b/diceparser.h index 81818b9..035c56e 100644 --- a/diceparser.h +++ b/diceparser.h @@ -58,14 +58,14 @@ public: /** * @brief The DiceOperator enum gathering all dice operators */ - enum DiceOperator {D}; + enum DiceOperator {D,L}; /** * @brief The OptionOperator enum gathering all options availables for result. */ - enum OptionOperator {KeepAndExplose,Keep,Reroll,Explosing,Sort,Count,RerollAndAdd}; + enum OptionOperator {KeepAndExplose,Keep,Reroll,Explosing,Sort,Count,RerollAndAdd,JumpBackward}; /** * @brief DiceParser default constructor @@ -135,9 +135,31 @@ private: */ bool readOption(QString&,ExecutionNode* node, bool hasDice = true); + /** + * @brief addRollDiceNode + * @param faces + * @return + */ DiceRollerNode* addRollDiceNode(qint64 faces,ExecutionNode*); + /** + * @brief readOperand + * @param node + * @return + */ bool readOperand(QString&,ExecutionNode* & node); + /** + * @brief DiceParser::convertAlias + * @param str + * @return + */ + QString convertAlias(QString str); + + /** + * @brief getErrorList + * @return + */ + QList<ExecutionNode::ERROR_CODE> getErrorList(); bool readInstructionOperator(QChar c); @@ -36,7 +36,11 @@ int main(int argc, char *argv[]) QStringList commands; - commands<< "5d6;1d10;4d100;3d20";/* + commands<< "3d10c[>=6]-@c[=1]" + << "3d10-@c[>1]" + << "3d10c[>=6]-c[=1]" + << "3d10c[>=5]"; + /*<< "3nwod" << "1+(4*3)D10" << "2+4/4" << "2D10*2D20*8" @@ -46,7 +50,7 @@ int main(int argc, char *argv[]) << "3D100" << "4k3" << "10D10e[>=6]sc[>=6]" - //<< "100190D6666666s" + << "100190D6666666s" << "10D10e10s" << "10D10s" << "15D10e10c[8-10]" @@ -79,8 +83,12 @@ int main(int argc, char *argv[]) myParser->Start(); myParser->displayResult(); } + else + { + qDebug() << "echec"; + } } - //main.show(); - //return a.exec(); + main.show(); + return a.exec(); } diff --git a/node/countexecutenode.cpp b/node/countexecutenode.cpp index ce0249f..a663544 100644 --- a/node/countexecutenode.cpp +++ b/node/countexecutenode.cpp @@ -15,7 +15,7 @@ void CountExecuteNode::setValidator(Validator* validator) void CountExecuteNode::run(ExecutionNode *previous) { -// qDebug() << "CountExecuteNode node"; + m_previousNode = previous; if(NULL==previous) { return; diff --git a/node/dicerollernode.cpp b/node/dicerollernode.cpp index 6a203b9..8eecf0d 100644 --- a/node/dicerollernode.cpp +++ b/node/dicerollernode.cpp @@ -41,6 +41,7 @@ DiceRollerNode::DiceRollerNode(quint64 faces) } void DiceRollerNode::run(ExecutionNode* previous) { + m_previousNode = previous; if(NULL!=previous) { Result* result=previous->getResult(); diff --git a/node/executionnode.cpp b/node/executionnode.cpp index cec9036..e1b71b0 100644 --- a/node/executionnode.cpp +++ b/node/executionnode.cpp @@ -30,3 +30,7 @@ QString ExecutionNode::getHelp() { return QString(); } +ExecutionNode* ExecutionNode::getPreviousNode() const +{ + return m_previousNode; +} diff --git a/node/executionnode.h b/node/executionnode.h index ef5fce8..e10ccb6 100644 --- a/node/executionnode.h +++ b/node/executionnode.h @@ -27,7 +27,7 @@ public: * @brief getResult * @return */ - Result* getResult(); + virtual Result* getResult(); /** * @brief setNextNode */ @@ -37,6 +37,11 @@ public: * @return */ ExecutionNode* getNextNode(); + /** + * @brief getPreviousNode + * @return + */ + virtual ExecutionNode* getPreviousNode() const; /** * @brief toString * @return @@ -59,6 +64,10 @@ public: */ virtual QString getHelp(); protected: + /** + * @brief m_nextNode + */ + ExecutionNode* m_previousNode; /** * @brief m_result */ diff --git a/node/explosedicenode.cpp b/node/explosedicenode.cpp index 9228190..42b3c2d 100644 --- a/node/explosedicenode.cpp +++ b/node/explosedicenode.cpp @@ -7,6 +7,7 @@ ExploseDiceNode::ExploseDiceNode() } void ExploseDiceNode::run(ExecutionNode* previous) { + m_previousNode = previous; if((NULL!=previous)&&(NULL!=previous->getResult())) { DiceResult* previous_result = static_cast<DiceResult*>(previous->getResult()); diff --git a/node/helpnode.cpp b/node/helpnode.cpp index a46d29a..9a0504e 100644 --- a/node/helpnode.cpp +++ b/node/helpnode.cpp @@ -6,6 +6,7 @@ HelpNode::HelpNode() } void HelpNode::run(ExecutionNode* previous) { + m_previousNode = previous; StringResult* txtResult = dynamic_cast<StringResult*>(m_result); qDebug() << m_result->hasResultOfType(Result::SCALAR) << m_result->hasResultOfType(Result::STRING); diff --git a/node/keepdiceexecnode.cpp b/node/keepdiceexecnode.cpp index c219e77..62b4c8f 100644 --- a/node/keepdiceexecnode.cpp +++ b/node/keepdiceexecnode.cpp @@ -12,7 +12,7 @@ KeepDiceExecNode::KeepDiceExecNode() void KeepDiceExecNode::run(ExecutionNode* previous) { -// qDebug() << "KeepDiceExecNode node"; +m_previousNode = previous; if(NULL==previous) { return; diff --git a/node/node.pri b/node/node.pri index fadbd22..d65d3e7 100644 --- a/node/node.pri +++ b/node/node.pri @@ -10,7 +10,8 @@ HEADERS += \ node/countexecutenode.h \ node/explosedicenode.h \ node/parenthesesnode.h \ - node/helpnode.h + node/helpnode.h \ + $$PWD/jumpbackwardnode.h SOURCES += \ node/dicerollernode.cpp \ @@ -24,4 +25,5 @@ SOURCES += \ node/countexecutenode.cpp \ node/explosedicenode.cpp \ node/parenthesesnode.cpp \ - node/helpnode.cpp + node/helpnode.cpp \ + $$PWD/jumpbackwardnode.cpp diff --git a/node/numbernode.cpp b/node/numbernode.cpp index e30426e..4e9d9a3 100644 --- a/node/numbernode.cpp +++ b/node/numbernode.cpp @@ -7,6 +7,7 @@ NumberNode::NumberNode() } void NumberNode::run(ExecutionNode* previous) { + m_previousNode = previous; if(NULL!=previous) { m_result->setPrevious(previous->getResult()); diff --git a/node/parenthesesnode.cpp b/node/parenthesesnode.cpp index 0f7002a..f76d33c 100644 --- a/node/parenthesesnode.cpp +++ b/node/parenthesesnode.cpp @@ -10,7 +10,7 @@ void ParenthesesNode::setInternelNode(ExecutionNode* node) } void ParenthesesNode::run(ExecutionNode* /*previous*/) { -// qDebug() << "ParenthesesNode node"; + m_previousNode = NULL; if(NULL!=m_internalNode) { m_internalNode->run(this); diff --git a/node/rerolldicenode.cpp b/node/rerolldicenode.cpp index 397d791..56bef61 100644 --- a/node/rerolldicenode.cpp +++ b/node/rerolldicenode.cpp @@ -8,7 +8,7 @@ RerollDiceNode::RerollDiceNode() } void RerollDiceNode::run(ExecutionNode* previous) { -// qDebug() << "RerollDiceNode node"; +m_previousNode = previous; if((NULL!=previous)&&(NULL!=previous->getResult())) { DiceResult* previous_result = static_cast<DiceResult*>(previous->getResult()); diff --git a/node/scalaroperatornode.cpp b/node/scalaroperatornode.cpp index fb7a110..6cef1a9 100644 --- a/node/scalaroperatornode.cpp +++ b/node/scalaroperatornode.cpp @@ -18,6 +18,7 @@ ScalarOperatorNode::ScalarOperatorNode() void ScalarOperatorNode::run(ExecutionNode* previous) { + m_previousNode = previous; if(NULL!=m_internalNode) { m_internalNode->run(this); diff --git a/node/sortresult.cpp b/node/sortresult.cpp index c80ebec..5d7f142 100644 --- a/node/sortresult.cpp +++ b/node/sortresult.cpp @@ -12,7 +12,7 @@ SortResultNode::SortResultNode() } void SortResultNode::run(ExecutionNode* node) { -// qDebug() << "SortResultNode node"; + m_previousNode = node; if(NULL==node) { return; diff --git a/node/startingnode.cpp b/node/startingnode.cpp index 9395e53..7ce1e38 100644 --- a/node/startingnode.cpp +++ b/node/startingnode.cpp @@ -7,7 +7,7 @@ StartingNode::StartingNode() } void StartingNode::run(ExecutionNode*) { -// qDebug() << "starting node"; + m_previousNode = NULL; if(NULL!=m_nextNode) { m_nextNode->run(this); diff --git a/parsingtoolbox.h b/parsingtoolbox.h index 5007564..6090b44 100644 --- a/parsingtoolbox.h +++ b/parsingtoolbox.h @@ -28,12 +28,32 @@ #include "booleancondition.h" #include "range.h" +/** + * @brief The ParsingToolBox class - gathering tools + */ class ParsingToolBox { public: ParsingToolBox(); + /** + * @brief addSort + * @param e + * @param b + * @return + */ ExecutionNode* addSort(ExecutionNode* e,bool b); + /** + * @brief readLogicOperator + * @param str + * @param op + * @return + */ bool readLogicOperator(QString& str,BooleanCondition::LogicOperator& op); + /** + * @brief readValidator + * @param str + * @return + */ Validator* readValidator(QString& str); @@ -46,7 +66,17 @@ public: bool readNumber(QString& str, int& myNumber); + /** + * @brief readOpenParentheses + * @param str + * @return + */ bool readOpenParentheses(QString& str); + /** + * @brief readCloseParentheses + * @param str + * @return + */ bool readCloseParentheses(QString& str); private: @@ -36,6 +36,10 @@ void Result::setPrevious(Result* p) m_previous = p; } +bool Result::isStringResult() +{ + return false; +} bool Result::hasResultOfType(RESULT_TYPE type) const { @@ -58,6 +58,9 @@ public: * @brief setPrevious */ virtual void setPrevious(Result*); + bool isStringResult(); + + QString getStringResult(); protected: int m_resultTypes;/// @brief |