aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorRenaud G <renaud@rolisteam.org>2017-02-12 11:05:09 +0100
committerRenaud G <renaud@rolisteam.org>2017-02-12 11:05:09 +0100
commit32f164c6e807c4f3d6fab3b147d1cf98e7a949c0 (patch)
tree93b0e528a61e238049568f8095fb57f41f2bceab
parent7184bf82c420f79ff794e2c6c405d447176482cc (diff)
downloadOneRoll-32f164c6e807c4f3d6fab3b147d1cf98e7a949c0.tar.gz
OneRoll-32f164c6e807c4f3d6fab3b147d1cf98e7a949c0.zip
-add comment support
-fix error on range.
-rw-r--r--diceparser.cpp36
-rw-r--r--diceparser.h4
2 files changed, 31 insertions, 9 deletions
diff --git a/diceparser.cpp b/diceparser.cpp
index 4ccc247..29bd8e7 100644
--- a/diceparser.cpp
+++ b/diceparser.cpp
@@ -195,6 +195,8 @@ bool DiceParser::parseLine(QString str)
bool DiceParser::readExpression(QString& str,ExecutionNode* & node)
{
ExecutionNode* operandNode=NULL;
+ QString result;
+ QString comment;
if(m_parsingToolbox->readOpenParentheses(str))
{
ExecutionNode* internalNode=NULL;
@@ -255,6 +257,11 @@ bool DiceParser::readExpression(QString& str,ExecutionNode* & node)
return false;
}
}
+ if(m_parsingToolbox->readComment(str,result,comment))
+ {
+ m_command.remove(comment);
+ m_comment = result;
+ }
return true;
}
bool DiceParser::readNode(QString& str,ExecutionNode* & node)
@@ -601,16 +608,16 @@ bool DiceParser::readDice(QString& str,ExecutionNode* & node)
{
if(currentOperator==D)
{
- qint64 num;
- qint64 end;
- if(m_parsingToolbox->readNumber(str,num))
+ qint64 max;
+ qint64 min;
+ if(m_parsingToolbox->readNumber(str,max))
{
- if(num<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(num));
+ 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(num);
+ DiceRollerNode* drNode = new DiceRollerNode(max);
node = drNode;
ExecutionNode* current = drNode;
while(readOption(str,current))
@@ -619,11 +626,12 @@ bool DiceParser::readDice(QString& str,ExecutionNode* & node)
}
return true;
}
- else if(m_parsingToolbox->readDiceRange(str,num,end))
+ else if(m_parsingToolbox->readDiceRange(str,min,max))
{
- qint64 face = abs(num - end)+1;
- DiceRollerNode* drNode = new DiceRollerNode(face,num);
+ // qint64 face = abs(num - end);
+ //qDebug() << face << end;
+ DiceRollerNode* drNode = new DiceRollerNode(max,min);
node = drNode;
ExecutionNode* current = drNode;
while(readOption(str,current))
@@ -1083,6 +1091,16 @@ bool DiceParser::readBlocInstruction(QString& str,ExecutionNode*& resultnode)
return false;
}
+QString DiceParser::getComment() const
+{
+ return m_comment;
+}
+
+void DiceParser::setComment(const QString &comment)
+{
+ m_comment = comment;
+}
+
QMap<ExecutionNode::DICE_ERROR_CODE,QString> DiceParser::getErrorMap()
{
return m_start->getExecutionErrorMap();
diff --git a/diceparser.h b/diceparser.h
index 0bc32e8..a1e58e1 100644
--- a/diceparser.h
+++ b/diceparser.h
@@ -225,6 +225,9 @@ public:
* @param variables
*/
void setVariableDictionary(QHash<QString,QString>* variables);
+ QString getComment() const;
+ void setComment(const QString &comment);
+
private:
/**
@@ -333,6 +336,7 @@ private:
QString m_helpPath;
bool m_currentTreeHasSeparator;
bool readBlocInstruction(QString &str, ExecutionNode *&resultnode);
+ QString m_comment;
};
#endif // DICEPARSER_H