From 23ea53c2aa66a9591c96108f5d9584f8123eb09a Mon Sep 17 00:00:00 2001 From: Renaud G Date: Tue, 9 Dec 2014 20:39:15 +0100 Subject: -add command management --- diceparser.cpp | 16 ++++++++++++++++ diceparser.h | 10 +++++++++- main.cpp | 9 +++++---- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/diceparser.cpp b/diceparser.cpp index c94c2b5..5d4a610 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -60,6 +60,10 @@ DiceParser::DiceParser() m_aliasMap->insert("l5R","D10e10k"); m_aliasMap->insert("nwod","D10e10c[>7]"); m_aliasMap->insert("nwod","D10e10c[>7]"); + + + m_commandList = new QList(); + m_commandList->append("help"); } ExecutionNode* DiceParser::getLatestNode(ExecutionNode* node) @@ -141,6 +145,10 @@ bool DiceParser::readExpression(QString& str,ExecutionNode* & node) + } + else if(readCommand(str,operandNode)) + { + return true; } else { @@ -294,6 +302,14 @@ bool DiceParser::readDiceOperator(QString& str,DiceOperator& op) } return false; } +bool DiceParser::readCommand(QString& str,ExecutionNode* & node) +{ + if(m_commandList->contains(str)) + { + // node = new HelpNode(); + } +} + bool DiceParser::readDiceExpression(QString& str,ExecutionNode* & node) { int number=1; diff --git a/diceparser.h b/diceparser.h index cf1bfce..9d9027d 100644 --- a/diceparser.h +++ b/diceparser.h @@ -36,7 +36,7 @@ /** * @mainpage DiceParser * - * the grammar is something like this: + * The grammar is something like this: * * Command =: Expression | ScalarOperator Expression * Expression =: number | number Dice | Command @@ -122,6 +122,13 @@ private: * @param node */ ExecutionNode* getLatestNode(ExecutionNode* node); + /** + * @brief DiceParser::readCommand + * @param str + * @param node + * @return + */ + bool readCommand(QString& str,ExecutionNode* & node); /** * @brief readOption @@ -136,6 +143,7 @@ private: QMap* m_mapDiceOp; QMap* m_OptionOp; QMap* m_aliasMap; + QList* m_commandList; ExecutionNode* m_start; ExecutionNode* m_current; diff --git a/main.cpp b/main.cpp index 6c774ec..5f5a8ec 100644 --- a/main.cpp +++ b/main.cpp @@ -36,7 +36,7 @@ int main(int argc, char *argv[]) QStringList commands; - commands<< "2*(4+4)" + commands<< "help";/* << "1+(4*3)D10" << "2+4/4" << "2D10*2D20*8" @@ -59,7 +59,8 @@ int main(int argc, char *argv[]) << "100/28*3" << "100/8" << "100*3*8" - << "100*3*8"; + << "help" + << "100*3*8";*/ if(argc>1) { @@ -79,7 +80,7 @@ int main(int argc, char *argv[]) myParser->displayResult(); } } - main.show(); - return a.exec(); + //main.show(); + //return a.exec(); } -- cgit v1.2.3-70-g09d2