aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/include
diff options
context:
space:
mode:
authorRenaud G <renaud@rolisteam.org>2020-01-30 01:27:15 +0100
committerRenaud G <renaud@rolisteam.org>2020-03-28 02:05:05 +0100
commit653ba9395a36cc20ec1d68c9a9cae78973fa334c (patch)
tree72753ed3bdca117baf001cdf8251b1fb22276eeb /include
parent22d71d0032e2f44a8f267895aea3bd87864791b3 (diff)
downloadOneRoll-653ba9395a36cc20ec1d68c9a9cae78973fa334c.tar.gz
OneRoll-653ba9395a36cc20ec1d68c9a9cae78973fa334c.zip
add unicity and repeat function part2
Diffstat (limited to 'include')
-rw-r--r--include/diceparser.h167
-rw-r--r--include/diceparserhelper.h12
-rw-r--r--include/parsingtoolbox.h176
3 files changed, 177 insertions, 178 deletions
diff --git a/include/diceparser.h b/include/diceparser.h
index 31f9760..e60f30d 100644
--- a/include/diceparser.h
+++ b/include/diceparser.h
@@ -24,6 +24,7 @@
#include <QMap>
#include <QString>
+#include <memory>
#include <vector>
#include "diceparserhelper.h"
@@ -53,52 +54,6 @@ class DiceParser
{
public:
/**
- * @brief The DiceOperator enum gathering all dice operators
- */
- enum DiceOperator
- {
- D,
- L
- };
- /**
- * @brief The DiceSymbol enum
- */
- enum NodeAction
- {
- JumpBackward
- };
- /**
- * @brief The OptionOperator enum gathering all options availables for result.
- */
- enum OptionOperator
- {
- KeepAndExplode,
- Keep,
- Reroll,
- RerollUntil,
- Explode,
- Sort,
- Count,
- RerollAndAdd,
- Merge,
- ifOperator,
- Painter,
- Filter,
- Split,
- Group,
- Occurences,
- Unique,
- Bind,
- AllSameExplode
- };
- /**
- * @brief The CommandOperator enum
- */
- enum CommandOperator
- {
- };
-
- /**
* @brief DiceParser default constructor
*/
DiceParser();
@@ -178,18 +133,12 @@ public:
* @brief getAliases
* @return
*/
- QList<DiceAlias*>* getAliases();
+ const QList<DiceAlias*>& getAliases() const;
/**
* @brief insertAlias
*/
void insertAlias(DiceAlias*, int);
/**
- * @brief DiceParser::convertAlias
- * @param str
- * @return
- */
- QString convertAlias(QString str);
- /**
* @brief getErrorList
* @return
*/
@@ -227,106 +176,10 @@ public:
void getDiceResultFromAllInstruction(QList<ExportedDiceResult>& resultList);
QString humanReadableWarning();
- bool readValuesList(QString& str, ExecutionNode*& node);
void cleanAll();
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
- */
- bool readDice(QString& str, ExecutionNode*& node);
- /**
- * @brief readDiceOperator
- * @return
- */
- bool readDiceOperator(QString&, DiceOperator&);
- /**
- * @brief readDiceExpression
- * @param node
- * @return
- */
- bool readDiceExpression(QString&, ExecutionNode*& node);
- /**
- * @brief readOperator
- * @return
- */
- bool readOperator(QString&, ExecutionNode* previous);
- /**
- * @brief DiceParser::readCommand
- * @param str
- * @param node
- * @return
- */
- bool readCommand(QString& str, ExecutionNode*& node);
-
- /**
- * @brief readOption
- */
- bool readOption(QString&, ExecutionNode* node); // OptionOperator& option,
-
- /**
- * @brief addRollDiceNode
- * @param faces
- * @return
- */
- DiceRollerNode* addRollDiceNode(qint64 faces, ExecutionNode*);
- /**
- * @brief addExplodeDiceNode
- * @param faces
- * @param previous
- * @return
- */
- ExplodeDiceNode* addExplodeDiceNode(qint64 faces, ExecutionNode* previous);
- /**
- * @brief readOperand
- * @param node
- * @return
- */
- bool readOperand(QString&, ExecutionNode*& node);
-
- /**
- * @brief readInstructionOperator
- * @param c
- * @return
- */
- bool readInstructionOperator(QChar c);
- /**
- * @brief readNode
- * @param str
- * @param node
- * @return
- */
- bool readNode(QString& str, ExecutionNode*& node);
-
- /**
- * @brief getLeafNode
- * @return
- */
- ExecutionNode* getLeafNode(ExecutionNode* node);
-
- /**
* @brief hasResultOfType
* @param notthelast
* @return
@@ -335,22 +188,8 @@ private:
bool readBlocInstruction(QString& str, ExecutionNode*& resultnode);
private:
- QMap<QString, DiceOperator>* m_mapDiceOp;
- QMap<QString, OptionOperator>* m_OptionOp;
- QMap<QString, NodeAction>* m_nodeActionMap;
- QList<DiceAlias*>* m_aliasList;
- QStringList* m_commandList;
-
- QMap<Dice::ERROR_CODE, QString> m_errorMap;
- QMap<Dice::ERROR_CODE, QString> m_warningMap;
-
- ExecutionNode* m_start= nullptr;
- std::vector<ExecutionNode*> m_startNodes;
+ std::unique_ptr<ParsingToolBox> m_parsingToolbox;
QString m_command;
- ParsingToolBox* m_parsingToolbox;
- QString m_helpPath;
- bool m_currentTreeHasSeparator;
- QString m_comment;
};
#endif // DICEPARSER_H
diff --git a/include/diceparserhelper.h b/include/diceparserhelper.h
index 1b91285..461d127 100644
--- a/include/diceparserhelper.h
+++ b/include/diceparserhelper.h
@@ -39,5 +39,15 @@ enum class RESULT_TYPE : int
STRING= 2,
DICE_LIST= 4
};
-}
+/**
+ * @brief The ConditionType enum defines compare method
+ */
+enum ConditionType
+{
+ OnEach,
+ OneOfThem,
+ AllOfThem,
+ OnScalar
+};
+} // namespace Dice
#endif // DICEPARSERHELPER_H
diff --git a/include/parsingtoolbox.h b/include/parsingtoolbox.h
index 038427f..701d2d3 100644
--- a/include/parsingtoolbox.h
+++ b/include/parsingtoolbox.h
@@ -23,9 +23,9 @@
#define PARSINGTOOLBOX_H
#include <QMap>
+#include <vector>
#include "booleancondition.h"
-#include "compositevalidator.h"
#include "highlightdice.h"
#include "node/dicerollernode.h"
#include "node/executionnode.h"
@@ -34,6 +34,11 @@
#include "node/scalaroperatornode.h"
#include "operationcondition.h"
#include "range.h"
+#include "validatorlist.h"
+
+class RepeaterNode;
+class DiceAlias;
+class ExplodeDiceNode;
class SubtituteInfo
{
@@ -73,7 +78,49 @@ public:
NONE,
UNIQUE
};
-
+ enum Function
+ {
+ REPEAT
+ };
+ /**
+ * @brief The OptionOperator enum gathering all options availables for result.
+ */
+ enum OptionOperator
+ {
+ KeepAndExplode,
+ Keep,
+ Reroll,
+ RerollUntil,
+ Explode,
+ Sort,
+ Count,
+ RerollAndAdd,
+ Merge,
+ ifOperator,
+ Painter,
+ Filter,
+ Split,
+ Group,
+ Occurences,
+ Unique,
+ Bind,
+ AllSameExplode
+ };
+ /**
+ * @brief The DiceOperator enum gathering all dice operators
+ */
+ enum DiceOperator
+ {
+ D,
+ L
+ };
+ /**
+ * @brief The DiceSymbol enum
+ */
+ enum NodeAction
+ {
+ JumpBackward
+ };
/**
* @brief ParsingToolBox
*/
@@ -87,6 +134,8 @@ public:
* @brief ~ParsingToolBox
*/
virtual ~ParsingToolBox();
+
+ void clearUp();
/**
* @brief addSort
* @param e
@@ -118,7 +167,7 @@ public:
* @param str
* @return
*/
- Validator* readCompositeValidator(QString& str);
+ ValidatorList* readValidatorList(QString& str);
/**
* @brief readNumber read number in the given str and remove from the string the read character.
@@ -176,7 +225,7 @@ public:
* @param val
* @return
*/
- Dice::CONDITION_STATE isValidValidator(ExecutionNode* previous, Validator* val);
+ Dice::CONDITION_STATE isValidValidator(ExecutionNode* previous, ValidatorList* val);
/**
* @brief getDiceRollerNode
* @param previous
@@ -201,11 +250,12 @@ public:
void readProbability(QStringList& str, QList<Range>& ranges);
- bool readLogicOperation(QString& str, CompositeValidator::LogicOperation& op);
+ bool readLogicOperation(QString& str, ValidatorList::LogicOperation& op);
bool readDiceLogicOperator(QString& str, OperationCondition::ConditionOperator& op);
bool readArithmeticOperator(QString& str, Die::ArithmeticOperator& op);
+ std::vector<ExecutionNode*> readInstructionList(QString& str, bool startNode);
static bool readPainterParameter(PainterNode* painter, QString& str);
@@ -216,15 +266,15 @@ public:
* @param str
* @return
*/
- static IfNode::ConditionType readConditionType(QString& str);
+ static Dice::ConditionType readConditionType(QString& str);
bool readComment(QString& str, QString&, QString&);
static ExecutionNode* getLatestNode(ExecutionNode* node);
- static std::vector<ExecutionNode*>* getStartNodes();
+ const std::vector<ExecutionNode*>& getStartNodes();
static void setStartNodes(std::vector<ExecutionNode*>* startNodes);
- static bool readOperand(QString& str, ExecutionNode*& node);
+ bool readOperand(QString& str, ExecutionNode*& node);
static int findClosingCharacterIndexOf(QChar open, QChar closing, const QString& str, int offset);
static QString replaceVariableToValue(const QString& source, QStringList values);
@@ -237,14 +287,114 @@ public:
static bool readComma(QString& str);
+ bool readReaperArguments(RepeaterNode* node, QString& source);
+
+ DiceRollerNode* addRollDiceNode(qint64 faces, ExecutionNode*);
+
+ ExplodeDiceNode* addExplodeDiceNode(qint64 faces, ExecutionNode* previous);
+
+ bool readExpression(QString& str, ExecutionNode*& node);
+
+ static ExecutionNode* getLeafNode(ExecutionNode* start);
+
+ bool hasError() const;
+
+ bool readInstructionOperator(QChar c);
+
+ bool readNode(QString& str, ExecutionNode*& node);
+ /**
+ * @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 readOptionFromNull(QString& str, ExecutionNode*& node);
+ bool readOperatorFromNull(QString& str, ExecutionNode*& node);
+ bool readParameterNode(QString& str, ExecutionNode*& node);
+
+ /**
+ *
+ */
+ bool readFunction(QString& str, ExecutionNode*& node);
+ /**
+ * @brief readDice
+ * @param str
+ * @return
+ */
+ bool readDice(QString& str, ExecutionNode*& node);
+ /**
+ * @brief readDiceOperator
+ * @return
+ */
+ bool readDiceOperator(QString&, DiceOperator&);
+ /**
+ * @brief readDiceExpression
+ * @param node
+ * @return
+ */
+ bool readDiceExpression(QString&, ExecutionNode*& node);
+ /**
+ * @brief readOperator
+ * @return
+ */
+ bool readOperator(QString&, ExecutionNode* previous);
+ /**
+ * @brief DiceParser::readCommand
+ * @param str
+ * @param node
+ * @return
+ */
+ bool readCommand(QString& str, ExecutionNode*& node);
+
+ /**
+ * @brief readOption
+ */
+ bool readOption(QString&, ExecutionNode* node); // OptionOperator& option,
+
+ bool readValuesList(QString& str, ExecutionNode*& node);
+
+ void addError(Dice::ERROR_CODE code, const QString& msg);
+ void addWarning(Dice::ERROR_CODE code, const QString& msg);
+
+ void setComment(const QString& comment);
+ QString getComment() const;
+
+ const QMap<Dice::ERROR_CODE, QString>& getErrorList() const;
+ const QMap<Dice::ERROR_CODE, QString>& getWarningList() const;
+
+ QString convertAlias(QString str);
+
+ bool readBlocInstruction(QString& str, ExecutionNode*& resultnode);
+
+ void setHelpPath(const QString& path);
+
+ void insertAlias(DiceAlias* dice, int i);
+ const QList<DiceAlias*>& getAliases() const;
+
private:
- QMap<QString, BooleanCondition::LogicOperator>* m_logicOp;
- QMap<QString, CompositeValidator::LogicOperation>* m_logicOperation;
- QMap<QString, OperationCondition::ConditionOperator>* m_conditionOperation;
- QHash<QString, Die::ArithmeticOperator>* m_arithmeticOperation;
+ QMap<QString, BooleanCondition::LogicOperator> m_logicOp;
+ QMap<QString, ValidatorList::LogicOperation> m_logicOperation;
+ QMap<QString, OperationCondition::ConditionOperator> m_conditionOperation;
+ QHash<QString, Die::ArithmeticOperator> m_arithmeticOperation;
+ QMap<QString, DiceOperator> m_mapDiceOp;
+ QMap<QString, OptionOperator> m_OptionOp;
+ QMap<QString, NodeAction> m_nodeActionMap;
+ std::map<QString, Function> m_functionMap;
+ QStringList m_commandList;
+
+ QMap<Dice::ERROR_CODE, QString> m_errorMap;
+ QMap<Dice::ERROR_CODE, QString> m_warningMap;
+ std::vector<ExecutionNode*> m_startNodes;
+
+ QString m_comment;
static QHash<QString, QString> m_variableHash;
- static std::vector<ExecutionNode*>* m_startNodes;
+ QString m_helpPath;
+ QList<DiceAlias*> m_aliasList;
};
#endif // PARSINGTOOLBOX_H