aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--diceparser.cpp26
-rw-r--r--diceparser.pri2
-rw-r--r--node/stringnode.cpp121
-rw-r--r--node/stringnode.h25
-rw-r--r--parsingtoolbox.cpp52
-rw-r--r--parsingtoolbox.h7
6 files changed, 229 insertions, 4 deletions
diff --git a/diceparser.cpp b/diceparser.cpp
index 39c9b98..5a13fbd 100644
--- a/diceparser.cpp
+++ b/diceparser.cpp
@@ -42,6 +42,8 @@
#include "node/mergenode.h"
#include "node/ifnode.h"
#include "node/paintnode.h"
+#include "node/stringnode.h"
+
#define DEFAULT_FACES_NUMBER 10
@@ -174,9 +176,8 @@ bool DiceParser::parseLine(QString str)
if(keepParsing)
{
// keepParsing =
- readOperator(str,m_current);
-
- m_current = getLatestNode(m_current);
+ readOperator(str,m_current);
+ m_current = getLatestNode(m_current);
}
}
@@ -1005,6 +1006,14 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous)//,
node = nodeif;
found = true;
}
+ else
+ {
+ delete nodeif;
+ }
+ }
+ else
+ {
+ delete nodeif;
}
}
@@ -1088,7 +1097,7 @@ QString DiceParser::humanReadableError()
bool DiceParser::readOperand(QString& str,ExecutionNode* & node)
{
qint64 myNumber=1;
-
+ QString resultStr;
if(m_parsingToolbox->readNumber(str,myNumber))
{
NumberNode* numberNode = new NumberNode();
@@ -1097,6 +1106,15 @@ bool DiceParser::readOperand(QString& str,ExecutionNode* & node)
node = numberNode;
return true;
}
+ else if(m_parsingToolbox->readString(str,resultStr))
+ {
+ StringNode* strNode = new StringNode();
+ strNode->setString(resultStr);
+ node = strNode;
+ return true;
+ }
+ ///! @todo Make this operator working
+
return false;
}
void DiceParser::writeDownDotTree(QString filepath)
diff --git a/diceparser.pri b/diceparser.pri
index 124ac62..4d73be9 100644
--- a/diceparser.pri
+++ b/diceparser.pri
@@ -17,6 +17,7 @@ SOURCES += $$PWD/diceparser.cpp \
$$PWD/compositevalidator.cpp \
$$PWD/dicealias.cpp \
$$PWD/operationcondition.cpp \
+ $$PWD/node/stringnode.cpp \
$$PWD/node/filternode.cpp
@@ -35,6 +36,7 @@ HEADERS += \
$$PWD/compositevalidator.h \
$$PWD/dicealias.h \
$$PWD/operationcondition.h \
+ $$PWD/node/stringnode.h \
$$PWD/node/filternode.h
diff --git a/node/stringnode.cpp b/node/stringnode.cpp
new file mode 100644
index 0000000..157f595
--- /dev/null
+++ b/node/stringnode.cpp
@@ -0,0 +1,121 @@
+#include "stringnode.h"
+
+StringNode::StringNode()
+ : m_stringResult(new StringResult())
+{
+ m_result = m_stringResult;
+}
+
+void StringNode::run(ExecutionNode *previous)
+{
+ m_previousNode = previous;
+ if(NULL!=previous)
+ {
+ m_result->setPrevious(previous->getResult());
+ }
+ if(NULL!=m_nextNode)
+ {
+ m_nextNode->run(this);
+ }
+}
+
+void StringNode::setString(QString str)
+{
+ m_data = str;
+ m_stringResult->setText(m_data);
+}
+QString StringNode::toString(bool withLabel) const
+{
+ if(withLabel)
+ {
+ return QString("%1 [label=\"StringNode %2\"]").arg(m_id).arg(m_data);
+ }
+ else
+ {
+ return m_id;
+ }
+}
+/*void StringNode::getScalarResult()
+{
+ QString scalarText;
+
+ if(m_diceParser->hasIntegerResultNotInFirst())
+ {
+ scalarText = QStringLiteral("%1").arg(m_diceParser->getLastIntegerResult());
+ }
+ else if(hasDiceList)
+ {
+ scalarText = QStringLiteral("%1").arg(m_diceParser->getSumOfDiceResult());
+ }
+}*/
+
+/*bool StringNode::getMessageResult(QString& value, QString& command, QString& list)
+{
+ QString scalarText;
+ QString diceText;
+ //QString pattern("");
+
+
+
+ bool hasDiceList = false;
+ if(m_diceParser->hasDiceResult())
+ {
+ ExportedDiceResult diceList;
+ bool ok;
+ m_diceParser->getLastDiceResult(diceList,ok);//fills the ExportedDiceResult
+ diceText = diceToText(diceList);
+ hasDiceList= true;
+ }
+ if(m_diceParser->hasSeparator())
+ {
+ bool ok;
+ QStringList allStringlist = m_diceParser->getAllDiceResult(ok);
+ if(ok)
+ {
+ QString patternColor("<span class=\"dice\">%1</span>");
+ list = patternColor.arg(allStringlist.join(' '));
+ scalarText = list;
+ }
+ }
+ else if(m_diceParser->hasIntegerResultNotInFirst())
+ {
+ scalarText = QStringLiteral("%1").arg(m_diceParser->getLastIntegerResult());
+ }
+ else if(hasDiceList)
+ {
+ scalarText = QStringLiteral("%1").arg(m_diceParser->getSumOfDiceResult());
+ }
+ value=scalarText;
+ list = diceText.trimmed();
+ command = m_diceParser->getDiceCommand().toHtmlEscaped();
+ if(m_diceParser->hasStringResult())
+ {
+ bool ok;
+ QStringList allStringlist = m_diceParser->getAllStringResult(ok);
+ if(ok)
+ {
+ QString patternColor("<span class=\"dice\">%1</span>");
+ list = patternColor.arg(allStringlist.join(' '));
+ value = list;
+ }
+ else
+ {
+ value = m_diceParser->getStringResult().replace("\n","<br/>");
+ list = allStringlist.join(' ');
+ return true;
+ }
+ }
+
+ return false;
+}*/
+qint64 StringNode::getPriority() const
+{
+ qint64 priority=0;
+ if(NULL!=m_nextNode)
+ {
+ priority = m_nextNode->getPriority();
+ }
+
+
+ return priority;
+}
diff --git a/node/stringnode.h b/node/stringnode.h
new file mode 100644
index 0000000..cf70d02
--- /dev/null
+++ b/node/stringnode.h
@@ -0,0 +1,25 @@
+#ifndef STRINGNODE_H
+#define STRINGNODE_H
+
+#include "node/executionnode.h"
+#include "result/stringresult.h"
+
+/**
+ * @brief The StringNode class is an ExecutionNode. It is dedicated to store string and display result.
+ */
+class StringNode : public ExecutionNode
+{
+public:
+ StringNode();
+ void run(ExecutionNode* previous);
+ void setString(QString str);
+ virtual QString toString(bool withLabel)const;
+ virtual qint64 getPriority() const;
+
+private:
+ QString m_data;
+ StringResult* m_stringResult;
+
+};
+
+#endif // STRINGNODE_H
diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp
index a52743d..f792d7a 100644
--- a/parsingtoolbox.cpp
+++ b/parsingtoolbox.cpp
@@ -283,6 +283,7 @@ bool ParsingToolBox::readNumber(QString& str, qint64& myNumber)
if(str.isEmpty())
return false;
+
QString number;
int i=0;
while(i<str.length() && ((str[i].isNumber()) || ( (i==0) && (str[i]=='-'))))
@@ -307,6 +308,57 @@ bool ParsingToolBox::readNumber(QString& str, qint64& myNumber)
return false;
}
+bool ParsingToolBox::readString(QString &str, QString& strResult)
+{
+ if(str.isEmpty())
+ return false;
+
+
+ if(str.startsWith('"'))
+ {
+ str=str.remove(0,1);
+ }
+
+ int i=0;
+ int j=0;
+ bool previousEscape=false;
+ QString result;
+ /*&&
+ (((!previousEscape) && !(str[i]=='"')) || (previousEscape) && !(str[i]=='"'))
+ || (str[i]=='\\'))*/
+ while(i<str.length() && (!(!previousEscape && (str[i]=='"')) || (previousEscape && str[i]!='"')))
+ {
+ if(str[i]=='\\')
+ {
+ previousEscape = true;
+ }
+ else
+ {
+ if(previousEscape && str[i]!='\"')
+ {
+ result += '\\';
+ ++j;
+ }
+ result+=str[i];
+ previousEscape = false;
+ }
+ ++i;
+ }
+ qDebug() << "previous" << previousEscape << str[i];
+
+ if(!result.isEmpty())
+ {
+ str=str.remove(0,i);
+ strResult = result;
+ if(str.startsWith('"'))
+ {
+ str=str.remove(0,1);
+ return true;
+ }
+ }
+ return false;
+}
+
bool ParsingToolBox::readVariable(QString &str, qint64 &myNumber)
{
if(str.isEmpty())
diff --git a/parsingtoolbox.h b/parsingtoolbox.h
index e5f7fa8..7c5bc53 100644
--- a/parsingtoolbox.h
+++ b/parsingtoolbox.h
@@ -96,6 +96,13 @@ public:
static bool readNumber(QString& str, qint64& myNumber);
/**
+ * @brief readString
+ * @param str
+ * @param strResult
+ * @return
+ */
+ static bool readString(QString& str, QString& strresult);
+ /**
* @brief readVariable
* @param str
* @param myNumber