From a6a22731a76eb52ab4ccd65364db8b91eb2420e9 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Sun, 17 Jun 2018 15:58:07 +0200 Subject: add file for compiling --- diceparser.pri | 2 ++ 1 file changed, 2 insertions(+) diff --git a/diceparser.pri b/diceparser.pri index 22bcb30..b554d8c 100644 --- a/diceparser.pri +++ b/diceparser.pri @@ -40,6 +40,7 @@ SOURCES += $$PWD/diceparser.cpp \ $$PWD/node/splitnode.cpp \ $$PWD/node/listsetrollnode.cpp\ $$PWD/node/variablenode.cpp\ + $$PWD/node/bind.cpp\ $$PWD/diceroller.cpp\ $$PWD/qmltypesregister.cpp @@ -79,6 +80,7 @@ HEADERS += \ $$PWD/node/mergenode.h \ $$PWD/node/listaliasnode.h \ $$PWD/node/ifnode.h \ + $$PWD/node/bind.h\ $$PWD/node/splitnode.h \ $$PWD/node/paintnode.h \ $$PWD/node/listsetrollnode.h \ -- cgit v1.2.3-70-g09d2 From a5c353199945213eed65565d2de78f339a35a78e Mon Sep 17 00:00:00 2001 From: Renaud G Date: Sun, 15 Jul 2018 13:05:01 +0200 Subject: Fix mispelled word Fix mispelled word --- HelpMe.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/HelpMe.md b/HelpMe.md index 4e59a78..f9b4239 100644 --- a/HelpMe.md +++ b/HelpMe.md @@ -75,7 +75,7 @@ Rolling 3 dice with 10 faces starting at 0. > 3d[-20--9] -Rolling 3 dice, values ars between -20 and -9. +Rolling 3 dice, values are between -20 and -9. ### Instruction: Roll two (or more) kinds of dice at once @@ -96,7 +96,7 @@ It is possible to merge every instruction inside a huge one. The operator merge is dedicated to that. It is useful when you need to manage all diceresult as the same result. -For example, if you need to keep the high dice between a d6 and d8. +For example, if you need to keep the higher dice between a d6 and d8. > d6;d8mk1 -- cgit v1.2.3-70-g09d2 From b3357e42347d8f05099be7c4688b17ef3661162a Mon Sep 17 00:00:00 2001 From: Renaud G Date: Mon, 30 Jul 2018 02:37:46 +0200 Subject: add unique operator add unique operator --- HelpMe.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/HelpMe.md b/HelpMe.md index f9b4239..8dbd121 100644 --- a/HelpMe.md +++ b/HelpMe.md @@ -19,6 +19,7 @@ * [Merge](#merge) * [if](#if) * [Group](#group) + * [Unique](#Unique) * [Comment (\#)](#comment-) * [Arithmetic](#arithmetic) * [Arithmetic and Dice](#arithmetic-and-dice) @@ -252,6 +253,16 @@ Merge operator is used for gathering several dice rolls from different die type This command merges together the result from the d6 and the d8. Then, it applied the k operator on both result to keep the best. Be careful, this operator merges the instruction list. Instruction reference (such as $1 etc..) won't work after merge operator. +### Unique + +It makes exploded dice as new dice. + +> 4d6e6u6k3 + +Result: 6 4 3 3 2 +Final result: 6+4+3 = 13 + + ### Bind Bind works exactly as merge but one thing. -- cgit v1.2.3-70-g09d2 From 0490332a1e85458059aa761c7a0769fe2fe985c7 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Thu, 2 Aug 2018 15:56:53 +0200 Subject: Clean up Comment line Clean up Comment line --- diceparser.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/diceparser.cpp b/diceparser.cpp index 22ff52f..1a065b7 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -155,6 +155,7 @@ void DiceParser::insertAlias(DiceAlias* dice, int i) bool DiceParser::parseLine(QString str, bool allowAlias) { m_errorMap.clear(); + m_comment = QStringLiteral(""); if(!m_startNodes.empty()) { qDeleteAll(m_startNodes); -- cgit v1.2.3-70-g09d2 From acb001bc1909d873a37fbe1c8cbabade76a8015e Mon Sep 17 00:00:00 2001 From: Renaud G Date: Sun, 12 Aug 2018 23:54:31 +0200 Subject: Change management of variable (ref instead of pointer) using static is a bad idea as more and more diceparser are now use in rolisteam. --- diceparser.cpp | 2 +- diceparser.h | 2 +- parsingtoolbox.cpp | 12 ++++++------ parsingtoolbox.h | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/diceparser.cpp b/diceparser.cpp index 1a065b7..41a91e5 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -1330,7 +1330,7 @@ void DiceParser::setPathToHelp(QString l) { m_helpPath = l; } -void DiceParser::setVariableDictionary(QHash* variables) +void DiceParser::setVariableDictionary(const QHash& variables) { ParsingToolBox::setVariableHash(variables); } diff --git a/diceparser.h b/diceparser.h index ad831cf..2ede553 100644 --- a/diceparser.h +++ b/diceparser.h @@ -213,7 +213,7 @@ public: * @brief setVariableDictionary * @param variables */ - void setVariableDictionary(QHash* variables); + void setVariableDictionary(const QHash &variables); QString getComment() const; void setComment(const QString &comment); diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp index bd326e2..eec190e 100644 --- a/parsingtoolbox.cpp +++ b/parsingtoolbox.cpp @@ -28,7 +28,7 @@ #include "node/stringnode.h" -QHash* ParsingToolBox::m_variableHash = nullptr; +QHash ParsingToolBox::m_variableHash; std::vector* ParsingToolBox::m_startNodes = nullptr; ParsingToolBox::ParsingToolBox() @@ -491,11 +491,11 @@ bool ParsingToolBox::readVariable(QString &str, qint64 &myNumber, QString& reaso int post = str.indexOf('}'); key = str.left(post); - if(nullptr!=m_variableHash) + if(!m_variableHash.isEmpty()) { - if(m_variableHash->contains(key)) + if(m_variableHash.contains(key)) { - QString value = m_variableHash->value(key); + QString value = m_variableHash.value(key); bool ok; int valueInt = value.toInt(&ok); if(ok) @@ -662,12 +662,12 @@ void ParsingToolBox::readPainterParameter(PainterNode* painter,QString& str) } } -QHash *ParsingToolBox::getVariableHash() +QHash ParsingToolBox::getVariableHash() { return m_variableHash; } -void ParsingToolBox::setVariableHash(QHash *variableHash) +void ParsingToolBox::setVariableHash(const QHash& variableHash) { m_variableHash = variableHash; } diff --git a/parsingtoolbox.h b/parsingtoolbox.h index 4a88732..be0b0eb 100644 --- a/parsingtoolbox.h +++ b/parsingtoolbox.h @@ -178,8 +178,8 @@ public: static void readPainterParameter(PainterNode *painter, QString &str); - static QHash *getVariableHash(); - static void setVariableHash(QHash *variableHash); + static QHash getVariableHash(); + static void setVariableHash(const QHash &variableHash); /** * @brief readConditionType * @param str @@ -202,7 +202,7 @@ private: QHash* m_arithmeticOperation; - static QHash* m_variableHash; + static QHash m_variableHash; static std::vector* m_startNodes; }; -- cgit v1.2.3-70-g09d2 From 16fbd4299406d069a142871a444c462f9a7fd57e Mon Sep 17 00:00:00 2001 From: Renaud G Date: Sun, 19 Aug 2018 17:26:12 +0200 Subject: make sure aliases don't affect variable names or string --- dicealias.cpp | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/dicealias.cpp b/dicealias.cpp index a2683e3..a27919d 100644 --- a/dicealias.cpp +++ b/dicealias.cpp @@ -24,6 +24,83 @@ #include +QString makeReplament(const QString& pattern, const QString& replacement, QString cmd) +{ + + // FIXME try to do the same with RegularExpression + auto hasPattern = cmd.contains(pattern); + if(hasPattern) + { + auto hasVariable = cmd.contains("${"); + auto hasQuote = cmd.contains("\""); + + if(!hasQuote && !hasVariable) + { + cmd.replace(pattern, replacement); + } + else + { + std::vector patternPosList; + std::vector> variablePos; + + int pos= 0; + QRegularExpressionMatch match; + while(pos!=-1) + { + auto start = cmd.indexOf(QRegularExpression("\\${\\N+}"),pos,&match); + if(start >=0) + { + auto end = start+match.captured().length(); + variablePos.push_back(std::make_pair(start,end)); + pos = end+1; + } + else + { + pos = start; + } + } + + pos = 0; + while(pos!=-1) + { + auto start = cmd.indexOf("\"",pos); + if(start >= 0) + { + auto end = cmd.indexOf("\"",start+1); + variablePos.push_back(std::make_pair(start,end)); + pos = end+1; + } + else + { + pos = start; + } + } + + pos= 0; + while((pos = cmd.indexOf(pattern,pos)) && pos!=-1) + { + bool isInsidePair = false; + for(auto pair : variablePos) + { + if(!isInsidePair) + isInsidePair = (pos > pair.first && pos < pair.second); + } + if(!isInsidePair) + patternPosList.push_back(pos); + pos+=1; + } + for(auto pos : patternPosList) + { + cmd.replace(pos,1,replacement); + } + } + } + return cmd; +} + + + + DiceAlias::DiceAlias(QString cmd, QString key, bool isReplace,bool isEnable) : m_command(cmd),m_value(key),m_isEnable(isEnable) { @@ -49,7 +126,8 @@ bool DiceAlias::resolved(QString & str) if((m_type == REPLACE)&&(str.contains(m_command))) { - str.replace(m_command,m_value); + str = makeReplament(m_command,m_value,str); + //str.replace(m_command,m_value); return true; } else if(m_type == REGEXP) -- cgit v1.2.3-70-g09d2 From 52343ff414f7b41e8f38e28bec3de39500b5fed2 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Wed, 22 Aug 2018 02:07:30 +0200 Subject: Fix bug on dicealias replacement (when several replacement must be done on the same command). --- dicealias.cpp | 6 ++++-- dicealias.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/dicealias.cpp b/dicealias.cpp index a27919d..f514e9e 100644 --- a/dicealias.cpp +++ b/dicealias.cpp @@ -89,9 +89,11 @@ QString makeReplament(const QString& pattern, const QString& replacement, QStrin patternPosList.push_back(pos); pos+=1; } - for(auto pos : patternPosList) + + // TODO to be replace by C++14 when it is ready + for (auto i = patternPosList.rbegin(); i != patternPosList.rend(); ++i) { - cmd.replace(pos,1,replacement); + cmd.replace(*i,1,replacement); } } } diff --git a/dicealias.h b/dicealias.h index a85c9a0..8320445 100644 --- a/dicealias.h +++ b/dicealias.h @@ -37,7 +37,7 @@ public: * @param key * @param isReplace */ - DiceAlias(QString cmd, QString key, bool isReplace = true, bool isEnable = true); + DiceAlias(QString pattern, QString remplacement, bool isReplace = true, bool isEnable = true); /** * @brief ~DiceAlias */ -- cgit v1.2.3-70-g09d2