From bb6b87a2685c0d71b5c38be33c100f85ac0b9cee Mon Sep 17 00:00:00 2001 From: Renaud G Date: Thu, 25 Jul 2019 09:59:29 +0200 Subject: Rework of the component to be a proper lib --- include/diceparser.h | 67 +++++++++++++++++++++------------------------- include/diceparserhelper.h | 30 +++++++++++++++++++++ 2 files changed, 61 insertions(+), 36 deletions(-) (limited to 'include') diff --git a/include/diceparser.h b/include/diceparser.h index 8ecfb50..230d571 100644 --- a/include/diceparser.h +++ b/include/diceparser.h @@ -24,10 +24,11 @@ #include #include +#include -#include "dicealias.h" #include "highlightdice.h" -#include "node/executionnode.h" +#include "diceparserhelper.h" +//#include "node/executionnode.h" typedef QList ListDiceResult; typedef QMap ExportedDiceResult; @@ -35,6 +36,8 @@ typedef QMap ExportedDiceResult; class ExplodeDiceNode; class ParsingToolBox; class DiceRollerNode; +class DiceAlias; +class ExecutionNode; /** * @page DiceParser Dice Parser * @@ -123,18 +126,6 @@ public: * */ void start(); - - /** - * @brief displayResult - */ - QString displayResult(); - /** - * @brief readExpression - * @param str - * @param node - * @return - */ - bool readExpression(QString& str, ExecutionNode*& node); /** * @brief displayDotTree - Write the execution tree into file using dot format. * @param filepath absolute or relative path to the tree file. @@ -204,7 +195,7 @@ public: * @brief getErrorList * @return */ - QMap getErrorMap(); + QMap getErrorMap(); /** * @brief setPathToHelp set the path to the documentation, this path must be adatped to the lang of application etc… * @param l the path. @@ -226,15 +217,7 @@ public: * @return true when the command has separator, false otherwise. */ bool hasSeparator() const; - /** - * @brief readIfInstruction reads the current command to build if node with proper parameters. - * @param str is the command string, if IF istruction is found, the str will be changed, in other case the string is - * unmodified - * @param trueNode is the branch's beginning to be executed if the IfNode is true. - * @param falseNode is the branch's beginning to be executed if the IfNode is false. - * @return true, ifNode has been found, false otherwise - */ - bool readIfInstruction(QString& str, ExecutionNode*& trueNode, ExecutionNode*& falseNode); + /** * @brief setVariableDictionary * @param variables @@ -243,19 +226,32 @@ public: QString getComment() const; void setComment(const QString& comment); - bool readOptionFromNull(QString& str, ExecutionNode*& node); - bool readOperatorFromNull(QString& str, ExecutionNode*& node); - - bool readInstructionList(QString& str); void getDiceResultFromAllInstruction(QList& resultList); QString humanReadableWarning(); bool readValuesList(QString& str, ExecutionNode*& node); -protected: - bool readParameterNode(QString& str, ExecutionNode*& node); - private: + /** + * @brief readIfInstruction reads the current command to build if node with proper parameters. + * @param str is the command string, if IF istruction is found, the str will be changed, in other case the string is + * unmodified + * @param trueNode is the branch's beginning to be executed if the IfNode is true. + * @param falseNode is the branch's beginning to be executed if the IfNode is false. + * @return true, ifNode has been found, false otherwise + */ + bool readIfInstruction(QString& str, ExecutionNode*& trueNode, ExecutionNode*& falseNode); + bool readInstructionList(QString& str); + bool readOptionFromNull(QString& str, ExecutionNode*& node); + bool readOperatorFromNull(QString& str, ExecutionNode*& node); + bool readParameterNode(QString& str, ExecutionNode*& node); + /** + * @brief readExpression + * @param str + * @param node + * @return + */ + bool readExpression(QString& str, ExecutionNode*& node); /** * @brief readDice * @param str @@ -336,7 +332,8 @@ private: * @param notthelast * @return */ - bool hasResultOfType(Result::RESULT_TYPE, ExecutionNode* node, bool notthelast= false); + bool hasResultOfType(Dice::RESULT_TYPE, ExecutionNode* node, bool notthelast= false); + bool readBlocInstruction(QString& str, ExecutionNode*& resultnode); private: QMap* m_mapDiceOp; @@ -345,17 +342,15 @@ private: QList* m_aliasList; QStringList* m_commandList; - QMap m_errorMap; - QMap m_warningMap; + QMap m_errorMap; + QMap m_warningMap; ExecutionNode* m_start= nullptr; std::vector m_startNodes; - // ExecutionNode* m_current; QString m_command; ParsingToolBox* m_parsingToolbox; QString m_helpPath; bool m_currentTreeHasSeparator; - bool readBlocInstruction(QString& str, ExecutionNode*& resultnode); QString m_comment; }; diff --git a/include/diceparserhelper.h b/include/diceparserhelper.h index 4f53293..3ca4f15 100644 --- a/include/diceparserhelper.h +++ b/include/diceparserhelper.h @@ -1,4 +1,34 @@ #ifndef DICEPARSERHELPER_H #define DICEPARSERHELPER_H +namespace Dice +{ + +enum class ERROR_CODE : int +{ + NO_DICE_ERROR, + DIE_RESULT_EXPECTED, + BAD_SYNTAXE, + ENDLESS_LOOP_ERROR, + DIVIDE_BY_ZERO, + NOTHING_UNDERSTOOD, + NO_DICE_TO_ROLL, + TOO_MANY_DICE, + NO_VARIBALE, + INVALID_INDEX, + UNEXPECTED_CHARACTER, + NO_PREVIOUS_ERROR +}; + +/** + * @brief The RESULT_TYPE enum or combinaison + */ +enum class RESULT_TYPE : int +{ + NONE= 0, + SCALAR= 1, + STRING= 2, + DICE_LIST= 4 +}; +} #endif // DICEPARSERHELPER_H -- cgit v1.2.3-70-g09d2