diff options
| author | 2019-07-25 09:59:29 +0200 | |
|---|---|---|
| committer | 2019-07-25 09:59:29 +0200 | |
| commit | bb6b87a2685c0d71b5c38be33c100f85ac0b9cee (patch) | |
| tree | 81da599ceec1368e55fee5fd6a4dd0173fc39b5f /include | |
| parent | 6f499de159eeac37fe473f945042e13359dc2d40 (diff) | |
| download | OneRoll-bb6b87a2685c0d71b5c38be33c100f85ac0b9cee.tar.gz OneRoll-bb6b87a2685c0d71b5c38be33c100f85ac0b9cee.zip | |
Rework of the component to be a proper lib
Diffstat (limited to 'include')
| -rw-r--r-- | include/diceparser.h | 67 | ||||
| -rw-r--r-- | include/diceparserhelper.h | 30 |
2 files changed, 61 insertions, 36 deletions
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 <QMap> #include <QString> +#include <vector> -#include "dicealias.h" #include "highlightdice.h" -#include "node/executionnode.h" +#include "diceparserhelper.h" +//#include "node/executionnode.h" typedef QList<HighLightDice> ListDiceResult; typedef QMap<quint64, ListDiceResult> ExportedDiceResult; @@ -35,6 +36,8 @@ typedef QMap<quint64, ListDiceResult> 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<ExecutionNode::DICE_ERROR_CODE, QString> getErrorMap(); + QMap<Dice::ERROR_CODE, QString> 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,20 +226,33 @@ 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<ExportedDiceResult>& 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 * @return @@ -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<QString, DiceOperator>* m_mapDiceOp; @@ -345,17 +342,15 @@ private: QList<DiceAlias*>* m_aliasList; QStringList* m_commandList; - QMap<ExecutionNode::DICE_ERROR_CODE, QString> m_errorMap; - QMap<ExecutionNode::DICE_ERROR_CODE, QString> m_warningMap; + QMap<Dice::ERROR_CODE, QString> m_errorMap; + QMap<Dice::ERROR_CODE, QString> m_warningMap; ExecutionNode* m_start= nullptr; std::vector<ExecutionNode*> 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 |