aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--HelpMe.md2
-rw-r--r--booleancondition.cpp1
-rw-r--r--diceparser.cpp91
-rw-r--r--diceparser.h15
-rw-r--r--diceparser.pri2
-rw-r--r--node/helpnode.cpp20
-rw-r--r--node/helpnode.h19
-rw-r--r--node/keepdiceexecnode.cpp4
-rw-r--r--node/listaliasnode.cpp1
-rw-r--r--node/parenthesesnode.cpp1
-rw-r--r--node/scalaroperatornode.cpp2
-rw-r--r--node/sortresult.cpp7
-rw-r--r--node/startingnode.cpp21
-rw-r--r--node/startingnode.h20
-rw-r--r--parsingtoolbox.cpp5
-rw-r--r--result/result.cpp2
-rw-r--r--result/stringresult.cpp10
-rw-r--r--result/stringresult.h4
18 files changed, 191 insertions, 36 deletions
diff --git a/HelpMe.md b/HelpMe.md
index 73265e6..b2a6bd4 100644
--- a/HelpMe.md
+++ b/HelpMe.md
@@ -163,7 +163,7 @@ Substract 4 to 6 and then roll two dice.
Divide by 2 the result of 1 die.
-## Roll two (or more) kind of dice at once.
+## Roll two (or more) kinds of dice at once.
To make it, you have to separate all dice commands by `;`
diff --git a/booleancondition.cpp b/booleancondition.cpp
index 533ec02..c5fd7c7 100644
--- a/booleancondition.cpp
+++ b/booleancondition.cpp
@@ -23,6 +23,7 @@
BooleanCondition::BooleanCondition()
+ : m_operator(Equal)
{
}
qint64 BooleanCondition::hasValid(Die* b,bool recursive,bool unhighlight) const
diff --git a/diceparser.cpp b/diceparser.cpp
index 3831400..802b5f2 100644
--- a/diceparser.cpp
+++ b/diceparser.cpp
@@ -42,8 +42,9 @@
#define DEFAULT_FACES_NUMBER 10
DiceParser::DiceParser()
- : m_start(NULL)
+ : m_start(NULL),m_current(NULL)
{
+ m_currentTreeHasSeparator =false;
m_parsingToolbox = new ParsingToolBox();
m_mapDiceOp = new QMap<QString,DiceOperator>();
@@ -145,6 +146,7 @@ void DiceParser::insertAlias(DiceAlias* dice, int i)
bool DiceParser::parseLine(QString str)
{
+ m_currentTreeHasSeparator = false;
m_errorMap.clear();
if(NULL!=m_start)
{
@@ -166,7 +168,8 @@ bool DiceParser::parseLine(QString str)
keepParsing =!str.isEmpty();
if(keepParsing)
{
- keepParsing = readOperator(str,m_current);
+ // keepParsing =
+ readOperator(str,m_current);
m_current = getLatestNode(m_current);
}
@@ -180,11 +183,7 @@ bool DiceParser::parseLine(QString str)
{
m_errorMap.insert(ExecutionNode::NOTHING_UNDERSTOOD,QObject::tr("Nothing was understood"));
}
- else
- {
- return false;
- }
-
+ return false;
}
bool DiceParser::readExpression(QString& str,ExecutionNode* & node)
@@ -393,6 +392,58 @@ QString DiceParser::getStringResult()
}
return str;
}
+QStringList DiceParser::getAllStringResult(bool& hasAlias)
+{
+ ExecutionNode* next = getLeafNode();
+ Result* result=next->getResult();
+ QStringList stringListResult;
+
+ while(NULL!=result)
+ {
+ if(result->hasResultOfType(Result::STRING))
+ {
+ StringResult* stringResult = dynamic_cast<StringResult*>(result);
+ if(NULL!=stringResult)
+ {
+ stringListResult << stringResult->getText();
+ hasAlias = stringResult->hasHighLight();
+ }
+ }
+ result = result->getPrevious();
+ }
+
+ return stringListResult;
+}
+QStringList DiceParser::getAllDiceResult(bool& hasAlias)
+{
+ ExecutionNode* next = getLeafNode();
+ Result* result=next->getResult();
+ QList<Die*> dieListResult;
+ QStringList stringListResult;
+
+ while(NULL!=result)
+ {
+ if(result->hasResultOfType(Result::DICE_LIST))
+ {
+ DiceResult* stringResult = dynamic_cast<DiceResult*>(result);
+ if(NULL!=stringResult)
+ {
+ dieListResult << stringResult->getResultList();
+ hasAlias = true;
+ }
+ }
+ result = result->getPrevious();
+ }
+ foreach(Die* die, dieListResult)
+ {
+ foreach (qint64 value, die->getListValue())
+ {
+ stringListResult << QString::number(value);
+ }
+ }
+
+ return stringListResult;
+}
void DiceParser::getLastDiceResult(ExportedDiceResult& diceValues)
{
ExecutionNode* next = getLeafNode();
@@ -405,7 +456,6 @@ void DiceParser::getLastDiceResult(ExportedDiceResult& diceValues)
DiceResult* diceResult = dynamic_cast<DiceResult*>(result);
if(NULL!=diceResult)
{
- bool hasResult = false;
quint64 face=0;
ListDiceResult listpair;
foreach(Die* die, diceResult->getResultList())
@@ -413,7 +463,6 @@ void DiceParser::getLastDiceResult(ExportedDiceResult& diceValues)
if(!die->hasBeenDisplayed())
{
QList<quint64> valuesResult;
- hasResult=true;
valuesResult.append(die->getValue());
die->displayed();
face = die->getFaces();
@@ -522,10 +571,10 @@ bool DiceParser::readDice(QString& str,ExecutionNode* & node)
if(readDiceOperator(str,currentOperator))
{
- int num;
- int end;
if(currentOperator==D)
{
+ int num;
+ int end;
if(m_parsingToolbox->readNumber(str,num))
{
if(num<1)
@@ -683,21 +732,19 @@ bool DiceParser::readOperator(QString& str,ExecutionNode* previous)
}
else if(readInstructionOperator(str[0]))
{
- str=str.remove(0,1);
- delete node;
+ str=str.remove(0,1);
+ delete node;
ExecutionNode* nodeExec = NULL;
if(readExpression(str,nodeExec))
{
-
- // nodeExec = getLatestNode(nodeExec);
-
if(NULL==nodeExec)
{
return false;
}
previous->setNextNode(nodeExec);
-
+ m_currentTreeHasSeparator = true;
return true;
+
}
}
else
@@ -710,6 +757,10 @@ bool DiceParser::readOperator(QString& str,ExecutionNode* previous)
}
return false;
}
+bool DiceParser::hasSeparator()const
+{
+ return m_currentTreeHasSeparator;
+}
DiceRollerNode* DiceParser::addRollDiceNode(qint64 faces,ExecutionNode* previous)
{
DiceRollerNode* mydiceRoller= new DiceRollerNode(faces);
@@ -814,7 +865,8 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous, bool hasDice)/
if(NULL!=validator)
{
/// @todo display warning here.
- bool b = m_parsingToolbox->isValidValidator(previous,validator);
+ //bool b =
+ m_parsingToolbox->isValidValidator(previous,validator);
CountExecuteNode* countNode = new CountExecuteNode();
countNode->setValidator(validator);
@@ -836,7 +888,8 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous, bool hasDice)/
if(NULL!=validator)
{
/// @todo display warning here.
- bool b = m_parsingToolbox->isValidValidator(previous,validator);
+ //bool b =
+ m_parsingToolbox->isValidValidator(previous,validator);
RerollDiceNode* rerollNode = new RerollDiceNode();
if(m_OptionOp->value(tmp)==RerollAndAdd)
{
diff --git a/diceparser.h b/diceparser.h
index 3eb55f1..6b9056f 100644
--- a/diceparser.h
+++ b/diceparser.h
@@ -191,6 +191,19 @@ public:
* @param l the path.
*/
void setPathToHelp(QString l);
+ /**
+ * @brief getAllStringResult
+ * @return
+ */
+ QStringList getAllStringResult(bool& hasAlias);
+ /**
+ * @brief getAllDiceResult
+ * @param hasAlias
+ * @return
+ */
+ QStringList getAllDiceResult(bool& hasAlias);
+
+ bool hasSeparator()const;
private:
/**
@@ -289,6 +302,7 @@ private:
QStringList* m_commandList;
QMap<ExecutionNode::ERROR_CODE,QString> m_errorMap;
+ QMap<ExecutionNode::ERROR_CODE,QString> m_warningMap;
ExecutionNode* m_start;
@@ -296,6 +310,7 @@ private:
QString m_command;
ParsingToolBox* m_parsingToolbox;
QString m_helpPath;
+ bool m_currentTreeHasSeparator;
};
#endif // DICEPARSER_H
diff --git a/diceparser.pri b/diceparser.pri
index cacca31..22ef326 100644
--- a/diceparser.pri
+++ b/diceparser.pri
@@ -25,7 +25,7 @@ HEADERS += \
$$PWD/die.h \
$$PWD/result/result.h \
$$PWD/result/scalarresult.h \
- $$PWD/result/parsingtoolbox.h \
+ $$PWD/parsingtoolbox.h \
$$PWD/result/stringresult.h \
$$PWD/dicealias.h
diff --git a/node/helpnode.cpp b/node/helpnode.cpp
index 6108e4d..dd5f087 100644
--- a/node/helpnode.cpp
+++ b/node/helpnode.cpp
@@ -1,3 +1,22 @@
+/***************************************************************************
+ * Copyright (C) 2015 by Renaud Guezennec *
+ * http://renaudguezennec.homelinux.org/accueil,3.html *
+ * *
+ * rolisteam is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
#include "helpnode.h"
HelpNode::HelpNode()
@@ -9,6 +28,7 @@ void HelpNode::run(ExecutionNode* previous)
{
m_previousNode = previous;
StringResult* txtResult = dynamic_cast<StringResult*>(m_result);
+ txtResult->setHighLight(false);
if(NULL != previous)
{
diff --git a/node/helpnode.h b/node/helpnode.h
index 88a0842..be21b67 100644
--- a/node/helpnode.h
+++ b/node/helpnode.h
@@ -1,3 +1,22 @@
+/***************************************************************************
+ * Copyright (C) 2015 by Renaud Guezennec *
+ * http://renaudguezennec.homelinux.org/accueil,3.html *
+ * *
+ * rolisteam is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
#ifndef HELPNODE_H
#define HELPNODE_H
#include "executionnode.h"
diff --git a/node/keepdiceexecnode.cpp b/node/keepdiceexecnode.cpp
index a225ac4..a230107 100644
--- a/node/keepdiceexecnode.cpp
+++ b/node/keepdiceexecnode.cpp
@@ -42,10 +42,8 @@ m_previousNode = previous;
if(NULL!=previousDiceResult)
{
QList<Die*> diceList=previousDiceResult->getResultList();
- QList<Die*> diceList2=m_diceResult->getResultList();
+ QList<Die*> diceList2 = diceList.mid(0,m_numberOfDice);
-
- diceList2 = diceList.mid(0,m_numberOfDice);
foreach(Die* tmp,diceList.mid(m_numberOfDice,-1))
{
tmp->setHighlighted(false);
diff --git a/node/listaliasnode.cpp b/node/listaliasnode.cpp
index ddb8ac9..1809eac 100644
--- a/node/listaliasnode.cpp
+++ b/node/listaliasnode.cpp
@@ -29,6 +29,7 @@ void ListAliasNode::run(ExecutionNode* previous )
{
m_previousNode = previous;
StringResult* txtResult = dynamic_cast<StringResult*>(m_result);
+ txtResult->setHighLight(false);
if(NULL != previous)
{
diff --git a/node/parenthesesnode.cpp b/node/parenthesesnode.cpp
index 2876147..f81fc1c 100644
--- a/node/parenthesesnode.cpp
+++ b/node/parenthesesnode.cpp
@@ -22,6 +22,7 @@
#include "parenthesesnode.h"
ParenthesesNode::ParenthesesNode()
+ : m_internalNode(NULL)
{
}
diff --git a/node/scalaroperatornode.cpp b/node/scalaroperatornode.cpp
index c5f91f9..d532df0 100644
--- a/node/scalaroperatornode.cpp
+++ b/node/scalaroperatornode.cpp
@@ -26,7 +26,7 @@
ScalarOperatorNode::ScalarOperatorNode()
- : m_internalNode(NULL),m_scalarResult(new ScalarResult())
+ : m_internalNode(NULL),m_scalarResult(new ScalarResult()),m_operator(PLUS)
{
m_scalarOperationList.insert('+',PLUS);
m_scalarOperationList.insert('-',MINUS);
diff --git a/node/sortresult.cpp b/node/sortresult.cpp
index 44a25f0..421beb3 100644
--- a/node/sortresult.cpp
+++ b/node/sortresult.cpp
@@ -54,14 +54,11 @@ void SortResultNode::run(ExecutionNode* node)
bool found = false;
int start = 0;
int end = diceList2.size();
- int distance = 0;
Die* tmp2 = NULL;
while(!found)
{
- distance = end-start;
+ int distance = end-start;
j = (start+end)/2;
-
-
if(distance == 0)
{
j=end;
@@ -78,9 +75,7 @@ void SortResultNode::run(ExecutionNode* node)
{
start=j+1;
}
-
}
-
}
diceList2.insert(j,tmp1);
}
diff --git a/node/startingnode.cpp b/node/startingnode.cpp
index b15101b..7e13f5d 100644
--- a/node/startingnode.cpp
+++ b/node/startingnode.cpp
@@ -1,3 +1,22 @@
+/***************************************************************************
+ * Copyright (C) 2015 by Renaud Guezennec *
+ * http://renaudguezennec.homelinux.org/accueil,3.html *
+ * *
+ * rolisteam is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
#include "startingnode.h"
#include <QDebug>
@@ -24,7 +43,5 @@ qint64 StartingNode::getPriority() const
{
priority = m_nextNode->getPriority();
}
-
-
return priority;
}
diff --git a/node/startingnode.h b/node/startingnode.h
index ebe28c0..1edebc9 100644
--- a/node/startingnode.h
+++ b/node/startingnode.h
@@ -1,3 +1,22 @@
+/***************************************************************************
+ * Copyright (C) 2015 by Renaud Guezennec *
+ * http://renaudguezennec.homelinux.org/accueil,3.html *
+ * *
+ * rolisteam is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
#ifndef STARTINGNODE_H
#define STARTINGNODE_H
@@ -31,3 +50,4 @@ public:
};
#endif // STARTINGNODE_H
+
diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp
index f6b1f12..2d26d79 100644
--- a/parsingtoolbox.cpp
+++ b/parsingtoolbox.cpp
@@ -75,7 +75,6 @@ Validator* ParsingToolBox::readValidator(QString& str)
{
Validator* returnVal=NULL;
bool expectSquareBrasket=false;
- bool isOk = true;
if((str.startsWith("[")))
{
str=str.remove(0,1);
@@ -83,11 +82,13 @@ Validator* ParsingToolBox::readValidator(QString& str)
}
BooleanCondition::LogicOperator myLogicOp = BooleanCondition::Equal;
- bool hasReadLogicOperator = readLogicOperator(str,myLogicOp);
+ //bool hasReadLogicOperator =
+ readLogicOperator(str,myLogicOp);
int value=0;
if(readNumber(str,value))
{
+ bool isOk = true;
if(str.startsWith("-"))
{
str=str.remove(0,1);
diff --git a/result/result.cpp b/result/result.cpp
index 257045c..161cfea 100644
--- a/result/result.cpp
+++ b/result/result.cpp
@@ -22,7 +22,7 @@
#include "result.h"
Result::Result()
- : m_previous(NULL)
+ : m_previous(NULL),m_resultTypes(STRING)
{
}
diff --git a/result/stringresult.cpp b/result/stringresult.cpp
index 4dbd577..474ae23 100644
--- a/result/stringresult.cpp
+++ b/result/stringresult.cpp
@@ -2,6 +2,7 @@
StringResult::StringResult()
{
+ m_highlight = true;
m_resultTypes = Result::STRING;
}
void StringResult::setText(QString text)
@@ -35,3 +36,12 @@ QString StringResult::toString()
{
return QString("StringResult_value_%1").arg(getText().replace(" ","_"));
}
+void StringResult::setHighLight(bool b)
+{
+ m_highlight = b;
+}
+
+bool StringResult::hasHighLight() const
+{
+ return m_highlight;
+}
diff --git a/result/stringresult.h b/result/stringresult.h
index 5a6b26c..6819aaa 100644
--- a/result/stringresult.h
+++ b/result/stringresult.h
@@ -37,8 +37,12 @@ public:
* @return
*/
virtual QString toString();
+
+ virtual void setHighLight(bool );
+ virtual bool hasHighLight() const;
private:
QString m_value;
+ bool m_highlight;
};
#endif // STRINGRESULT_H