From 8087429c108c4f6bef5f792ce256b8d5b8b69101 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Sat, 11 Jul 2020 00:45:44 +0200 Subject: Rework exporting --- include/diceparser.h | 64 +------------- include/highlightdice.h | 17 ++-- include/parsingtoolbox.h | 224 ++++++++++------------------------------------- 3 files changed, 59 insertions(+), 246 deletions(-) (limited to 'include') diff --git a/include/diceparser.h b/include/diceparser.h index eb4dee4..4d5555e 100644 --- a/include/diceparser.h +++ b/include/diceparser.h @@ -89,61 +89,10 @@ public: QList* aliases() const; void cleanAliases(); void insertAlias(DiceAlias*, int); - /** - * @brief getErrorList - * @return - */ - QMap errorMap() const; - /** - * @brief setPathToHelp set the path to the documentation, this path must be adatped to the lang of application etc… - * @param l the path. - */ - void setPathToHelp(QString l); - /** - * @brief allFirstResultAsString - * @return - */ + QString convertAlias(const QString& cmd) const; + QStringList allFirstResultAsString(bool& hasAlias); - /** - * @brief getAllDiceResult - * @param hasAlias - * @return - */ QStringList getAllDiceResult(bool& hasAlias); - /** - * @brief hasSeparator allows to know if the current command has separator. - * @return true when the command has separator, false otherwise. - */ - bool hasSeparator() const; -// beginning of strange code ||||||| parent of af8b69b... change the way diceparser is giving its result. - /** - * @brief getErrorList - * @return - */ - 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. - */ - void setPathToHelp(QString l); - /** - * @brief getAllStringResult - * @return - */ - QStringList getAllStringResult(bool& hasAlias); - /** - * @brief getAllDiceResult - * @param hasAlias - * @return - */ - QStringList getAllDiceResult(bool& hasAlias); - /** - * @brief hasSeparator allows to know if the current command has separator. - * @return true when the command has separator, false otherwise. - */ - bool hasSeparator() const; -// END of strange code - QString convertAlias(const QString& cmd) const; // Accessors int startNodeCount() const; @@ -156,12 +105,11 @@ public: QString comment() const; QString humanReadableWarning() const; QString humanReadableError() const; - QJsonObject exportResult() const; + QString resultAsJSon() const; // QStringList stringResult() const; // QStringList allDiceResult(bool& hasAlias) const; // void lastDiceResult(QList& diceValues, bool& homogeneous) const; - // QList sumOfDiceResult() const; // setters void setPathToHelp(QString l); @@ -169,12 +117,6 @@ public: void setComment(const QString& comment); private: - /** - * @brief hasResultOfType - * @param notthelast - * @return - */ - bool hasResultOfType(Dice::RESULT_TYPE, ExecutionNode* node, QVariant& value, bool notthelast= false); bool readBlocInstruction(QString& str, ExecutionNode*& resultnode); private: diff --git a/include/highlightdice.h b/include/highlightdice.h index c70a371..66bd445 100644 --- a/include/highlightdice.h +++ b/include/highlightdice.h @@ -27,35 +27,40 @@ class HighLightDice { public: - HighLightDice(QList result, bool isHighlighted, QString color, bool displayed, quint64 faces); + HighLightDice(QList result, bool isHighlighted, QString color, bool displayed, quint64 faces, + const QString& uuid); virtual ~HighLightDice(); - QList getResult() const; + QList result() const; void setResult(const QList& result); bool isHighlighted() const; void setHighlight(bool hasHighlight); - QString getColor() const; + QString color() const; void setColor(const QString& color); - bool getDisplayed() const; + bool displayed() const; void setDisplayed(bool displayed); - quint64 getFaces() const; + quint64 faces() const; void setFaces(const quint64& faces); QString getResultString() const; + QString uuid() const; + void setUuid(const QString& uuid); + private: QList m_result; bool m_hasHighlight= true; QString m_color; bool m_displayed= false; quint64 m_faces; + QString m_uuid; }; typedef QList ListDiceResult; -typedef QMap ExportedDiceResult; +typedef QMap> ExportedDiceResult; #endif // HighLightDice_H diff --git a/include/parsingtoolbox.h b/include/parsingtoolbox.h index 40d2b33..d0a757f 100644 --- a/include/parsingtoolbox.h +++ b/include/parsingtoolbox.h @@ -138,174 +138,45 @@ public: * @brief ~ParsingToolBox */ virtual ~ParsingToolBox(); - void clearUp(); - /** - * @brief addSort - * @param e - * @param b - * @return - */ + + // Build execution tree + DiceRollerNode* getDiceRollerNode(ExecutionNode* previous); + DiceRollerNode* addRollDiceNode(qint64 faces, ExecutionNode*); + ExplodeDiceNode* addExplodeDiceNode(qint64 faces, ExecutionNode* previous); + Dice::CONDITION_STATE isValidValidator(ExecutionNode* previous, ValidatorList* val); ExecutionNode* addSort(ExecutionNode* e, bool b); - /** - * @brief readAscending - * @param str - * @return - */ + + // parsing tools static bool readAscending(QString& str); - /** - * @brief readLogicOperator - * @param str - * @param op - * @return - */ bool readLogicOperator(QString& str, BooleanCondition::LogicOperator& op); - /** - * @brief readValidator - * @param str - * @return - */ Validator* readValidator(QString& str, bool hasSquare= false); - /** - * @brief readCompositeValidator - * @param str - * @return - */ ValidatorList* readValidatorList(QString& str); - - /** - * @brief readNumber read number in the given str and remove from the string the read character. - * @param str the command line - * @param myNumber reference to the found number - * @return true, succeed to read number, false otherwise. - */ static bool readNumber(QString& str, qint64& myNumber); - - /** - * @brief readString - * @param str - * @param strResult - * @return - */ static bool readString(QString& str, QString& strresult); - /** - * @brief readVariable - * @param str - * @param myNumber - * @return - */ static bool readVariable(QString& str, qint64& myNumber, QString& reasonFail); - /** - * @brief readOpenParentheses - * @param str - * @return - */ static bool readOpenParentheses(QString& str); - /** - * @brief readCloseParentheses - * @param str - * @return - */ static bool readCloseParentheses(QString& str); - /** - * @brief readNumber read number in the given str and remove from the string the read character. - * @param str the command line - * @param myNumber reference to the found number - * @return true, succeed to read number, false otherwise. - */ static bool readDynamicVariable(QString& str, qint64& index); - - /** - * @brief readList - * @param str - * @param list - * @return - */ bool readList(QString& str, QStringList& list, QList& ranges); - /** - * @brief isValidValidator - * @param previous - * @param val - * @return - */ - Dice::CONDITION_STATE isValidValidator(ExecutionNode* previous, ValidatorList* val); - /** - * @brief getDiceRollerNode - * @param previous - * @return - */ - DiceRollerNode* getDiceRollerNode(ExecutionNode* previous); - - /** - * @brief readDiceRange - * @param str - * @param start - * @param end - * @return - */ bool readDiceRange(QString& str, qint64& start, qint64& end); - /** - * @brief readListOperator - * @param str - * @return - */ static LIST_OPERATOR readListOperator(QString& str); - void readProbability(QStringList& str, QList& ranges); - bool readLogicOperation(QString& str, ValidatorList::LogicOperation& op); - bool readDiceLogicOperator(QString& str, OperationCondition::ConditionOperator& op); - bool readArithmeticOperator(QString& str, Die::ArithmeticOperator& op); std::vector readInstructionList(QString& str, bool startNode); - - static bool readPainterParameter(PainterNode* painter, QString& str); - - static QHash getVariableHash(); - static void setVariableHash(const QHash& variableHash); - /** - * @brief readConditionType - * @param str - * @return - */ static Dice::ConditionType readConditionType(QString& str); - bool readComment(QString& str, QString&, QString&); - static ExecutionNode* getLatestNode(ExecutionNode* node); - - const std::vector& getStartNodes(); - static void setStartNodes(std::vector* startNodes); - 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, - QMap& errorMap); - static QString replacePlaceHolderToValue(const QString& source, const QList& list); - - static SubtituteInfo readVariableFromString(const QString& source, int& start); - static SubtituteInfo readPlaceHolderFromString(const QString& source, int& start); - static void readSubtitutionParameters(SubtituteInfo& info, QString& rest); - + static bool readPainterParameter(PainterNode* painter, QString& str); 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. @@ -316,67 +187,62 @@ public: * @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 readBlocInstruction(QString& str, ExecutionNode*& resultnode); bool readOption(QString&, ExecutionNode* node); // OptionOperator& option, - bool readValuesList(QString& str, ExecutionNode*& node); + // Error + bool hasError() const; 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& getErrorList() const; const QMap& getWarningList() const; - QString convertAlias(QString str); - - bool readBlocInstruction(QString& str, ExecutionNode*& resultnode); + // Traversal functions + static ExecutionNode* getLatestNode(ExecutionNode* node); + static ExecutionNode* getLeafNode(ExecutionNode* start); + const std::vector& getStartNodes(); + static void setStartNodes(std::vector* startNodes); + std::pair hasResultOfType(Dice::RESULT_TYPE, ExecutionNode* node, bool notthelast= false) const; + QList scalarResultsFromEachInstruction() const; + std::pair finalScalarResult() const; + QString finalStringResult() const; + QStringList allFirstResultAsString(bool& hasAlias) const; + QList sumOfDiceResult() const; + QList diceResultFromEachInstruction() const; + bool hasIntegerResultNotInFirst() const; + bool hasDiceResult() const; + bool hasStringResult() const; + + // result + static QString replaceVariableToValue(const QString& source, QStringList values, + QMap& errorMap); + static QString replacePlaceHolderToValue(const QString& source, const QList& list); + static SubtituteInfo readVariableFromString(const QString& source, int& start); + static SubtituteInfo readPlaceHolderFromString(const QString& source, int& start); + static ExportedDiceResult finalDiceResultFromInstruction(ExecutionNode* start); + static ExportedDiceResult allDiceResultFromInstruction(ExecutionNode* start); + void addResultInJson(QJsonObject obj, Dice::RESULT_TYPE type, const QString& key, ExecutionNode* start, bool b); + void addDiceResultInJson(QJsonObject obj, ExecutionNode* start); + // accessors + void setComment(const QString& comment); + QString getComment() const; void setHelpPath(const QString& path); + static QHash getVariableHash(); + static void setVariableHash(const QHash& variableHash); + // Aliases + QString convertAlias(QString str); void insertAlias(DiceAlias* dice, int i); const QList& getAliases() const; QList* aliases(); -- cgit v1.2.3-70-g09d2