diff options
| author | 2025-02-09 06:05:05 +0100 | |
|---|---|---|
| committer | 2025-02-09 06:05:05 +0100 | |
| commit | 6fcb5ca46927f7baab744e117af9eb1ce5b74838 (patch) | |
| tree | 803b14b1315dfed095705d0c417b19c970541535 /src/libparser/parsingtoolbox.cpp | |
| parent | b8486f92408afa1a0c71d3f62d93f49ac8bebc60 (diff) | |
| download | OneRoll-6fcb5ca46927f7baab744e117af9eb1ce5b74838.tar.gz OneRoll-6fcb5ca46927f7baab744e117af9eb1ce5b74838.zip | |
[Dice] add functions: floor, ceil, round
Diffstat (limited to 'src/libparser/parsingtoolbox.cpp')
| -rw-r--r-- | src/libparser/parsingtoolbox.cpp | 57 |
1 files changed, 53 insertions, 4 deletions
diff --git a/src/libparser/parsingtoolbox.cpp b/src/libparser/parsingtoolbox.cpp index a7b089d..b0d41a7 100644 --- a/src/libparser/parsingtoolbox.cpp +++ b/src/libparser/parsingtoolbox.cpp @@ -61,6 +61,7 @@ #include "node/variablenode.h" #include "operationcondition.h" #include "range.h" +#include "roundnode.h" #include "validatorlist.h" QHash<QString, QString> ParsingToolBox::m_variableHash; @@ -118,6 +119,9 @@ ParsingToolBox::ParsingToolBox() m_OptionOp.insert(QStringLiteral("T"), TransformOption); m_functionMap.insert({QStringLiteral("repeat"), REPEAT}); + m_functionMap.insert({QStringLiteral("floor"), FLOOR}); + m_functionMap.insert({QStringLiteral("ceil"), CEIL}); + m_functionMap.insert({QStringLiteral("round"), ROUND}); m_nodeActionMap.insert(QStringLiteral("@"), JumpBackward); @@ -1438,7 +1442,7 @@ void ParsingToolBox::readSubtitutionParameters(SubtituteInfo& info, QString& res info.setLength(info.length() + sizeS - rest.size()); } -bool ParsingToolBox::readReaperArguments(RepeaterNode* node, QString& source) +bool ParsingToolBox::readRepeaterArguments(RepeaterNode* node, QString& source) { if(!readOpenParentheses(source)) return false; @@ -1466,6 +1470,26 @@ bool ParsingToolBox::readReaperArguments(RepeaterNode* node, QString& source) return false; } + +bool ParsingToolBox::readRoundArguments(RoundNode* node, QString& source) +{ + if(!readOpenParentheses(source)) + return false; + + ExecutionNode* startNode= nullptr; + auto instruction= readExpression(source, startNode); + if(startNode == nullptr || !instruction) + { + m_errorMap.insert(Dice::ERROR_CODE::BAD_SYNTAXE, QObject::tr("Can read the paramater for Round Function.")); + return false; + } + + if(!readCloseParentheses(source)) + return false; + + node->setCommand(startNode); + return true; +} bool ParsingToolBox::readExpression(QString& str, ExecutionNode*& node) { ExecutionNode* operandNode= nullptr; @@ -2338,12 +2362,39 @@ bool ParsingToolBox::readFunction(QString& str, ExecutionNode*& node) case REPEAT: { auto repeaterNode= new RepeaterNode(); - if(ParsingToolBox::readReaperArguments(repeaterNode, str)) + if(ParsingToolBox::readRepeaterArguments(repeaterNode, str)) { node= repeaterNode; } } break; + case FLOOR: + { + auto roundNode= new RoundNode(RoundNode::FLOOR); + if(ParsingToolBox::readRoundArguments(roundNode, str)) + { + node= roundNode; + } + } + break; + case CEIL: + { + auto roundNode= new RoundNode(RoundNode::CEIL); + if(ParsingToolBox::readRoundArguments(roundNode, str)) + { + node= roundNode; + } + } + break; + case ROUND: + { + auto roundNode= new RoundNode(RoundNode::ROUND); + if(ParsingToolBox::readRoundArguments(roundNode, str)) + { + node= roundNode; + } + } + break; } } } @@ -2410,7 +2461,6 @@ std::vector<ExecutionNode*> ParsingToolBox::readInstructionList(QString& str, bo std::vector<ExecutionNode*> startNodes; - bool hasInstruction= false; bool readInstruction= true; while(readInstruction) { @@ -2418,7 +2468,6 @@ std::vector<ExecutionNode*> ParsingToolBox::readInstructionList(QString& str, bo bool keepParsing= readExpression(str, startNode); if(nullptr != startNode) { - hasInstruction= true; startNodes.push_back(startNode); auto latest= startNode; if(keepParsing) |