From bb6b87a2685c0d71b5c38be33c100f85ac0b9cee Mon Sep 17 00:00:00 2001 From: Renaud G Date: Thu, 25 Jul 2019 09:59:29 +0200 Subject: Rework of the component to be a proper lib --- cli/CMakeLists.txt | 2 ++ cli/main.cpp | 48 +++++++++++++++++++++++++----------------------- 2 files changed, 27 insertions(+), 23 deletions(-) (limited to 'cli') diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt index 215287d..5d79b3c 100644 --- a/cli/CMakeLists.txt +++ b/cli/CMakeLists.txt @@ -74,6 +74,8 @@ SET( cli_sources set(documentation_files ../HelpMe.md ../README.md) add_executable( dice ${cli_sources} ${dice_QM} ${documentation_files}) +target_include_directories(dice PRIVATE ../include) + target_link_libraries(dice diceparser ${Qt5Core_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Qt5Svg_LIBRARIES}) INSTALL_TARGETS(/bin dice) diff --git a/cli/main.cpp b/cli/main.cpp index d6f6398..958d96f 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -35,6 +35,7 @@ #include #endif +#include "dicealias.h" #include "diceparser.h" #include "displaytoolbox.h" #include "highlightdice.h" @@ -115,7 +116,7 @@ QString diceToMarkdown(QJsonArray array, bool withColor, bool allSameColor, bool } void displayJSon(QString scalarText, QString resultStr, QJsonArray array, bool withColor, QString cmd, QString error, - QString warning, QString comment, bool allSameFaceCount, bool allSameColor) + QString warning, QString comment, bool allSameFaceCount, bool allSameColor) { Q_UNUSED(withColor); QJsonDocument doc; @@ -133,7 +134,7 @@ void displayJSon(QString scalarText, QString resultStr, QJsonArray array, bool w out << doc.toJson() << "\n"; } void displayMarkdown(QString scalarText, QString resultStr, QJsonArray array, bool withColor, QString cmd, - QString error, QString warning, QString comment, bool allSameFaceCount, bool allSameColor) + QString error, QString warning, QString comment, bool allSameFaceCount, bool allSameColor) { Q_UNUSED(withColor); QString str("```Markdown\n"); @@ -165,7 +166,7 @@ void displayMarkdown(QString scalarText, QString resultStr, QJsonArray array, bo out << str; } QString displaySVG(QString scalarText, QString resultStr, QJsonArray array, bool withColor, QString cmd, QString error, - QString warning, QString comment, bool allSameFaceCount, bool allSameColor) + QString warning, QString comment, bool allSameFaceCount, bool allSameColor) { QString str( "\n", "aliasfile"); + "path to alias json files: ", "aliasfile"); QCommandLineOption character(QStringList() << "s" << "charactersheet", - "set Parameters to simulate character sheet: ", "sheetfile"); + "set Parameters to simulate character sheet: ", "sheetfile"); QCommandLineOption markdown(QStringList() << "m" << "markdown", - "The output is formatted in markdown."); + "The output is formatted in markdown."); QCommandLineOption bot(QStringList() << "b" << "bot", - "Discord bot."); + "Discord bot."); QCommandLineOption svg(QStringList() << "g" << "svg", - "The output is formatted in svg."); + "The output is formatted in svg."); QCommandLineOption json(QStringList() << "j" << "json", - "The output is formatted in json."); + "The output is formatted in json."); QCommandLineOption dotFile(QStringList() << "d" << "dot-file", - "Instead of rolling dice, generate the execution tree and write it in ", "dotfile"); + "Instead of rolling dice, generate the execution tree and write it in ", + "dotfile"); QCommandLineOption translation(QStringList() << "t" << "translation", - "path to the translation file: ", "translationfile"); + "path to the translation file: ", "translationfile"); QCommandLineOption help(QStringList() << "h" << "help", - "Display this help"); + "Display this help"); optionParser.addOption(color); optionParser.addOption(version); -- cgit v1.2.3-70-g09d2 From 3fd2bd47e6581760c2129bcd2fccf532a32ef7ba Mon Sep 17 00:00:00 2001 From: Renaud G Date: Thu, 25 Jul 2019 22:34:20 +0200 Subject: Put together all important enums inside diceparserhelper.h --- cli/CMakeLists.txt | 60 +++++++++++++++++++++++++++++++++++----------- include/diceparserhelper.h | 3 ++- 2 files changed, 48 insertions(+), 15 deletions(-) (limited to 'cli') diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt index 5d79b3c..c697899 100644 --- a/cli/CMakeLists.txt +++ b/cli/CMakeLists.txt @@ -3,15 +3,57 @@ cmake_minimum_required(VERSION 3.5) option(UPDATE_TRANSLATIONS "update Translation" OFF) MESSAGE(STATUS "UPDATE TRANSLATIONS: ${UPDATE_TRANSLATIONS}") - project(dice) +SET( dice_sources + ../diceparser.cpp + ../range.cpp + ../booleancondition.cpp + ../validator.cpp + ../compositevalidator.cpp + ../operationcondition.cpp + ../die.cpp + ../parsingtoolbox.cpp + ../dicealias.cpp + ../result/result.cpp + ../result/scalarresult.cpp + ../result/stringresult.cpp + ../result/diceresult.cpp + ../node/countexecutenode.cpp + ../node/dicerollernode.cpp + ../node/executionnode.cpp + ../node/explodedicenode.cpp + ../node/helpnode.cpp + ../node/mergenode.cpp + ../node/jumpbackwardnode.cpp + ../node/keepdiceexecnode.cpp + ../node/listaliasnode.cpp + ../node/listsetrollnode.cpp + ../node/numbernode.cpp + ../node/parenthesesnode.cpp + # ../ node/forloopnode.cpp + ../node/paintnode.cpp + ../node/rerolldicenode.cpp + ../node/scalaroperatornode.cpp + ../node/sortresult.cpp + ../node/startingnode.cpp + ../node/filternode.cpp + ../node/stringnode.cpp + ../node/ifnode.cpp + ../node/splitnode.cpp + ../node/groupnode.cpp + ../node/bind.cpp + ../node/occurencecountnode.cpp + ../node/uniquenode.cpp + ../highlightdice.cpp + ../node/variablenode.cpp + ../node/valueslistnode.cpp +) # Find includes in corresponding build directories set(CMAKE_INCLUDE_CURRENT_DIR ON) # Instruct CMake to run moc automatically when needed. set(CMAKE_AUTOMOC ON) - set(EXECUTABLE_OUTPUT_PATH bin/) # Find the QtWidgets library @@ -38,7 +80,6 @@ set(dice_RESOURCES diceparser.qrc) find_package(Qt5LinguistTools) find_package(Qt5Svg) - IF(UPDATE_TRANSLATIONS) MESSAGE( update Translation ) FILE(GLOB_RECURSE translate_dice_SRCS ../*.cpp ../*.h) @@ -50,17 +91,8 @@ ELSE() ENDIF(UPDATE_TRANSLATIONS) if(Qt5Core_FOUND) - - #IF(UPDATE_TRANSLATIONS) - MESSAGE(status "find" ${dice_TS} ${translate_SRCS} ) - #QT5_CREATE_TRANSLATION(dice_QM ${translate_SRCS} ${dice_TS}) - #ELSE() - #QT5_ADD_TRANSLATION(dice_QM ${dice_TS}) - #ENDIF() - + MESSAGE(status "find" ${dice_TS} ${translate_SRCS} ) QT5_ADD_RESOURCES(dice_RESOURCES_RCC ${dice_RESOURCES}) - - # guess plugins and libraries directory set(QT_PLUGINS_DIR "${Qt5Core_DIR}/../../../plugins") get_target_property(QT_LIBRARY_DIR Qt5::Core LOCATION) get_filename_component(QT_LIBRARY_DIR ${QT_LIBRARY_DIR} PATH) @@ -73,7 +105,7 @@ SET( cli_sources set(documentation_files ../HelpMe.md ../README.md) -add_executable( dice ${cli_sources} ${dice_QM} ${documentation_files}) +add_executable( dice ${cli_sources} ${dice_QM} ${dice_sources} ${documentation_files}) target_include_directories(dice PRIVATE ../include) diff --git a/include/diceparserhelper.h b/include/diceparserhelper.h index 3ca4f15..5013ebe 100644 --- a/include/diceparserhelper.h +++ b/include/diceparserhelper.h @@ -17,7 +17,8 @@ enum class ERROR_CODE : int NO_VARIBALE, INVALID_INDEX, UNEXPECTED_CHARACTER, - NO_PREVIOUS_ERROR + NO_PREVIOUS_ERROR, + NO_VALID_RESULT }; /** -- cgit v1.2.3-70-g09d2 From dee4f259c8372dea752ccd222800dfba82372246 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Sun, 28 Jul 2019 01:01:48 +0200 Subject: Clean the memory after execution. --- cli/main.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'cli') diff --git a/cli/main.cpp b/cli/main.cpp index 958d96f..c597dea 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -367,11 +367,6 @@ int startDiceParsing(QStringList& cmds, QString& treeFile, bool withColor, EXPOR stringResult.replace("\\n", "\n"); stringResult= ParsingToolBox::replaceVariableToValue(stringResult, strLst); - /*for(auto it= strLst.rbegin(); it != strLst.rend(); ++it) - { - stringResult.replace(QStringLiteral("$%1").arg(i), (*it)); - --i; - }*/ int i= strLst.size(); for(auto it= strLst.rbegin(); it != strLst.rend(); ++it) @@ -441,10 +436,12 @@ int startDiceParsing(QStringList& cmds, QString& treeFile, bool withColor, EXPOR } else { + QString error= parser.humanReadableError(); + err << "Error: " << error << "\n"; rt= 1; } } - + parser.cleanAll(); return rt; } #include -- cgit v1.2.3-70-g09d2