aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorobiwankennedy <renaud@rolisteam.org>2014-01-15 11:25:21 +0100
committerobiwankennedy <renaud@rolisteam.org>2014-01-15 11:25:21 +0100
commit26e407c1343a01f6a96bd656f25705fba8296bf3 (patch)
tree7ac3d15ef57db24968d641a9e242028d94657d7d
parent7f609ac6c679186e15c6a35c2c99fcb0327a1af7 (diff)
downloadOneRoll-26e407c1343a01f6a96bd656f25705fba8296bf3.tar.gz
OneRoll-26e407c1343a01f6a96bd656f25705fba8296bf3.zip
Update diceparser.cpp
fix >= and <= operator parsing
-rw-r--r--diceparser.cpp36
1 files changed, 26 insertions, 10 deletions
diff --git a/diceparser.cpp b/diceparser.cpp
index b1bd875..2adfd28 100644
--- a/diceparser.cpp
+++ b/diceparser.cpp
@@ -29,11 +29,12 @@ DiceParser::DiceParser()
m_logicOp = new QMap<QString,BooleanCondition::LogicOperator>();
+ m_logicOp->insert(">=",BooleanCondition::GreaterOrEqual);
+ m_logicOp->insert("<=",BooleanCondition::LesserOrEqual);
m_logicOp->insert("<",BooleanCondition::LesserThan);
m_logicOp->insert("=",BooleanCondition::Equal);
- m_logicOp->insert("<=",BooleanCondition::LesserOrEqual);
m_logicOp->insert(">",BooleanCondition::GreaterThan);
- m_logicOp->insert(">=",BooleanCondition::GreaterOrEqual);
+
@@ -104,7 +105,7 @@ void DiceParser::displayResult()
QString dieValue("D%1 : {%2} ");
bool scalarDone=false;
-
+ bool vectorDone=false;
while(NULL!=myResult)
{
@@ -116,7 +117,7 @@ void DiceParser::displayResult()
}
DiceResult* myDiceResult = dynamic_cast<DiceResult*>(myResult);
- if(NULL!=myDiceResult)
+ if((NULL!=myDiceResult)&&(!vectorDone))
{
QString resulStr;
@@ -142,7 +143,7 @@ void DiceParser::displayResult()
}
resulStr.remove(resulStr.size()-2,2);
-
+ vectorDone = true;
stream << dieValue.arg(face).arg(resulStr);
@@ -237,8 +238,14 @@ bool DiceParser::readDiceExpression(QString& str,ExecutionNode* & node)
-
- while(readOption(str,next,next));
+ ExecutionNode* latest = next;
+ while(readOption(str,latest,next))
+ {
+ while(NULL!=latest->getNextNode())
+ {
+ latest = latest->getNextNode();
+ }
+ }
returnVal = true;
@@ -457,15 +464,24 @@ Validator* DiceParser::readValidator(QString& str)
}
bool DiceParser::readLogicOperator(QString& str,BooleanCondition::LogicOperator& op)
{
+ QString longKey;
foreach(QString tmp, m_logicOp->keys())
{
if(str.startsWith(tmp))
{
- str=str.remove(0,tmp.size());
- op = m_logicOp->value(tmp);
- return true;
+ if(longKey.size()<tmp.size())
+ {
+ longKey = tmp;
+ }
}
}
+ if(longKey.size()>0)
+ {
+ str=str.remove(0,longKey.size());
+ op = m_logicOp->value(longKey);
+ return true;
+ }
+
return false;
}