aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/diceparser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'diceparser.cpp')
-rw-r--r--diceparser.cpp925
1 files changed, 463 insertions, 462 deletions
diff --git a/diceparser.cpp b/diceparser.cpp
index d3d86a2..5ec7122 100644
--- a/diceparser.cpp
+++ b/diceparser.cpp
@@ -1,131 +1,129 @@
/***************************************************************************
- * Copyright (C) 2014 by Renaud Guezennec *
- * http://www.rolisteam.org/contact *
- * *
- * This file is part of DiceParser *
- * *
- * DiceParser is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
- ***************************************************************************/
+ * Copyright (C) 2014 by Renaud Guezennec *
+ * http://www.rolisteam.org/contact *
+ * *
+ * This file is part of DiceParser *
+ * *
+ * DiceParser is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
#include "diceparser.h"
#include <QDebug>
-#include <QStringList>
-#include <QObject>
#include <QFile>
+#include <QObject>
+#include <QStringList>
#include <functional>
-#include "node/startingnode.h"
-#include "node/scalaroperatornode.h"
-#include "node/filternode.h"
-#include "node/numbernode.h"
-#include "node/keepdiceexecnode.h"
-#include "node/sortresult.h"
+#include "node/bind.h"
#include "node/countexecutenode.h"
-#include "node/rerolldicenode.h"
#include "node/explodedicenode.h"
-#include "node/parenthesesnode.h"
+#include "node/filternode.h"
+#include "node/groupnode.h"
#include "node/helpnode.h"
+#include "node/ifnode.h"
#include "node/jumpbackwardnode.h"
-#include "node/listsetrollnode.h"
+#include "node/keepdiceexecnode.h"
#include "node/listaliasnode.h"
+#include "node/listsetrollnode.h"
#include "node/mergenode.h"
-#include "node/ifnode.h"
+#include "node/numbernode.h"
#include "node/paintnode.h"
-#include "node/stringnode.h"
+#include "node/parenthesesnode.h"
+#include "node/rerolldicenode.h"
+#include "node/scalaroperatornode.h"
+#include "node/sortresult.h"
#include "node/splitnode.h"
-#include "node/groupnode.h"
+#include "node/startingnode.h"
+#include "node/stringnode.h"
#include "node/variablenode.h"
-#include "node/bind.h"
#define DEFAULT_FACES_NUMBER 10
DiceParser::DiceParser()
//: //m_start(nullptr),m_current(nullptr)
{
- m_currentTreeHasSeparator =false;
- m_parsingToolbox = new ParsingToolBox();
+ m_currentTreeHasSeparator= false;
+ m_parsingToolbox= new ParsingToolBox();
ParsingToolBox::setStartNodes(&m_startNodes);
-
- m_mapDiceOp = new QMap<QString,DiceOperator>();
- m_mapDiceOp->insert(QStringLiteral("D"),D);
- m_mapDiceOp->insert(QStringLiteral("L"),L);
-
- m_OptionOp = new QMap<QString,OptionOperator>();
- m_OptionOp->insert(QStringLiteral("k"),Keep);
- m_OptionOp->insert(QStringLiteral("K"),KeepAndExplode);
- m_OptionOp->insert(QStringLiteral("s"),Sort);
- m_OptionOp->insert(QStringLiteral("c"),Count);
- m_OptionOp->insert(QStringLiteral("r"),Reroll);
- m_OptionOp->insert(QStringLiteral("e"),Explode);
- m_OptionOp->insert(QStringLiteral("R"),RerollUntil);
- m_OptionOp->insert(QStringLiteral("a"),RerollAndAdd);
- m_OptionOp->insert(QStringLiteral("m"),Merge);
- m_OptionOp->insert(QStringLiteral("i"),ifOperator);
- m_OptionOp->insert(QStringLiteral("p"),Painter);
- m_OptionOp->insert(QStringLiteral("f"),Filter);
- m_OptionOp->insert(QStringLiteral("u"),Split);
- m_OptionOp->insert(QStringLiteral("g"),Group);
- m_OptionOp->insert(QStringLiteral("b"),Bind);
-
- m_aliasList = new QList<DiceAlias*>();
-
- m_nodeActionMap = new QMap<QString,NodeAction>();
- m_nodeActionMap->insert(QStringLiteral("@"),JumpBackward);
-
- m_commandList = new QStringList();
+ m_mapDiceOp= new QMap<QString, DiceOperator>();
+ m_mapDiceOp->insert(QStringLiteral("D"), D);
+ m_mapDiceOp->insert(QStringLiteral("L"), L);
+
+ m_OptionOp= new QMap<QString, OptionOperator>();
+ m_OptionOp->insert(QStringLiteral("k"), Keep);
+ m_OptionOp->insert(QStringLiteral("K"), KeepAndExplode);
+ m_OptionOp->insert(QStringLiteral("s"), Sort);
+ m_OptionOp->insert(QStringLiteral("c"), Count);
+ m_OptionOp->insert(QStringLiteral("r"), Reroll);
+ m_OptionOp->insert(QStringLiteral("e"), Explode);
+ m_OptionOp->insert(QStringLiteral("R"), RerollUntil);
+ m_OptionOp->insert(QStringLiteral("a"), RerollAndAdd);
+ m_OptionOp->insert(QStringLiteral("m"), Merge);
+ m_OptionOp->insert(QStringLiteral("i"), ifOperator);
+ m_OptionOp->insert(QStringLiteral("p"), Painter);
+ m_OptionOp->insert(QStringLiteral("f"), Filter);
+ m_OptionOp->insert(QStringLiteral("u"), Split);
+ m_OptionOp->insert(QStringLiteral("g"), Group);
+ m_OptionOp->insert(QStringLiteral("b"), Bind);
+
+ m_aliasList= new QList<DiceAlias*>();
+
+ m_nodeActionMap= new QMap<QString, NodeAction>();
+ m_nodeActionMap->insert(QStringLiteral("@"), JumpBackward);
+
+ m_commandList= new QStringList();
m_commandList->append(QStringLiteral("help"));
m_commandList->append(QStringLiteral("la"));
-
}
DiceParser::~DiceParser()
{
- if(nullptr!=m_commandList)
+ if(nullptr != m_commandList)
{
delete m_commandList;
- m_commandList = nullptr;
+ m_commandList= nullptr;
}
- if(nullptr!=m_nodeActionMap)
+ if(nullptr != m_nodeActionMap)
{
delete m_nodeActionMap;
- m_nodeActionMap = nullptr;
+ m_nodeActionMap= nullptr;
}
- if(nullptr!=m_OptionOp)
+ if(nullptr != m_OptionOp)
{
delete m_OptionOp;
- m_OptionOp = nullptr;
+ m_OptionOp= nullptr;
}
- if(nullptr!=m_mapDiceOp)
+ if(nullptr != m_mapDiceOp)
{
delete m_mapDiceOp;
- m_mapDiceOp = nullptr;
+ m_mapDiceOp= nullptr;
}
- if(nullptr!=m_parsingToolbox)
+ if(nullptr != m_parsingToolbox)
{
delete m_parsingToolbox;
- m_parsingToolbox = nullptr;
+ m_parsingToolbox= nullptr;
}
- if(nullptr!=m_aliasList)
+ if(nullptr != m_aliasList)
{
delete m_aliasList;
- m_aliasList = nullptr;
+ m_aliasList= nullptr;
}
- if(nullptr!=m_start)
+ if(nullptr != m_start)
{
delete m_start;
- m_start = nullptr;
+ m_start= nullptr;
}
}
@@ -146,7 +144,7 @@ QList<DiceAlias*>* DiceParser::getAliases()
}
void DiceParser::insertAlias(DiceAlias* dice, int i)
{
- if(i>=m_aliasList->size())
+ if(i >= m_aliasList->size())
{
m_aliasList->insert(i, dice);
}
@@ -155,58 +153,62 @@ void DiceParser::insertAlias(DiceAlias* dice, int i)
bool DiceParser::parseLine(QString str, bool allowAlias)
{
m_errorMap.clear();
- m_comment = QString("");
+ m_comment= QString("");
if(!m_startNodes.empty())
{
qDeleteAll(m_startNodes);
m_startNodes.clear();
}
- m_currentTreeHasSeparator=false;
+ m_currentTreeHasSeparator= false;
if(allowAlias)
{
- str = convertAlias(str);
+ str= convertAlias(str);
}
- m_command = str;
- bool hasInstruction = readInstructionList(str);
+ m_command= str;
+ bool hasInstruction= readInstructionList(str);
- bool value = hasInstruction;
+ bool value= hasInstruction;
if(!hasInstruction)
{
- m_errorMap.insert(ExecutionNode::NOTHING_UNDERSTOOD,QObject::tr("Nothing was understood. To roll dice: !1d6 - full documation: "
- "<a href=\"https://github.com/Rolisteam/DiceParser/blob/master/HelpMe.md\">https://github.com/Rolisteam/DiceParser/blob/master/HelpMe.md</a>"));
+ m_errorMap.insert(ExecutionNode::NOTHING_UNDERSTOOD,
+ QObject::tr("Nothing was understood. To roll dice: !1d6 - full documation: "
+ "<a "
+ "href=\"https://github.com/Rolisteam/DiceParser/blob/master/HelpMe.md\">https://github.com/"
+ "Rolisteam/DiceParser/blob/master/HelpMe.md</a>"));
}
else if(hasInstruction && !str.isEmpty())
{
- auto i = m_command.size()-str.size();
- m_warningMap.insert(ExecutionNode::UNEXPECTED_CHARACTER,QObject::tr("Unexpected character at %1 - end of command was ignored \"%2\"").arg(i).arg(str));
+ auto i= m_command.size() - str.size();
+ m_warningMap.insert(ExecutionNode::UNEXPECTED_CHARACTER,
+ QObject::tr("Unexpected character at %1 - end of command was ignored \"%2\"").arg(i).arg(str));
}
if(!m_errorMap.isEmpty())
- value = false;
+ value= false;
return value;
}
-bool DiceParser::readExpression(QString& str,ExecutionNode* & node)
+bool DiceParser::readExpression(QString& str, ExecutionNode*& node)
{
- ExecutionNode* operandNode=nullptr;
+ ExecutionNode* operandNode= nullptr;
if(m_parsingToolbox->readOpenParentheses(str))
{
- ExecutionNode* internalNode=nullptr;
- if(readExpression(str,internalNode))
+ ExecutionNode* internalNode= nullptr;
+ if(readExpression(str, internalNode))
{
- ParenthesesNode* parentheseNode = new ParenthesesNode();
+ ParenthesesNode* parentheseNode= new ParenthesesNode();
parentheseNode->setInternelNode(internalNode);
- node = parentheseNode;
+ node= parentheseNode;
if(m_parsingToolbox->readCloseParentheses(str))
{
- ExecutionNode* diceNode=nullptr;
- ExecutionNode* operatorNode=nullptr;
+ ExecutionNode* diceNode= nullptr;
+ ExecutionNode* operatorNode= nullptr;
if(readDice(str, diceNode))
{
parentheseNode->setNextNode(diceNode);
}
- else if(readExpression(str,operatorNode))
+ else if(readExpression(str, operatorNode))
{
parentheseNode->setNextNode(operatorNode);
}
@@ -214,57 +216,58 @@ bool DiceParser::readExpression(QString& str,ExecutionNode* & node)
}
else
{
- m_warningMap.insert(ExecutionNode::BAD_SYNTAXE,QObject::tr("Expected closing parenthesis - can't validate the inside."));
+ m_warningMap.insert(ExecutionNode::BAD_SYNTAXE,
+ QObject::tr("Expected closing parenthesis - can't validate the inside."));
}
}
}
- else if(m_parsingToolbox->readOperand(str,operandNode))
+ else if(m_parsingToolbox->readOperand(str, operandNode))
{
- ExecutionNode* diceNode=nullptr;
- if(readDice(str,diceNode))
+ ExecutionNode* diceNode= nullptr;
+ if(readDice(str, diceNode))
{
operandNode->setNextNode(diceNode);
}
- node = operandNode;
+ node= operandNode;
operandNode= ParsingToolBox::getLatestNode(operandNode);
- //ExecutionNode* operatorNode=nullptr;
- while(readOperator(str,operandNode))
+ // ExecutionNode* operatorNode=nullptr;
+ while(readOperator(str, operandNode))
{
- //operandNode->setNextNode(operatorNode);
+ // operandNode->setNextNode(operatorNode);
operandNode= ParsingToolBox::getLatestNode(operandNode);
};
return true;
}
- else if(readCommand(str,operandNode))
+ else if(readCommand(str, operandNode))
{
- node = operandNode;
+ node= operandNode;
return true;
}
- else if(readNode(str,operandNode))
+ else if(readNode(str, operandNode))
{
- node = operandNode;
+ node= operandNode;
return true;
}
- else if(readOptionFromNull(str,operandNode))
+ else if(readOptionFromNull(str, operandNode))
{
- node = operandNode;
+ node= operandNode;
return true;
}
- else if(readOperatorFromNull(str,operandNode))
+ else if(readOperatorFromNull(str, operandNode))
{
- node = operandNode;
+ node= operandNode;
return true;
}
else
{
- ExecutionNode* diceNode=nullptr;
- if(readDice(str,diceNode))
+ ExecutionNode* diceNode= nullptr;
+ if(readDice(str, diceNode))
{
- NumberNode* numberNode=new NumberNode();
+ NumberNode* numberNode= new NumberNode();
numberNode->setNumber(1);
numberNode->setNextNode(diceNode);
- node = numberNode;
+ node= numberNode;
return true;
}
else
@@ -275,33 +278,33 @@ bool DiceParser::readExpression(QString& str,ExecutionNode* & node)
return false;
}
-bool DiceParser::readOptionFromNull(QString& str,ExecutionNode* & node)
+bool DiceParser::readOptionFromNull(QString& str, ExecutionNode*& node)
{
StartingNode nodePrevious;
- if(readOption(str,&nodePrevious))
+ if(readOption(str, &nodePrevious))
{
- auto nodeNext = nodePrevious.getNextNode();
+ auto nodeNext= nodePrevious.getNextNode();
nodePrevious.setNextNode(nullptr);
- node = nodeNext;
+ node= nodeNext;
return true;
}
return false;
}
-bool DiceParser::readOperatorFromNull(QString& str,ExecutionNode* & node)
+bool DiceParser::readOperatorFromNull(QString& str, ExecutionNode*& node)
{
StartingNode nodePrevious;
- if(readOperator(str,&nodePrevious))
+ if(readOperator(str, &nodePrevious))
{
- auto nodeNext = nodePrevious.getNextNode();
+ auto nodeNext= nodePrevious.getNextNode();
nodePrevious.setNextNode(nullptr);
- node = nodeNext;
+ node= nodeNext;
return true;
}
return false;
}
-bool DiceParser::readNode(QString& str,ExecutionNode* & node)
+bool DiceParser::readNode(QString& str, ExecutionNode*& node)
{
if(str.isEmpty())
return false;
@@ -309,10 +312,10 @@ bool DiceParser::readNode(QString& str,ExecutionNode* & node)
QString key= str.at(0);
if(m_nodeActionMap->contains(key))
{
- JumpBackwardNode* jumpNode = new JumpBackwardNode();
- node = jumpNode;
- str=str.remove(0,1);
- readOption(str,jumpNode);
+ JumpBackwardNode* jumpNode= new JumpBackwardNode();
+ node= jumpNode;
+ str= str.remove(0, 1);
+ readOption(str, jumpNode);
return true;
}
return false;
@@ -331,38 +334,38 @@ QList<qreal> DiceParser::getLastIntegerResults()
QList<qreal> resultValues;
for(auto node : m_startNodes)
{
- ExecutionNode* next = getLeafNode(node);
- Result* result=next->getResult();
- bool scalarDone = false;
- while((result!=nullptr)&&(!scalarDone))
+ ExecutionNode* next= getLeafNode(node);
+ Result* result= next->getResult();
+ bool scalarDone= false;
+ while((result != nullptr) && (!scalarDone))
{
if(result->hasResultOfType(Result::SCALAR))
{
resultValues << result->getResult(Result::SCALAR).toReal();
- scalarDone=true;
+ scalarDone= true;
}
- result=result->getPrevious();
+ result= result->getPrevious();
}
}
return resultValues;
}
-QStringList DiceParser::getStringResult( )
+QStringList DiceParser::getStringResult()
{
QStringList stringListResult;
for(auto node : m_startNodes)
{
- ExecutionNode* next = getLeafNode(node);
+ ExecutionNode* next= getLeafNode(node);
QString str;
- Result* result=next->getResult();
- bool found = false;
- while((nullptr!=result) && (!found) )
+ Result* result= next->getResult();
+ bool found= false;
+ while((nullptr != result) && (!found))
{
if(result->hasResultOfType(Result::STRING))
{
- str = result->getResult(Result::STRING).toString();
- found = true;
+ str= result->getResult(Result::STRING).toString();
+ found= true;
}
- result = result->getPrevious();
+ result= result->getPrevious();
}
stringListResult << str;
}
@@ -370,25 +373,25 @@ QStringList DiceParser::getStringResult( )
}
QStringList DiceParser::getAllStringResult(bool& hasAlias)
{
- //QStringList allResult;
+ // QStringList allResult;
QStringList stringListResult;
for(auto node : m_startNodes)
{
- ExecutionNode* next = getLeafNode(node);
- Result* result=next->getResult();
+ ExecutionNode* next= getLeafNode(node);
+ Result* result= next->getResult();
- while(nullptr!=result)
+ while(nullptr != result)
{
if(result->hasResultOfType(Result::STRING))
{
- StringResult* stringResult = dynamic_cast<StringResult*>(result);
- if(nullptr!=stringResult)
+ StringResult* stringResult= dynamic_cast<StringResult*>(result);
+ if(nullptr != stringResult)
{
stringListResult << stringResult->getText();
- hasAlias = stringResult->hasHighLight();
+ hasAlias= stringResult->hasHighLight();
}
}
- result = result->getPrevious();
+ result= result->getPrevious();
}
}
return stringListResult;
@@ -398,16 +401,16 @@ QStringList DiceParser::getAllDiceResult(bool& hasAlias)
QStringList stringListResult;
for(auto node : m_startNodes)
{
- ExecutionNode* next = getLeafNode(node);
- Result* result=next->getResult();
+ ExecutionNode* next= getLeafNode(node);
+ Result* result= next->getResult();
QList<Die*> dieListResult;
- while(nullptr!=result)
+ while(nullptr != result)
{
if(result->hasResultOfType(Result::DICE_LIST))
{
- DiceResult* stringResult = dynamic_cast<DiceResult*>(result);
- if(nullptr!=stringResult)
+ DiceResult* stringResult= dynamic_cast<DiceResult*>(result);
+ if(nullptr != stringResult)
{
for(auto& die : stringResult->getResultList())
{
@@ -417,10 +420,10 @@ QStringList DiceParser::getAllDiceResult(bool& hasAlias)
dieListResult << die;
}
}
- hasAlias = true;
+ hasAlias= true;
}
}
- result = result->getPrevious();
+ result= result->getPrevious();
}
for(auto& die : dieListResult)
{
@@ -428,7 +431,6 @@ QStringList DiceParser::getAllDiceResult(bool& hasAlias)
{
for(qint64& value : die->getListValue())
{
-
stringListResult << QString::number(value);
}
}
@@ -442,54 +444,54 @@ void DiceParser::getDiceResultFromAllInstruction(QList<ExportedDiceResult>& resu
{
for(auto start : m_startNodes)
{
- ExecutionNode* next = getLeafNode(start);
- Result* result=next->getResult();
- //qDebug() << "result id" << result->toString(true);
+ ExecutionNode* next= getLeafNode(start);
+ Result* result= next->getResult();
+ // qDebug() << "result id" << result->toString(true);
ExportedDiceResult nodeResult;
- while(nullptr!=result)
+ while(nullptr != result)
{
if(result->hasResultOfType(Result::DICE_LIST))
{
- DiceResult* diceResult = dynamic_cast<DiceResult*>(result);
+ DiceResult* diceResult= dynamic_cast<DiceResult*>(result);
QList<HighLightDice> list;
- quint64 faces = 0;
+ quint64 faces= 0;
for(auto& die : diceResult->getResultList())
{
- faces = die->getFaces();
+ faces= die->getFaces();
// qDebug() << "face" << faces;
- HighLightDice hlDice(die->getListValue(),die->isHighlighted(),die->getColor(), die->hasBeenDisplayed(),die->getFaces());
+ HighLightDice hlDice(die->getListValue(), die->isHighlighted(), die->getColor(),
+ die->hasBeenDisplayed(), die->getFaces());
list.append(hlDice);
}
- nodeResult.insert(faces,list);
+ nodeResult.insert(faces, list);
}
- result = result->getPrevious();
+ result= result->getPrevious();
}
resultList.append(nodeResult);
}
- //qDebug() << resultList.size();
+ // qDebug() << resultList.size();
}
-void DiceParser::getLastDiceResult(QList<ExportedDiceResult>& diceValuesList,bool& homogeneous)
+void DiceParser::getLastDiceResult(QList<ExportedDiceResult>& diceValuesList, bool& homogeneous)
{
for(auto start : m_startNodes)
{
ExportedDiceResult diceValues;
- ExecutionNode* next = getLeafNode(start);
- Result* result=next->getResult();
- while(nullptr!=result)
+ ExecutionNode* next= getLeafNode(start);
+ Result* result= next->getResult();
+ while(nullptr != result)
{
if(result->hasResultOfType(Result::DICE_LIST))
{
- DiceResult* diceResult = dynamic_cast<DiceResult*>(result);
- if(nullptr!=diceResult)
+ DiceResult* diceResult= dynamic_cast<DiceResult*>(result);
+ if(nullptr != diceResult)
{
if(homogeneous)
{
-
- homogeneous = diceResult->isHomogeneous();
+ homogeneous= diceResult->isHomogeneous();
}
- quint64 face=0;
+ quint64 face= 0;
ListDiceResult listpair;
for(auto& die : diceResult->getResultList())
{
@@ -498,7 +500,7 @@ void DiceParser::getLastDiceResult(QList<ExportedDiceResult>& diceValuesList,boo
QList<qint64> valuesResult;
valuesResult.append(die->getValue());
die->displayed();
- face = die->getFaces();
+ face= die->getFaces();
if(die->hasChildrenValue())
{
for(qint64& i : die->getListValue())
@@ -506,7 +508,8 @@ void DiceParser::getLastDiceResult(QList<ExportedDiceResult>& diceValuesList,boo
valuesResult.append(i);
}
}
- HighLightDice hlDice(valuesResult,die->isHighlighted(),die->getColor(), die->hasBeenDisplayed(),0);
+ HighLightDice hlDice(
+ valuesResult, die->isHighlighted(), die->getColor(), die->hasBeenDisplayed(), 0);
listpair.append(hlDice);
}
}
@@ -514,18 +517,18 @@ void DiceParser::getLastDiceResult(QList<ExportedDiceResult>& diceValuesList,boo
{
if(!diceValues.contains(face))
{
- diceValues.insert(face,listpair);
+ diceValues.insert(face, listpair);
}
else
{
- ListDiceResult tmp = diceValues.value(face);
+ ListDiceResult tmp= diceValues.value(face);
tmp.append(listpair);
- diceValues.insert(face,tmp);
+ diceValues.insert(face, tmp);
}
}
}
}
- result = result->getPrevious();
+ result= result->getPrevious();
}
if(!diceValues.isEmpty())
{
@@ -543,7 +546,7 @@ bool DiceParser::hasIntegerResultNotInFirst()
bool result= false;
for(auto node : m_startNodes)
{
- result |= hasResultOfType(Result::SCALAR,node);
+ result|= hasResultOfType(Result::SCALAR, node);
}
return result;
}
@@ -553,31 +556,31 @@ bool DiceParser::hasDiceResult()
bool result= false;
for(auto node : m_startNodes)
{
- result |= hasResultOfType(Result::DICE_LIST,node);
+ result|= hasResultOfType(Result::DICE_LIST, node);
}
return result;
}
bool DiceParser::hasStringResult()
{
- bool result = false;
+ bool result= false;
for(auto node : m_startNodes)
{
- result |= hasResultOfType(Result::STRING,node);
+ result|= hasResultOfType(Result::STRING, node);
}
return result;
}
bool DiceParser::hasResultOfType(Result::RESULT_TYPE type, ExecutionNode* node, bool notthelast)
{
- bool scalarDone = false;
- ExecutionNode* next = getLeafNode(node);
- Result* result=next->getResult();
- while((result!=nullptr)&&(!scalarDone))
+ bool scalarDone= false;
+ ExecutionNode* next= getLeafNode(node);
+ Result* result= next->getResult();
+ while((result != nullptr) && (!scalarDone))
{
- if(result->hasResultOfType(type) && ((!notthelast)||(nullptr!=result->getPrevious())))
+ if(result->hasResultOfType(type) && ((!notthelast) || (nullptr != result->getPrevious())))
{
- scalarDone=true;
+ scalarDone= true;
}
- result=result->getPrevious();
+ result= result->getPrevious();
}
return scalarDone;
}
@@ -586,25 +589,25 @@ QList<qreal> DiceParser::getSumOfDiceResult()
QList<qreal> resultValues;
for(auto node : m_startNodes)
{
- qreal resultValue=0;
- ExecutionNode* next = getLeafNode(node);
- Result* result=next->getResult();
- bool found = false;
- while((nullptr!=result)&&(!found))
+ qreal resultValue= 0;
+ ExecutionNode* next= getLeafNode(node);
+ Result* result= next->getResult();
+ bool found= false;
+ while((nullptr != result) && (!found))
{
if(result->hasResultOfType(Result::DICE_LIST))
{
- DiceResult* myDiceResult = dynamic_cast<DiceResult*>(result);
- if(nullptr!=myDiceResult)
+ DiceResult* myDiceResult= dynamic_cast<DiceResult*>(result);
+ if(nullptr != myDiceResult)
{
for(auto& die : myDiceResult->getResultList())
{
- resultValue+=die->getValue();
+ resultValue+= die->getValue();
}
- found = true;
+ found= true;
}
}
- result = result->getPrevious();
+ result= result->getPrevious();
}
resultValues << resultValue;
}
@@ -616,156 +619,155 @@ int DiceParser::getStartNodeCount() const
}
ExecutionNode* DiceParser::getLeafNode(ExecutionNode* start)
{
- ExecutionNode* next = start;
- while(nullptr != next->getNextNode() )
+ ExecutionNode* next= start;
+ while(nullptr != next->getNextNode())
{
- next = next->getNextNode();
+ next= next->getNextNode();
}
return next;
}
-bool DiceParser::readDice(QString& str,ExecutionNode* & node)
+bool DiceParser::readDice(QString& str, ExecutionNode*& node)
{
DiceOperator currentOperator;
- if(readDiceOperator(str,currentOperator))
+ if(readDiceOperator(str, currentOperator))
{
- if(currentOperator==D)
+ if(currentOperator == D)
{
qint64 max;
qint64 min;
- bool unique = (ParsingToolBox::UNIQUE == m_parsingToolbox->readListOperator(str)) ?
- true : false;
+ bool unique= (ParsingToolBox::UNIQUE == m_parsingToolbox->readListOperator(str)) ? true : false;
Die::ArithmeticOperator op;
- bool hasOp= m_parsingToolbox->readArithmeticOperator(str,op);
- if(m_parsingToolbox->readNumber(str,max))
+ bool hasOp= m_parsingToolbox->readArithmeticOperator(str, op);
+ if(m_parsingToolbox->readNumber(str, max))
{
- if(max<1)
+ if(max < 1)
{
- m_errorMap.insert(ExecutionNode::BAD_SYNTAXE,QObject::tr("Dice with %1 face(s) does not exist. Please, put a value higher than 0").arg(max));
+ m_errorMap.insert(ExecutionNode::BAD_SYNTAXE,
+ QObject::tr("Dice with %1 face(s) does not exist. Please, put a value higher than 0").arg(max));
return false;
}
- DiceRollerNode* drNode = new DiceRollerNode(max);
+ DiceRollerNode* drNode= new DiceRollerNode(max);
drNode->setUnique(unique);
if(hasOp)
{
drNode->setOperator(op);
}
- node = drNode;
- ExecutionNode* current = drNode;
- while(readOption(str,current))
+ node= drNode;
+ ExecutionNode* current= drNode;
+ while(readOption(str, current))
{
- current = ParsingToolBox::getLatestNode(current);
+ current= ParsingToolBox::getLatestNode(current);
}
return true;
}
- else if(m_parsingToolbox->readDiceRange(str,min,max))
+ else if(m_parsingToolbox->readDiceRange(str, min, max))
{
- DiceRollerNode* drNode = new DiceRollerNode(max,min);
+ DiceRollerNode* drNode= new DiceRollerNode(max, min);
drNode->setUnique(unique);
if(hasOp)
{
drNode->setOperator(op);
}
- node = drNode;
- ExecutionNode* current = drNode;
- while(readOption(str,current))
+ node= drNode;
+ ExecutionNode* current= drNode;
+ while(readOption(str, current))
{
- current = ParsingToolBox::getLatestNode(current);
+ current= ParsingToolBox::getLatestNode(current);
}
return true;
}
}
- else if(currentOperator ==L)
+ else if(currentOperator == L)
{
QStringList list;
QList<Range> listRange;
- ParsingToolBox::LIST_OPERATOR op = m_parsingToolbox->readListOperator(str);
- if(m_parsingToolbox->readList(str,list,listRange))
+ ParsingToolBox::LIST_OPERATOR op= m_parsingToolbox->readListOperator(str);
+ if(m_parsingToolbox->readList(str, list, listRange))
{
- ListSetRollNode* lsrNode = new ListSetRollNode();
+ ListSetRollNode* lsrNode= new ListSetRollNode();
lsrNode->setRangeList(listRange);
if(op == ParsingToolBox::UNIQUE)
{
lsrNode->setUnique(true);
}
lsrNode->setListValue(list);
- node = lsrNode;
+ node= lsrNode;
return true;
}
else
{
- m_errorMap.insert(ExecutionNode::BAD_SYNTAXE,QObject::tr("List is missing after the L operator. Please, add it (e.g : 1L[sword,spear,gun,arrow])"));
+ m_errorMap.insert(ExecutionNode::BAD_SYNTAXE,
+ QObject::tr(
+ "List is missing after the L operator. Please, add it (e.g : 1L[sword,spear,gun,arrow])"));
}
}
-
}
return false;
-
}
-bool DiceParser::readDiceOperator(QString& str,DiceOperator& op)
+bool DiceParser::readDiceOperator(QString& str, DiceOperator& op)
{
- QStringList listKey = m_mapDiceOp->keys();
+ QStringList listKey= m_mapDiceOp->keys();
for(const QString& key : listKey)
{
- if(str.startsWith(key,Qt::CaseInsensitive))
+ if(str.startsWith(key, Qt::CaseInsensitive))
{
- str=str.remove(0,key.size());
- op = m_mapDiceOp->value(key);
+ str= str.remove(0, key.size());
+ op= m_mapDiceOp->value(key);
return true;
}
}
return false;
}
-bool DiceParser::readCommand(QString& str,ExecutionNode* & node)
+bool DiceParser::readCommand(QString& str, ExecutionNode*& node)
{
if(m_commandList->contains(str))
{
- if(str== QLatin1String("help"))
+ if(str == QLatin1String("help"))
{
- str=str.remove(0,QLatin1String("help").size());
- HelpNode* help = new HelpNode();
+ str= str.remove(0, QLatin1String("help").size());
+ HelpNode* help= new HelpNode();
if(!m_helpPath.isEmpty())
{
help->setHelpPath(m_helpPath);
}
- node = help;
-
+ node= help;
}
- else if(str== QLatin1String("la"))
+ else if(str == QLatin1String("la"))
{
- str=str.remove(0,QLatin1String("la").size());
- node = new ListAliasNode(m_aliasList);
+ str= str.remove(0, QLatin1String("la").size());
+ node= new ListAliasNode(m_aliasList);
}
return true;
}
return false;
}
-bool DiceParser::readDiceExpression(QString& str,ExecutionNode* & node)
+bool DiceParser::readDiceExpression(QString& str, ExecutionNode*& node)
{
- bool returnVal=false;
+ bool returnVal= false;
- ExecutionNode* next = nullptr;
- if(readDice(str,next))
+ ExecutionNode* next= nullptr;
+ if(readDice(str, next))
{
- ExecutionNode* latest = next;
- while(readOption(str,latest))
+ ExecutionNode* latest= next;
+ while(readOption(str, latest))
{
- while(nullptr!=latest->getNextNode())
+ while(nullptr != latest->getNextNode())
{
- latest = latest->getNextNode();
+ latest= latest->getNextNode();
}
}
- node = next;
- returnVal = true;
+ node= next;
+ returnVal= true;
}
else
{
- returnVal = false;
+ returnVal= false;
}
return returnVal;
}
@@ -782,56 +784,56 @@ bool DiceParser::readInstructionList(QString& str)
if(str.isEmpty())
return false;
- bool hasInstruction = false;
- bool readInstruction = true;
+ bool hasInstruction= false;
+ bool readInstruction= true;
while(readInstruction)
{
- ExecutionNode* startNode = nullptr;
- bool keepParsing = readExpression(str,startNode);
+ ExecutionNode* startNode= nullptr;
+ bool keepParsing= readExpression(str, startNode);
if(nullptr != startNode)
{
- hasInstruction = true;
+ hasInstruction= true;
m_startNodes.push_back(startNode);
- auto latest = startNode;
+ auto latest= startNode;
if(keepParsing)
{
- latest = ParsingToolBox::getLatestNode(latest);
- keepParsing =!str.isEmpty();
+ latest= ParsingToolBox::getLatestNode(latest);
+ keepParsing= !str.isEmpty();
while(keepParsing)
{
- auto before = str;
- if(readOperator(str,latest))
+ auto before= str;
+ if(readOperator(str, latest))
{
- latest = ParsingToolBox::getLatestNode(latest);
+ latest= ParsingToolBox::getLatestNode(latest);
}
- keepParsing = (!str.isEmpty() && (before!=str));
+ keepParsing= (!str.isEmpty() && (before != str));
}
}
- if( !str.isEmpty() && readInstructionOperator(str[0]))
+ if(!str.isEmpty() && readInstructionOperator(str[0]))
{
- str=str.remove(0,1);
+ str= str.remove(0, 1);
}
else
{
QString result;
QString comment;
- if(m_parsingToolbox->readComment(str,result,comment))
+ if(m_parsingToolbox->readComment(str, result, comment))
{
m_command.remove(comment);
- m_comment = result;
+ m_comment= result;
}
- readInstruction = false;
+ readInstruction= false;
}
}
else
{
- readInstruction = false;
+ readInstruction= false;
}
}
return hasInstruction;
}
-bool DiceParser::readOperator(QString& str,ExecutionNode* previous)
+bool DiceParser::readOperator(QString& str, ExecutionNode* previous)
{
if(str.isEmpty() || nullptr == previous)
{
@@ -839,44 +841,44 @@ bool DiceParser::readOperator(QString& str,ExecutionNode* previous)
}
Die::ArithmeticOperator op;
- if(m_parsingToolbox->readArithmeticOperator(str,op))
+ if(m_parsingToolbox->readArithmeticOperator(str, op))
{
- ScalarOperatorNode* node = new ScalarOperatorNode();
+ ScalarOperatorNode* node= new ScalarOperatorNode();
node->setArithmeticOperator(op);
- ExecutionNode* nodeExec = nullptr;
- if(readExpression(str,nodeExec))
+ ExecutionNode* nodeExec= nullptr;
+ if(readExpression(str, nodeExec))
{
node->setInternalNode(nodeExec);
- if(nullptr==nodeExec)
+ if(nullptr == nodeExec)
{
delete node;
return false;
}
- ExecutionNode* nodeExecOrChild = nodeExec;
- ExecutionNode* parent = nullptr;
+ ExecutionNode* nodeExecOrChild= nodeExec;
+ ExecutionNode* parent= nullptr;
- while((nullptr!=nodeExecOrChild) && (node->getPriority()<nodeExecOrChild->getPriority()))
+ while((nullptr != nodeExecOrChild) && (node->getPriority() < nodeExecOrChild->getPriority()))
{
- parent = nodeExecOrChild;
- nodeExecOrChild = nodeExecOrChild->getNextNode();
+ parent= nodeExecOrChild;
+ nodeExecOrChild= nodeExecOrChild->getNextNode();
}
// management of operator priority
- if((nullptr != nodeExecOrChild)&&(nodeExec != nodeExecOrChild))
+ if((nullptr != nodeExecOrChild) && (nodeExec != nodeExecOrChild))
{
// good 1 1 2 ; bad 1 0 4
- if(nodeExecOrChild->getPriority()>=node->getPriority())
+ if(nodeExecOrChild->getPriority() >= node->getPriority())
{
node->setNextNode(nodeExecOrChild);
parent->setNextNode(nullptr);
}
}
- else if(node->getPriority()>=nodeExec->getPriority())
+ else if(node->getPriority() >= nodeExec->getPriority())
{
node->setNextNode(nodeExec->getNextNode());
nodeExec->setNextNode(nullptr);
}
- //nodeResult = node;
+ // nodeResult = node;
previous->setNextNode(node);
return true;
@@ -888,255 +890,255 @@ bool DiceParser::readOperator(QString& str,ExecutionNode* previous)
}
else
{
- while(readOption(str,previous))
+ while(readOption(str, previous))
{
- previous = ParsingToolBox::getLatestNode(previous);
+ previous= ParsingToolBox::getLatestNode(previous);
}
}
return false;
}
-bool DiceParser::hasSeparator()const
+bool DiceParser::hasSeparator() const
{
return m_currentTreeHasSeparator;
}
-DiceRollerNode* DiceParser::addRollDiceNode(qint64 faces,ExecutionNode* previous)
+DiceRollerNode* DiceParser::addRollDiceNode(qint64 faces, ExecutionNode* previous)
{
DiceRollerNode* mydiceRoller= new DiceRollerNode(faces);
previous->setNextNode(mydiceRoller);
return mydiceRoller;
}
-ExplodeDiceNode* DiceParser::addExplodeDiceNode(qint64 value,ExecutionNode* previous)
+ExplodeDiceNode* DiceParser::addExplodeDiceNode(qint64 value, ExecutionNode* previous)
{
ExplodeDiceNode* explodeDiceNode= new ExplodeDiceNode();
- NumberNode* node = new NumberNode();
+ NumberNode* node= new NumberNode();
node->setNumber(value);
- BooleanCondition* condition = new BooleanCondition();
+ BooleanCondition* condition= new BooleanCondition();
condition->setValueNode(node);
condition->setOperator(BooleanCondition::Equal);
- m_parsingToolbox->isValidValidator(previous,condition);
+ m_parsingToolbox->isValidValidator(previous, condition);
explodeDiceNode->setValidator(condition);
previous->setNextNode(explodeDiceNode);
return explodeDiceNode;
}
-bool DiceParser::readOption(QString& str,ExecutionNode* previous)//,
+bool DiceParser::readOption(QString& str, ExecutionNode* previous) //,
{
if(str.isEmpty())
{
return false;
}
- ExecutionNode* node = nullptr;
- bool found=false;
- auto keys = m_OptionOp->keys();
- for(int i = 0; ((i<keys.size())&&(!found));++i )
+ ExecutionNode* node= nullptr;
+ bool found= false;
+ auto keys= m_OptionOp->keys();
+ for(int i= 0; ((i < keys.size()) && (!found)); ++i)
{
- QString key = keys.at(i);
+ QString key= keys.at(i);
if(str.startsWith(key))
{
-
- str=str.remove(0,key.size());
- auto operatorName = m_OptionOp->value(key);
+ str= str.remove(0, key.size());
+ auto operatorName= m_OptionOp->value(key);
switch(operatorName)
{
case Keep:
{
- qint64 myNumber=0;
- bool ascending = m_parsingToolbox->readAscending(str);
+ qint64 myNumber= 0;
+ bool ascending= m_parsingToolbox->readAscending(str);
- if(m_parsingToolbox->readNumber(str,myNumber))
+ if(m_parsingToolbox->readNumber(str, myNumber))
{
- node = m_parsingToolbox->addSort(previous,ascending);
- KeepDiceExecNode* nodeK = new KeepDiceExecNode();
+ node= m_parsingToolbox->addSort(previous, ascending);
+ KeepDiceExecNode* nodeK= new KeepDiceExecNode();
nodeK->setDiceKeepNumber(myNumber);
node->setNextNode(nodeK);
- node = nodeK;
- found = true;
+ node= nodeK;
+ found= true;
}
}
- break;
+ break;
case KeepAndExplode:
{
- qint64 myNumber=0;
- bool ascending = m_parsingToolbox->readAscending(str);
- if(m_parsingToolbox->readNumber(str,myNumber))
+ qint64 myNumber= 0;
+ bool ascending= m_parsingToolbox->readAscending(str);
+ if(m_parsingToolbox->readNumber(str, myNumber))
{
/* if(!hasDice)
{
previous = addRollDiceNode(DEFAULT_FACES_NUMBER,previous);
}*/
- DiceRollerNode* nodeTmp = dynamic_cast<DiceRollerNode*>(previous);
- if(nullptr!=nodeTmp)
+ DiceRollerNode* nodeTmp= dynamic_cast<DiceRollerNode*>(previous);
+ if(nullptr != nodeTmp)
{
- previous = addExplodeDiceNode(static_cast<qint64>(nodeTmp->getFaces()),previous);
+ previous= addExplodeDiceNode(static_cast<qint64>(nodeTmp->getFaces()), previous);
}
- node = m_parsingToolbox->addSort(previous,ascending);
+ node= m_parsingToolbox->addSort(previous, ascending);
- KeepDiceExecNode* nodeK = new KeepDiceExecNode();
+ KeepDiceExecNode* nodeK= new KeepDiceExecNode();
nodeK->setDiceKeepNumber(myNumber);
node->setNextNode(nodeK);
- node = nodeK;
- found = true;
+ node= nodeK;
+ found= true;
}
}
- break;
+ break;
case Filter:
{
- Validator* validator = m_parsingToolbox->readCompositeValidator(str);
- if(nullptr!=validator)
+ Validator* validator= m_parsingToolbox->readCompositeValidator(str);
+ if(nullptr != validator)
{
- m_parsingToolbox->isValidValidator(previous,validator);
+ m_parsingToolbox->isValidValidator(previous, validator);
- FilterNode* filterNode = new FilterNode();
+ FilterNode* filterNode= new FilterNode();
filterNode->setValidator(validator);
previous->setNextNode(filterNode);
- node = filterNode;
- found = true;
+ node= filterNode;
+ found= true;
}
}
- break;
+ break;
case Sort:
{
- bool ascending = m_parsingToolbox->readAscending(str);
- node = m_parsingToolbox->addSort(previous,ascending);
+ bool ascending= m_parsingToolbox->readAscending(str);
+ node= m_parsingToolbox->addSort(previous, ascending);
/*if(!hasDice)
{
- m_errorMap.insert(ExecutionNode::BAD_SYNTAXE,QObject::tr("Sort Operator does not support default dice. You should add dice command before the s"));
+ m_errorMap.insert(ExecutionNode::BAD_SYNTAXE,QObject::tr("Sort Operator does not support default
+ dice. You should add dice command before the s"));
}*/
- found = true;
+ found= true;
}
- break;
+ break;
case Count:
{
- Validator* validator = m_parsingToolbox->readCompositeValidator(str);
- if(nullptr!=validator)
+ Validator* validator= m_parsingToolbox->readCompositeValidator(str);
+ if(nullptr != validator)
{
- m_parsingToolbox->isValidValidator(previous,validator);
+ m_parsingToolbox->isValidValidator(previous, validator);
- CountExecuteNode* countNode = new CountExecuteNode();
+ CountExecuteNode* countNode= new CountExecuteNode();
countNode->setValidator(validator);
previous->setNextNode(countNode);
- node = countNode;
- found = true;
+ node= countNode;
+ found= true;
}
else
{
- m_errorMap.insert(ExecutionNode::BAD_SYNTAXE,QObject::tr("Validator is missing after the c operator. Please, change it"));
+ m_errorMap.insert(ExecutionNode::BAD_SYNTAXE,
+ QObject::tr("Validator is missing after the c operator. Please, change it"));
}
}
- break;
+ break;
case Reroll:
case RerollUntil:
case RerollAndAdd:
// Todo: I think that Exploding and Rerolling could share the same code
- {
- Validator* validator = m_parsingToolbox->readCompositeValidator(str);
- if(nullptr!=validator)
{
- if(!m_parsingToolbox->isValidValidator(previous,validator))
+ Validator* validator= m_parsingToolbox->readCompositeValidator(str);
+ if(nullptr != validator)
{
- m_errorMap.insert(ExecutionNode::BAD_SYNTAXE,QObject::tr("Validator is missing after the %1 operator. Please, change it")
- .arg(operatorName == Reroll ? "r" : "a" ));
- }
+ if(!m_parsingToolbox->isValidValidator(previous, validator))
+ {
+ m_errorMap.insert(ExecutionNode::BAD_SYNTAXE,
+ QObject::tr("Validator is missing after the %1 operator. Please, change it")
+ .arg(operatorName == Reroll ? "r" : "a"));
+ }
- auto reroll = (operatorName==RerollAndAdd || operatorName==Reroll);
- auto addingMode = (operatorName==RerollAndAdd);
- RerollDiceNode* rerollNode = new RerollDiceNode(reroll, addingMode);
- ExecutionNode* nodeParam = nullptr;
- if(readParameterNode(str,nodeParam))
+ auto reroll= (operatorName == RerollAndAdd || operatorName == Reroll);
+ auto addingMode= (operatorName == RerollAndAdd);
+ RerollDiceNode* rerollNode= new RerollDiceNode(reroll, addingMode);
+ ExecutionNode* nodeParam= nullptr;
+ if(readParameterNode(str, nodeParam))
+ {
+ rerollNode->setInstruction(nodeParam);
+ }
+ rerollNode->setValidator(validator);
+ previous->setNextNode(rerollNode);
+ node= rerollNode;
+ found= true;
+ }
+ else
{
- rerollNode->setInstruction(nodeParam);
+ m_errorMap.insert(ExecutionNode::BAD_SYNTAXE,
+ QObject::tr("Validator is missing after the %1 operator. Please, change it")
+ .arg(operatorName == Reroll ? QStringLiteral("r") :
+ operatorName == RerollUntil ?
+ QStringLiteral("R") :
+ operatorName == RerollAndAdd ? QStringLiteral("a") : ""));
}
- rerollNode->setValidator(validator);
- previous->setNextNode(rerollNode);
- node = rerollNode;
- found = true;
-
- }
- else
- {
- m_errorMap.insert(ExecutionNode::BAD_SYNTAXE,
- QObject::tr("Validator is missing after the %1 operator. Please, change it")
- .arg(operatorName==Reroll? QStringLiteral("r")
- :operatorName==RerollUntil? QStringLiteral("R")
- :operatorName==RerollAndAdd? QStringLiteral("a")
- :""));
}
-
- }
break;
case Explode:
{
- Validator* validator = m_parsingToolbox->readCompositeValidator(str);
- if(nullptr!=validator)
+ Validator* validator= m_parsingToolbox->readCompositeValidator(str);
+ if(nullptr != validator)
{
- if(!m_parsingToolbox->isValidValidator(previous,validator))
+ if(!m_parsingToolbox->isValidValidator(previous, validator))
{
- m_errorMap.insert(ExecutionNode::ENDLESS_LOOP_ERROR,QObject::tr("This condition %1 introduces an endless loop. Please, change it").arg(validator->toString()));
+ m_errorMap.insert(ExecutionNode::ENDLESS_LOOP_ERROR,
+ QObject::tr("This condition %1 introduces an endless loop. Please, change it")
+ .arg(validator->toString()));
}
- ExplodeDiceNode* explodedNode = new ExplodeDiceNode();
+ ExplodeDiceNode* explodedNode= new ExplodeDiceNode();
explodedNode->setValidator(validator);
previous->setNextNode(explodedNode);
- node = explodedNode;
- found = true;
-
+ node= explodedNode;
+ found= true;
}
else
{
- m_errorMap.insert(ExecutionNode::BAD_SYNTAXE,QObject::tr("Validator is missing after the e operator. Please, change it"));
+ m_errorMap.insert(ExecutionNode::BAD_SYNTAXE,
+ QObject::tr("Validator is missing after the e operator. Please, change it"));
}
}
- break;
+ break;
case Merge:
{
- MergeNode* mergeNode = new MergeNode();
+ MergeNode* mergeNode= new MergeNode();
mergeNode->setStartList(&m_startNodes);
previous->setNextNode(mergeNode);
- node = mergeNode;
- found = true;
-
+ node= mergeNode;
+ found= true;
}
- break;
+ break;
case Bind:
{
- BindNode* bindNode = new BindNode();
+ BindNode* bindNode= new BindNode();
bindNode->setStartList(&m_startNodes);
previous->setNextNode(bindNode);
- node = bindNode;
- found = true;
-
+ node= bindNode;
+ found= true;
}
- break;
+ break;
case Painter:
{
- PainterNode* painter = new PainterNode();
- m_parsingToolbox->readPainterParameter(painter,str);
+ PainterNode* painter= new PainterNode();
+ m_parsingToolbox->readPainterParameter(painter, str);
previous->setNextNode(painter);
- node = painter;
- found = true;
+ node= painter;
+ found= true;
}
- break;
+ break;
case ifOperator:
{
- IfNode* nodeif = new IfNode();
+ IfNode* nodeif= new IfNode();
nodeif->setConditionType(m_parsingToolbox->readConditionType(str));
- Validator* validator = m_parsingToolbox->readCompositeValidator(str);
- if(nullptr!=validator)
+ Validator* validator= m_parsingToolbox->readCompositeValidator(str);
+ if(nullptr != validator)
{
- ExecutionNode* trueNode = nullptr;
- ExecutionNode* falseNode = nullptr;
- if(readIfInstruction(str,trueNode,falseNode))
+ ExecutionNode* trueNode= nullptr;
+ ExecutionNode* falseNode= nullptr;
+ if(readIfInstruction(str, trueNode, falseNode))
{
nodeif->setInstructionTrue(trueNode);
nodeif->setInstructionFalse(falseNode);
nodeif->setValidator(validator);
previous->setNextNode(nodeif);
- node = nodeif;
- found = true;
+ node= nodeif;
+ found= true;
}
else
{
@@ -1151,36 +1153,35 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous)//,
}
case Split:
{
- SplitNode* splitnode = new SplitNode();
+ SplitNode* splitnode= new SplitNode();
previous->setNextNode(splitnode);
- node = splitnode;
- found = true;
+ node= splitnode;
+ found= true;
}
- break;
+ break;
case Group:
{
- qint64 groupNumber=0;
- if(m_parsingToolbox->readNumber(str,groupNumber))
+ qint64 groupNumber= 0;
+ if(m_parsingToolbox->readNumber(str, groupNumber))
{
- GroupNode* groupNode = new GroupNode();
+ GroupNode* groupNode= new GroupNode();
groupNode->setGroupValue(groupNumber);
previous->setNextNode(groupNode);
- node = groupNode;
- found = true;
+ node= groupNode;
+ found= true;
}
}
- break;
-
+ break;
}
}
}
return found;
}
-bool DiceParser::readIfInstruction(QString& str,ExecutionNode*& trueNode,ExecutionNode*& falseNode)
+bool DiceParser::readIfInstruction(QString& str, ExecutionNode*& trueNode, ExecutionNode*& falseNode)
{
- if(readBlocInstruction(str,trueNode))
+ if(readBlocInstruction(str, trueNode))
{
- if(readBlocInstruction(str,falseNode))
+ if(readBlocInstruction(str, falseNode))
{
return true;
}
@@ -1189,16 +1190,16 @@ bool DiceParser::readIfInstruction(QString& str,ExecutionNode*& trueNode,Executi
return false;
}
-bool DiceParser::readParameterNode(QString& str, ExecutionNode* & node)
+bool DiceParser::readParameterNode(QString& str, ExecutionNode*& node)
{
if(str.startsWith("("))
{
- str=str.remove(0,1);
- if(readExpression(str,node))
+ str= str.remove(0, 1);
+ if(readExpression(str, node))
{
if(str.startsWith(")"))
{
- str=str.remove(0,1);
+ str= str.remove(0, 1);
return true;
}
}
@@ -1206,33 +1207,33 @@ bool DiceParser::readParameterNode(QString& str, ExecutionNode* & node)
return false;
}
-bool DiceParser::readBlocInstruction(QString& str,ExecutionNode*& resultnode)
+bool DiceParser::readBlocInstruction(QString& str, ExecutionNode*& resultnode)
{
if(str.startsWith('{'))
{
- str=str.remove(0,1);
- ExecutionNode* node = nullptr;
+ str= str.remove(0, 1);
+ ExecutionNode* node= nullptr;
Die::ArithmeticOperator op;
- ScalarOperatorNode* scalarNode = nullptr;
- if(m_parsingToolbox->readArithmeticOperator(str,op))
+ ScalarOperatorNode* scalarNode= nullptr;
+ if(m_parsingToolbox->readArithmeticOperator(str, op))
{
- scalarNode = new ScalarOperatorNode();
+ scalarNode= new ScalarOperatorNode();
scalarNode->setArithmeticOperator(op);
}
- if(readExpression(str,node))
+ if(readExpression(str, node))
{
if(str.startsWith('}'))
{
- if(nullptr==scalarNode)
+ if(nullptr == scalarNode)
{
- resultnode = node;
+ resultnode= node;
}
else
{
- resultnode = scalarNode;
+ resultnode= scalarNode;
scalarNode->setInternalNode(node);
}
- str=str.remove(0,1);
+ str= str.remove(0, 1);
return true;
}
}
@@ -1245,39 +1246,39 @@ QString DiceParser::getComment() const
return m_comment;
}
-void DiceParser::setComment(const QString &comment)
+void DiceParser::setComment(const QString& comment)
{
- m_comment = comment;
+ m_comment= comment;
}
-QMap<ExecutionNode::DICE_ERROR_CODE,QString> DiceParser::getErrorMap()
+QMap<ExecutionNode::DICE_ERROR_CODE, QString> DiceParser::getErrorMap()
{
- QMap<ExecutionNode::DICE_ERROR_CODE,QString> map;
+ QMap<ExecutionNode::DICE_ERROR_CODE, QString> map;
for(auto start : m_startNodes)
{
- auto mapTmp = start->getExecutionErrorMap();
- auto keys = mapTmp.keys();
+ auto mapTmp= start->getExecutionErrorMap();
+ auto keys= mapTmp.keys();
for(auto& key : keys)
{
- map.insertMulti(key,mapTmp[key]);
+ map.insertMulti(key, mapTmp[key]);
}
}
return map;
}
QString DiceParser::humanReadableError()
{
- QMapIterator<ExecutionNode::DICE_ERROR_CODE,QString> i(m_errorMap);
+ QMapIterator<ExecutionNode::DICE_ERROR_CODE, QString> i(m_errorMap);
QString str("");
- while (i.hasNext())
+ while(i.hasNext())
{
i.next();
str.append(i.value());
str.append(QStringLiteral("\n"));
}
- ///list
- QMapIterator<ExecutionNode::DICE_ERROR_CODE,QString> j(getErrorMap());
+ /// list
+ QMapIterator<ExecutionNode::DICE_ERROR_CODE, QString> j(getErrorMap());
while(j.hasNext())
{
j.next();
@@ -1289,9 +1290,9 @@ QString DiceParser::humanReadableError()
QString DiceParser::humanReadableWarning()
{
- QMapIterator<ExecutionNode::DICE_ERROR_CODE,QString> i(m_warningMap);
+ QMapIterator<ExecutionNode::DICE_ERROR_CODE, QString> i(m_warningMap);
QString str("");
- while (i.hasNext())
+ while(i.hasNext())
{
i.next();
str.append(i.value());
@@ -1321,9 +1322,9 @@ void DiceParser::writeDownDotTree(QString filepath)
}
void DiceParser::setPathToHelp(QString l)
{
- m_helpPath = l;
+ m_helpPath= l;
}
-void DiceParser::setVariableDictionary(const QHash<QString,QString>& variables)
+void DiceParser::setVariableDictionary(const QHash<QString, QString>& variables)
{
ParsingToolBox::setVariableHash(variables);
}