diff options
| author | 2014-12-09 20:39:15 +0100 | |
|---|---|---|
| committer | 2014-12-09 20:39:15 +0100 | |
| commit | 23ea53c2aa66a9591c96108f5d9584f8123eb09a (patch) | |
| tree | 331903f20d34e0dfa36d9b8dc3cc1a507da65ab9 | |
| parent | d044490547eb9c5b14bc937ee7cce448ea29d562 (diff) | |
| download | OneRoll-23ea53c2aa66a9591c96108f5d9584f8123eb09a.tar.gz OneRoll-23ea53c2aa66a9591c96108f5d9584f8123eb09a.zip | |
-add command management
| -rw-r--r-- | diceparser.cpp | 16 | ||||
| -rw-r--r-- | diceparser.h | 10 | ||||
| -rw-r--r-- | 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<QString>(); + m_commandList->append("help"); } ExecutionNode* DiceParser::getLatestNode(ExecutionNode* node) @@ -142,6 +146,10 @@ bool DiceParser::readExpression(QString& str,ExecutionNode* & node) } + else if(readCommand(str,operandNode)) + { + return true; + } else { ExecutionNode* diceNode=NULL; @@ -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<QString,DiceOperator>* m_mapDiceOp; QMap<QString,OptionOperator>* m_OptionOp; QMap<QString,QString>* m_aliasMap; + QList<QString>* m_commandList; ExecutionNode* m_start; ExecutionNode* m_current; @@ -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(); } |