aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/diceparser.cpp
diff options
context:
space:
mode:
authorRenaud G <renaud@rolisteam.org>2018-04-10 20:43:24 +0200
committerRenaud G <renaud@rolisteam.org>2018-04-11 00:18:05 +0200
commitd205f806d0bcfc119e2ecd3ea063288877064dde (patch)
treee1bd4b4741143972aabdeeef2cb2146eac41265b /diceparser.cpp
parent826f21f33721f0c232e1440ab8c4d04a822aff8c (diff)
downloadOneRoll-d205f806d0bcfc119e2ecd3ea063288877064dde.tar.gz
OneRoll-d205f806d0bcfc119e2ecd3ea063288877064dde.zip
-Add support for subcommand on reroll operator.
Diffstat (limited to 'diceparser.cpp')
-rw-r--r--diceparser.cpp33
1 files changed, 31 insertions, 2 deletions
diff --git a/diceparser.cpp b/diceparser.cpp
index d76c474..f23cad4 100644
--- a/diceparser.cpp
+++ b/diceparser.cpp
@@ -955,7 +955,8 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous)//,
{
str=str.remove(0,tmp.size());
- switch(m_OptionOp->value(tmp))
+ auto operatorName = m_OptionOp->value(tmp);
+ switch(operatorName)
{
case Keep:
{
@@ -1055,8 +1056,17 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous)//,
Validator* validator = m_parsingToolbox->readCompositeValidator(str);
if(nullptr!=validator)
{
- m_parsingToolbox->isValidValidator(previous,validator);
+ 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" ));
+ }
RerollDiceNode* rerollNode = new RerollDiceNode();
+ ExecutionNode* nodeParam = nullptr;
+ if(readParameterNode(str,nodeParam))
+ {
+ rerollNode->setInstruction(nodeParam);
+ }
if(m_OptionOp->value(tmp)==RerollAndAdd)
{
rerollNode->setAddingMode(true);
@@ -1065,6 +1075,7 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous)//,
previous->setNextNode(rerollNode);
node = rerollNode;
found = true;
+
}
else
{
@@ -1182,6 +1193,24 @@ bool DiceParser::readIfInstruction(QString& str,ExecutionNode*& trueNode,Executi
}
return false;
}
+
+bool DiceParser::readParameterNode(QString& str, ExecutionNode* & node)
+{
+ if(str.startsWith("("))
+ {
+ str=str.remove(0,1);
+ if(readExpression(str,node))
+ {
+ if(str.startsWith(")"))
+ {
+ str=str.remove(0,1);
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
bool DiceParser::readBlocInstruction(QString& str,ExecutionNode*& resultnode)
{
if(str.startsWith('{'))