aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/diceparser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'diceparser.cpp')
-rw-r--r--diceparser.cpp57
1 files changed, 29 insertions, 28 deletions
diff --git a/diceparser.cpp b/diceparser.cpp
index 4ec44ef..da838f1 100644
--- a/diceparser.cpp
+++ b/diceparser.cpp
@@ -29,6 +29,7 @@
#include "node/bind.h"
#include "node/countexecutenode.h"
#include "node/dicerollernode.h"
+#include "node/executionnode.h"
#include "node/explodedicenode.h"
#include "node/filternode.h"
#include "node/groupnode.h"
@@ -180,7 +181,7 @@ bool DiceParser::parseLine(QString str, bool allowAlias)
if(!hasInstruction)
{
m_errorMap.insert(
- ExecutionNode::NOTHING_UNDERSTOOD,
+ Dice::ERROR_CODE::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/"
@@ -190,7 +191,7 @@ bool DiceParser::parseLine(QString str, bool allowAlias)
{
auto i= m_command.size() - str.size();
m_warningMap.insert(
- ExecutionNode::UNEXPECTED_CHARACTER,
+ Dice::ERROR_CODE::UNEXPECTED_CHARACTER,
QObject::tr("Unexpected character at %1 - end of command was ignored \"%2\"").arg(i).arg(str));
}
if(!m_errorMap.isEmpty())
@@ -226,7 +227,7 @@ bool DiceParser::readExpression(QString& str, ExecutionNode*& node)
}
else
{
- m_warningMap.insert(ExecutionNode::BAD_SYNTAXE,
+ m_warningMap.insert(Dice::ERROR_CODE::BAD_SYNTAXE,
QObject::tr("Expected closing parenthesis - can't validate the inside."));
}
}
@@ -392,11 +393,11 @@ QList<qreal> DiceParser::getLastIntegerResults()
bool scalarDone= false;
while((result != nullptr) && (!scalarDone))
{
- if(result->hasResultOfType(Result::SCALAR))
+ if(result->hasResultOfType(Dice::RESULT_TYPE::SCALAR))
{
if(!alreadyVisitedNode.contains(result->getId()))
{
- resultValues << result->getResult(Result::SCALAR).toReal();
+ resultValues << result->getResult(Dice::RESULT_TYPE::SCALAR).toReal();
alreadyVisitedNode << result->getId();
}
scalarDone= true;
@@ -417,9 +418,9 @@ QStringList DiceParser::getStringResult()
bool found= false;
while((nullptr != result) && (!found))
{
- if(result->hasResultOfType(Result::STRING))
+ if(result->hasResultOfType(Dice::RESULT_TYPE::STRING))
{
- str= result->getResult(Result::STRING).toString();
+ str= result->getResult(Dice::RESULT_TYPE::STRING).toString();
found= true;
}
result= result->getPrevious();
@@ -440,7 +441,7 @@ QStringList DiceParser::getAllStringResult(bool& hasAlias)
while(nullptr != result)
{
- if(result->hasResultOfType(Result::STRING))
+ if(result->hasResultOfType(Dice::RESULT_TYPE::STRING))
{
StringResult* stringResult= dynamic_cast<StringResult*>(result);
if(nullptr != stringResult)
@@ -465,7 +466,7 @@ QStringList DiceParser::getAllDiceResult(bool& hasAlias)
while(nullptr != result)
{
- if(result->hasResultOfType(Result::DICE_LIST))
+ if(result->hasResultOfType(Dice::RESULT_TYPE::DICE_LIST))
{
DiceResult* stringResult= dynamic_cast<DiceResult*>(result);
if(nullptr != stringResult)
@@ -508,7 +509,7 @@ void DiceParser::getDiceResultFromAllInstruction(QList<ExportedDiceResult>& resu
ExportedDiceResult nodeResult;
while(nullptr != result)
{
- if(result->hasResultOfType(Result::DICE_LIST))
+ if(result->hasResultOfType(Dice::RESULT_TYPE::DICE_LIST))
{
DiceResult* diceResult= dynamic_cast<DiceResult*>(result);
QList<HighLightDice> list;
@@ -540,7 +541,7 @@ void DiceParser::getLastDiceResult(QList<ExportedDiceResult>& diceValuesList, bo
Result* result= next->getResult();
while(nullptr != result)
{
- if(result->hasResultOfType(Result::DICE_LIST))
+ if(result->hasResultOfType(Dice::RESULT_TYPE::DICE_LIST))
{
DiceResult* diceResult= dynamic_cast<DiceResult*>(result);
if(nullptr != diceResult)
@@ -604,7 +605,7 @@ bool DiceParser::hasIntegerResultNotInFirst()
bool result= false;
for(auto node : m_startNodes)
{
- result|= hasResultOfType(Result::SCALAR, node);
+ result|= hasResultOfType(Dice::RESULT_TYPE::SCALAR, node);
}
return result;
}
@@ -614,7 +615,7 @@ bool DiceParser::hasDiceResult()
bool result= false;
for(auto node : m_startNodes)
{
- result|= hasResultOfType(Result::DICE_LIST, node);
+ result|= hasResultOfType(Dice::RESULT_TYPE::DICE_LIST, node);
}
return result;
}
@@ -623,11 +624,11 @@ bool DiceParser::hasStringResult()
bool result= false;
for(auto node : m_startNodes)
{
- result|= hasResultOfType(Result::STRING, node);
+ result|= hasResultOfType(Dice::RESULT_TYPE::STRING, node);
}
return result;
}
-bool DiceParser::hasResultOfType(Result::RESULT_TYPE type, ExecutionNode* node, bool notthelast)
+bool DiceParser::hasResultOfType(Dice::RESULT_TYPE type, ExecutionNode* node, bool notthelast)
{
bool scalarDone= false;
ExecutionNode* next= getLeafNode(node);
@@ -653,7 +654,7 @@ QList<qreal> DiceParser::getSumOfDiceResult()
bool found= false;
while((nullptr != result) && (!found))
{
- if(result->hasResultOfType(Result::DICE_LIST))
+ if(result->hasResultOfType(Dice::RESULT_TYPE::DICE_LIST))
{
DiceResult* myDiceResult= dynamic_cast<DiceResult*>(result);
if(nullptr != myDiceResult)
@@ -704,7 +705,7 @@ bool DiceParser::readDice(QString& str, ExecutionNode*& node)
if(max < 1)
{
m_errorMap.insert(
- ExecutionNode::BAD_SYNTAXE,
+ Dice::ERROR_CODE::BAD_SYNTAXE,
QObject::tr("Dice with %1 face(s) does not exist. Please, put a value higher than 0").arg(max));
return false;
}
@@ -759,7 +760,7 @@ bool DiceParser::readDice(QString& str, ExecutionNode*& node)
else
{
m_errorMap.insert(
- ExecutionNode::BAD_SYNTAXE,
+ Dice::ERROR_CODE::BAD_SYNTAXE,
QObject::tr(
"List is missing after the L operator. Please, add it (e.g : 1L[sword,spear,gun,arrow])"));
}
@@ -1087,7 +1088,7 @@ bool DiceParser::readOption(QString& str, ExecutionNode* previous) //,
}
else
{
- m_errorMap.insert(ExecutionNode::BAD_SYNTAXE,
+ m_errorMap.insert(Dice::ERROR_CODE::BAD_SYNTAXE,
QObject::tr("Validator is missing after the c operator. Please, change it"));
}
}
@@ -1103,7 +1104,7 @@ bool DiceParser::readOption(QString& str, ExecutionNode* previous) //,
if(!m_parsingToolbox->isValidValidator(previous, validator))
{
m_errorMap.insert(
- ExecutionNode::BAD_SYNTAXE,
+ Dice::ERROR_CODE::BAD_SYNTAXE,
QObject::tr("Validator is missing after the %1 operator. Please, change it")
.arg(operatorName == Reroll ? "r" : "a"));
}
@@ -1123,7 +1124,7 @@ bool DiceParser::readOption(QString& str, ExecutionNode* previous) //,
}
else
{
- m_errorMap.insert(ExecutionNode::BAD_SYNTAXE,
+ m_errorMap.insert(Dice::ERROR_CODE::BAD_SYNTAXE,
QObject::tr("Validator is missing after the %1 operator. Please, change it")
.arg(operatorName == Reroll ?
QStringLiteral("r") :
@@ -1140,7 +1141,7 @@ bool DiceParser::readOption(QString& str, ExecutionNode* previous) //,
{
if(!m_parsingToolbox->isValidValidator(previous, validator))
{
- m_errorMap.insert(ExecutionNode::ENDLESS_LOOP_ERROR,
+ m_errorMap.insert(Dice::ERROR_CODE::ENDLESS_LOOP_ERROR,
QObject::tr("This condition %1 introduces an endless loop. Please, change it")
.arg(validator->toString()));
}
@@ -1152,7 +1153,7 @@ bool DiceParser::readOption(QString& str, ExecutionNode* previous) //,
}
else
{
- m_errorMap.insert(ExecutionNode::BAD_SYNTAXE,
+ m_errorMap.insert(Dice::ERROR_CODE::BAD_SYNTAXE,
QObject::tr("Validator is missing after the e operator. Please, change it"));
}
}
@@ -1345,9 +1346,9 @@ void DiceParser::setComment(const QString& comment)
m_comment= comment;
}
-QMap<ExecutionNode::DICE_ERROR_CODE, QString> DiceParser::getErrorMap()
+QMap<Dice::ERROR_CODE, QString> DiceParser::getErrorMap()
{
- QMap<ExecutionNode::DICE_ERROR_CODE, QString> map;
+ QMap<Dice::ERROR_CODE, QString> map;
for(auto start : m_startNodes)
{
@@ -1362,7 +1363,7 @@ QMap<ExecutionNode::DICE_ERROR_CODE, QString> DiceParser::getErrorMap()
}
QString DiceParser::humanReadableError()
{
- QMapIterator<ExecutionNode::DICE_ERROR_CODE, QString> i(m_errorMap);
+ QMapIterator<Dice::ERROR_CODE, QString> i(m_errorMap);
QString str("");
while(i.hasNext())
{
@@ -1372,7 +1373,7 @@ QString DiceParser::humanReadableError()
}
/// list
- QMapIterator<ExecutionNode::DICE_ERROR_CODE, QString> j(getErrorMap());
+ QMapIterator<Dice::ERROR_CODE, QString> j(getErrorMap());
while(j.hasNext())
{
j.next();
@@ -1384,7 +1385,7 @@ QString DiceParser::humanReadableError()
QString DiceParser::humanReadableWarning()
{
- QMapIterator<ExecutionNode::DICE_ERROR_CODE, QString> i(m_warningMap);
+ QMapIterator<Dice::ERROR_CODE, QString> i(m_warningMap);
QString str("");
while(i.hasNext())
{