diff options
| author | 2015-04-01 00:28:17 +0200 | |
|---|---|---|
| committer | 2015-04-01 00:28:17 +0200 | |
| commit | 60a0e524561ae86c9509c61b00a5d8ba40a1d7ee (patch) | |
| tree | cd60b92368403a806ee8e7bcb00b41e5000722f1 | |
| parent | 5bd5a8a07a900c013c120b4e228c766a84a05b09 (diff) | |
| download | OneRoll-60a0e524561ae86c9509c61b00a5d8ba40a1d7ee.tar.gz OneRoll-60a0e524561ae86c9509c61b00a5d8ba40a1d7ee.zip | |
-Better understanding of validators toString method
-return error if error have been detected for endless loop.
-add listaliasnode.h/.cpp to the pri file
-protect the use of pointer
| -rw-r--r-- | booleancondition.cpp | 21 | ||||
| -rw-r--r-- | diceparser.cpp | 18 | ||||
| -rw-r--r-- | diceparser.h | 46 | ||||
| -rw-r--r-- | diceparser.pri | 2 | ||||
| -rw-r--r-- | parsingtoolbox.cpp | 9 | ||||
| -rw-r--r-- | range.cpp | 2 |
6 files changed, 86 insertions, 12 deletions
diff --git a/booleancondition.cpp b/booleancondition.cpp index af4ad10..267d7e9 100644 --- a/booleancondition.cpp +++ b/booleancondition.cpp @@ -77,7 +77,26 @@ void BooleanCondition::setValue(qint64 v) } QString BooleanCondition::toString() { - return QString("BooleanCondition_op_%1_value_%2").arg(m_operator).arg(m_value); + QString str=""; + switch (m_operator) + { + case Equal: + str.append("="); + break; + case GreaterThan: + str.append(">"); + break; + case LesserThan: + str.append("<"); + break; + case GreaterOrEqual: + str.append(">="); + break; + case LesserOrEqual: + str.append("<="); + break; + } + return QString("[%1%2]").arg(str).arg(m_value); } quint8 BooleanCondition::getValidRangeSize(quint64 faces) const { diff --git a/diceparser.cpp b/diceparser.cpp index 9404f08..91e4af0 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -100,6 +100,7 @@ QString DiceParser::convertAlias(QString str) bool DiceParser::parseLine(QString str) { + m_errorMap.clear(); m_command = str; m_start = new StartingNode(); ExecutionNode* newNode = NULL; @@ -108,7 +109,7 @@ bool DiceParser::parseLine(QString str) str = convertAlias(str); bool keepParsing = readExpression(str,newNode); - while(keepParsing) + if(keepParsing) { m_current->setNextNode(newNode); m_current = getLatestNode(m_current); @@ -119,10 +120,16 @@ bool DiceParser::parseLine(QString str) m_current = getLatestNode(m_current); } - return true; + } + if(m_errorMap.isEmpty()) + { + return true; + } + else + { + return false; } - return false; } @@ -785,9 +792,9 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous, bool hasDice) Validator* validator = m_parsingToolbox->readValidator(str); if(NULL!=validator) { - if(m_parsingToolbox->isValidValidator(previous,validator)) + if(!m_parsingToolbox->isValidValidator(previous,validator)) { - m_errorMap.insert(ExecutionNode::ENDLESS_LOOP_ERROR,tr("this condition introduce an endless loop: %1. 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())); } ExploseDiceNode* explosedNode = new ExploseDiceNode(); explosedNode->setValidator(validator); @@ -819,6 +826,7 @@ QString DiceParser::humanReadableError() str.append(i.value()); str.append("\n"); } + return str; } bool DiceParser::readOperand(QString& str,ExecutionNode* & node) diff --git a/diceparser.h b/diceparser.h index 6dd2a10..e4ea0e3 100644 --- a/diceparser.h +++ b/diceparser.h @@ -110,18 +110,50 @@ public: * @brief displayDotTree */ void displayDotTree(); - + /** + * @brief getLastIntegerResult + * @return + */ qreal getLastIntegerResult(); + /** + * @brief getSumOfDiceResult + * @return + */ qreal getSumOfDiceResult(); - + /** + * @brief getLastDiceResult + * @return + */ QString getLastDiceResult(); - + /** + * @brief hasIntegerResultNotInFirst + * @return + */ bool hasIntegerResultNotInFirst(); + /** + * @brief hasDiceResult + * @return + */ bool hasDiceResult(); + /** + * @brief getDiceCommand + * @return + */ QString getDiceCommand(); + /** + * @brief hasStringResult + * @return + */ bool hasStringResult(); + /** + * @brief getStringResult + * @return + */ QString getStringResult(); - + /** + * @brief humanReadableError + * @return + */ QString humanReadableError(); private: @@ -171,6 +203,12 @@ private: * @return */ DiceRollerNode* addRollDiceNode(qint64 faces,ExecutionNode*); + /** + * @brief addExploseDiceNode + * @param faces + * @param previous + * @return + */ ExploseDiceNode* addExploseDiceNode(qint64 faces,ExecutionNode* previous); /** * @brief readOperand diff --git a/diceparser.pri b/diceparser.pri index bf9847e..b9af1d7 100644 --- a/diceparser.pri +++ b/diceparser.pri @@ -42,6 +42,7 @@ HEADERS += \ $$PWD/node/parenthesesnode.h \ $$PWD/node/helpnode.h \ $$PWD/node/jumpbackwardnode.h \ + $$PWD/node/listaliasnode.h \ $$PWD/node/listsetrollnode.h SOURCES += \ @@ -58,6 +59,7 @@ SOURCES += \ $$PWD/node/parenthesesnode.cpp \ $$PWD/node/helpnode.cpp \ $$PWD/node/jumpbackwardnode.cpp \ + $$PWD/node/listaliasnode.cpp \ $$PWD/node/listsetrollnode.cpp diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp index f276abf..e03690e 100644 --- a/parsingtoolbox.cpp +++ b/parsingtoolbox.cpp @@ -204,7 +204,14 @@ bool ParsingToolBox::readAscending(QString& str) bool ParsingToolBox::isValidValidator(ExecutionNode* previous, Validator* val) { DiceRollerNode* node = getDiceRollerNode(previous); - return (val->getValidRangeSize(node->getFaces())<node->getFaces()); + if(NULL!=node) + { + return (val->getValidRangeSize(node->getFaces())<node->getFaces()); + } + else + { + return true; + } } DiceRollerNode* ParsingToolBox::getDiceRollerNode(ExecutionNode* previous) { @@ -54,7 +54,7 @@ qint64 Range::hasValid(Die* m,bool recursive) const } QString Range::toString() { - return QString("Range_%1_%2").arg(m_start).arg(m_end); + return QString("[%1-%2]").arg(m_start).arg(m_end); } quint8 Range::getValidRangeSize(quint64 faces) const { |