From 06aac01fdcdb0b320b5c931b6b28f8a3cb2e74ed Mon Sep 17 00:00:00 2001 From: Renaud G Date: Sun, 9 Dec 2018 22:51:15 +0100 Subject: Display warning message and fix error. --- diceparser.cpp | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) (limited to 'diceparser.cpp') diff --git a/diceparser.cpp b/diceparser.cpp index 2508f41..337efd0 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -169,16 +169,19 @@ bool DiceParser::parseLine(QString str, bool allowAlias) m_command = str; bool hasInstruction = readInstructionList(str); - if((m_errorMap.isEmpty())&&(hasInstruction)) + bool value = hasInstruction; + if(!hasInstruction) { - return true; + m_errorMap.insert(ExecutionNode::NOTHING_UNDERSTOOD,QObject::tr("Nothing was understood. To roll dice: !1d6 - full documation: " + "https://github.com/Rolisteam/DiceParser/blob/master/HelpMe.md")); } - else + else if(hasInstruction && !str.isEmpty()) { - m_errorMap.insert(ExecutionNode::NOTHING_UNDERSTOOD,QObject::tr("Nothing was understood. To roll dice: !1d6 - full documation: " - "https://github.com/Rolisteam/DiceParser/blob/master/HelpMe.md")); + auto i = m_command.size()-str.size(); + m_warningMap.insert(ExecutionNode::UNEXPECTED_CHARACTER,QObject::tr("Unexpected character at %1 - end of command was ignored \"%2\"").arg(i).arg(str)); } - return false; + + return value; } bool DiceParser::readExpression(QString& str,ExecutionNode* & node) @@ -253,8 +256,6 @@ bool DiceParser::readExpression(QString& str,ExecutionNode* & node) { NumberNode* numberNode=new NumberNode(); numberNode->setNumber(1); - ExecutionNode* previous = diceNode->getPreviousNode(); - numberNode->setPreviousNode(previous); numberNode->setNextNode(diceNode); node = numberNode; return true; @@ -860,12 +861,16 @@ bool DiceParser::readInstructionList(QString& str) { latest = ParsingToolBox::getLatestNode(latest); keepParsing =!str.isEmpty(); - if(keepParsing) + while(keepParsing) { + auto before = str; ExecutionNode* operatorNode = nullptr; if(readOperator(str,operatorNode)) + { latest->setNextNode(operatorNode); - latest = ParsingToolBox::getLatestNode(latest); + latest = ParsingToolBox::getLatestNode(latest); + } + keepParsing = (!str.isEmpty() & (before!=str)); } } if( !str.isEmpty() && readInstructionOperator(str[0])) @@ -1348,6 +1353,18 @@ QString DiceParser::humanReadableError() return str; } +QString DiceParser::humanReadableWarning() +{ + QMapIterator i(m_warningMap); + QString str(""); + while (i.hasNext()) + { + i.next(); + str.append(i.value()); + str.append(QStringLiteral("\n")); + } + return str; +} void DiceParser::writeDownDotTree(QString filepath) { -- cgit v1.2.3-70-g09d2