From 27c6b698741cfb19f6dfd888332f45c91c0d242c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Tue, 9 May 2017 15:05:59 +0200 Subject: [PATCH] Moved basic parsing to a separate module. --- .travis.yml | 4 +- CMakeLists.txt | 1 + app/CMakeLists.txt | 1 + app/main.cpp | 4 +- include/plasp/LanguageDetection.h | 5 +- include/plasp/output/Logger.h | 7 +- include/plasp/pddl/Action.h | 3 +- include/plasp/pddl/Description.h | 7 +- include/plasp/pddl/Domain.h | 10 +-- include/plasp/pddl/Expression.h | 2 +- include/plasp/pddl/Parser.h | 4 +- include/plasp/pddl/Problem.h | 10 +-- include/plasp/sas/AssignedVariable.h | 7 +- include/plasp/sas/AxiomRule.h | 5 +- include/plasp/sas/Description.h | 27 ++++---- include/plasp/sas/Effect.h | 5 +- include/plasp/sas/Goal.h | 5 +- include/plasp/sas/InitialState.h | 5 +- include/plasp/sas/MutexGroup.h | 5 +- include/plasp/sas/Operator.h | 5 +- include/plasp/sas/Predicate.h | 5 +- include/plasp/sas/TranslatorASP.h | 4 +- include/plasp/sas/Value.h | 7 +- include/plasp/sas/Variable.h | 7 +- include/plasp/sas/VariableTransition.h | 5 +- lib/parsebase/CMakeLists.txt | 28 ++++++++ .../parsebase/include/parsebase}/Location.h | 9 +-- .../parsebase/include/parsebase}/Parser.h | 21 +++--- .../include/parsebase}/ParserException.h | 21 +++--- .../include/parsebase}/ParserPolicy.h | 9 +-- .../parsebase/include/parsebase}/Stream.h | 16 ++--- lib/parsebase/src/CMakeLists.txt | 21 ++++++ .../parsebase/src/parsebase}/Stream.cpp | 14 ++-- lib/parsebase/tests/CMakeLists.txt | 22 ++++++ .../parsebase/tests/TestParser.cpp | 68 +++++++++---------- lib/parsebase/tests/main.cpp | 2 + src/CMakeLists.txt | 2 + src/plasp/output/Logger.cpp | 4 +- src/plasp/pddl/Description.cpp | 9 +-- src/plasp/pddl/Domain.cpp | 9 +-- src/plasp/pddl/Expression.cpp | 9 +-- src/plasp/pddl/InitialState.cpp | 5 +- src/plasp/pddl/Problem.cpp | 9 +-- src/plasp/pddl/Requirement.cpp | 4 +- src/plasp/pddl/VariableStack.cpp | 2 +- src/plasp/pddl/expressions/Constant.cpp | 11 +-- src/plasp/pddl/expressions/Predicate.cpp | 2 +- src/plasp/pddl/expressions/PrimitiveType.cpp | 7 +- src/plasp/pddl/expressions/Variable.cpp | 7 +- src/plasp/sas/AssignedVariable.cpp | 4 +- src/plasp/sas/AxiomRule.cpp | 2 +- src/plasp/sas/Description.cpp | 37 +++++----- src/plasp/sas/Effect.cpp | 2 +- src/plasp/sas/Goal.cpp | 2 +- src/plasp/sas/InitialState.cpp | 2 +- src/plasp/sas/MutexGroup.cpp | 6 +- src/plasp/sas/Operator.cpp | 2 +- src/plasp/sas/Predicate.cpp | 7 +- src/plasp/sas/TranslatorASP.cpp | 2 + src/plasp/sas/Value.cpp | 13 ++-- src/plasp/sas/Variable.cpp | 11 +-- src/plasp/sas/VariableTransition.cpp | 2 +- tests/CMakeLists.txt | 1 + tests/TestPDDLParser.cpp | 2 +- 64 files changed, 322 insertions(+), 234 deletions(-) create mode 100644 lib/parsebase/CMakeLists.txt rename {include/plasp/input => lib/parsebase/include/parsebase}/Location.h (84%) rename {include/plasp/input => lib/parsebase/include/parsebase}/Parser.h (97%) rename {include/plasp/input => lib/parsebase/include/parsebase}/ParserException.h (70%) rename {include/plasp/input => lib/parsebase/include/parsebase}/ParserPolicy.h (91%) rename {include/plasp/input => lib/parsebase/include/parsebase}/Stream.h (86%) create mode 100644 lib/parsebase/src/CMakeLists.txt rename {src/plasp/input => lib/parsebase/src/parsebase}/Stream.cpp (94%) create mode 100644 lib/parsebase/tests/CMakeLists.txt rename tests/TestUtils.cpp => lib/parsebase/tests/TestParser.cpp (80%) create mode 100644 lib/parsebase/tests/main.cpp diff --git a/.travis.yml b/.travis.yml index f4873f3..bd61abd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,5 +42,5 @@ script: - git submodule update --recursive --init - mkdir -p build/debug - cd build/debug - - cmake ../.. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=$_CXX -DPLASP_BUILD_TESTS=ON - - make -j3 plasp-app && make -j3 run-tests + - cmake ../.. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=$_CXX -DPLASP_BUILD_TESTS=ON -DPARSEBASE_BUILD_TESTS=ON + - make -j3 plasp-app && make -j3 run-parsebase-tests && make -j3 run-tests diff --git a/CMakeLists.txt b/CMakeLists.txt index 1070d7d..6e55958 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,7 @@ if (CMAKE_GENERATOR STREQUAL "Ninja" AND set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always") endif() +add_subdirectory(lib/parsebase) add_subdirectory(src) add_subdirectory(app) if(PLASP_BUILD_TESTS) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 7907fe7..e0c76ee 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -6,6 +6,7 @@ file(GLOB core_headers "*.h") set(includes ${Boost_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/include + ${PROJECT_SOURCE_DIR}/lib/parsebase/include ) set(sources diff --git a/app/main.cpp b/app/main.cpp index e4f3029..3e40aeb 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -109,7 +109,7 @@ int main(int argc, char **argv) try { - plasp::input::Parser parser; + parsebase::Parser parser; if (variablesMap.count("input")) { @@ -160,7 +160,7 @@ int main(int argc, char **argv) translator.translate(); } } - catch (const plasp::input::ParserException &e) + catch (const parsebase::ParserException &e) { logger.log(plasp::output::Priority::Error, e.location(), e.message().c_str()); return EXIT_FAILURE; diff --git a/include/plasp/LanguageDetection.h b/include/plasp/LanguageDetection.h index 481ff5d..c292029 100644 --- a/include/plasp/LanguageDetection.h +++ b/include/plasp/LanguageDetection.h @@ -2,7 +2,8 @@ #define __PLASP__LANGUAGE_DETECTION_H #include -#include + +#include namespace plasp { @@ -13,7 +14,7 @@ namespace plasp // //////////////////////////////////////////////////////////////////////////////////////////////////// -Language::Type detectLanguage(input::Parser &parser) +Language::Type detectLanguage(parsebase::Parser &parser) { parser.skipWhiteSpace(); diff --git a/include/plasp/output/Logger.h b/include/plasp/output/Logger.h index ce65659..5530bbb 100644 --- a/include/plasp/output/Logger.h +++ b/include/plasp/output/Logger.h @@ -3,10 +3,11 @@ #include -#include #include #include +#include + namespace plasp { namespace output @@ -36,8 +37,8 @@ class Logger void log(Priority priority, const char *message); void log(Priority priority, const std::string &message); - void log(Priority priority, const input::Location &location, const char *message); - void log(Priority priority, const input::Location &location, const std::string &message); + void log(Priority priority, const parsebase::Location &location, const char *message); + void log(Priority priority, const parsebase::Location &location, const std::string &message); private: ColorStream m_outputStream; diff --git a/include/plasp/pddl/Action.h b/include/plasp/pddl/Action.h index 50f820c..4a42dcc 100644 --- a/include/plasp/pddl/Action.h +++ b/include/plasp/pddl/Action.h @@ -3,10 +3,11 @@ #include -#include #include #include +#include + namespace plasp { namespace pddl diff --git a/include/plasp/pddl/Description.h b/include/plasp/pddl/Description.h index 2483bf2..40b309d 100644 --- a/include/plasp/pddl/Description.h +++ b/include/plasp/pddl/Description.h @@ -5,7 +5,8 @@ #include #include -#include + +#include namespace plasp { @@ -47,9 +48,9 @@ class Description Context &m_context; - input::Stream::Position m_domainPosition; + parsebase::Stream::Position m_domainPosition; std::unique_ptr m_domain; - input::Stream::Position m_problemPosition; + parsebase::Stream::Position m_problemPosition; std::unique_ptr m_problem; }; diff --git a/include/plasp/pddl/Domain.h b/include/plasp/pddl/Domain.h index c13741a..e6c4d6c 100644 --- a/include/plasp/pddl/Domain.h +++ b/include/plasp/pddl/Domain.h @@ -75,19 +75,19 @@ class Domain std::string m_name; - input::Stream::Position m_requirementsPosition; + parsebase::Stream::Position m_requirementsPosition; Requirements m_requirements; - input::Stream::Position m_typesPosition; + parsebase::Stream::Position m_typesPosition; expressions::PrimitiveTypes m_types; - input::Stream::Position m_constantsPosition; + parsebase::Stream::Position m_constantsPosition; expressions::Constants m_constants; - input::Stream::Position m_predicatesPosition; + parsebase::Stream::Position m_predicatesPosition; expressions::PredicateDeclarations m_predicates; - std::vector m_actionPositions; + std::vector m_actionPositions; std::vector> m_actions; expressions::DerivedPredicates m_derivedPredicates; diff --git a/include/plasp/pddl/Expression.h b/include/plasp/pddl/Expression.h index 3b77321..d59609c 100644 --- a/include/plasp/pddl/Expression.h +++ b/include/plasp/pddl/Expression.h @@ -6,7 +6,7 @@ #include -#include +#include namespace plasp { diff --git a/include/plasp/pddl/Parser.h b/include/plasp/pddl/Parser.h index 4badd0e..ac10a4d 100644 --- a/include/plasp/pddl/Parser.h +++ b/include/plasp/pddl/Parser.h @@ -1,7 +1,7 @@ #ifndef __PLASP__PDDL__PARSER_H #define __PLASP__PDDL__PARSER_H -#include +#include namespace plasp { @@ -44,7 +44,7 @@ class PDDLParserPolicy //////////////////////////////////////////////////////////////////////////////////////////////////// -using Parser = input::Parser; +using Parser = parsebase::Parser; //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/include/plasp/pddl/Problem.h b/include/plasp/pddl/Problem.h index 05f53d3..0f13a08 100644 --- a/include/plasp/pddl/Problem.h +++ b/include/plasp/pddl/Problem.h @@ -64,18 +64,18 @@ class Problem std::string m_name; - input::Stream::Position m_domainPosition; + parsebase::Stream::Position m_domainPosition; - input::Stream::Position m_requirementsPosition; + parsebase::Stream::Position m_requirementsPosition; Requirements m_requirements; - input::Stream::Position m_objectsPosition; + parsebase::Stream::Position m_objectsPosition; expressions::Constants m_objects; - input::Stream::Position m_initialStatePosition; + parsebase::Stream::Position m_initialStatePosition; std::unique_ptr m_initialState; - input::Stream::Position m_goalPosition; + parsebase::Stream::Position m_goalPosition; ExpressionPointer m_goal; }; diff --git a/include/plasp/sas/AssignedVariable.h b/include/plasp/sas/AssignedVariable.h index 5eef7e3..cfb6367 100644 --- a/include/plasp/sas/AssignedVariable.h +++ b/include/plasp/sas/AssignedVariable.h @@ -4,10 +4,11 @@ #include #include -#include #include #include +#include + namespace plasp { namespace sas @@ -27,8 +28,8 @@ using AssignedVariables = std::vector; class AssignedVariable { public: - static AssignedVariable fromSAS(input::Parser<> &parser, const Variables &variables); - static AssignedVariable fromSAS(input::Parser<> &parser, const Variable &variable); + static AssignedVariable fromSAS(parsebase::Parser<> &parser, const Variables &variables); + static AssignedVariable fromSAS(parsebase::Parser<> &parser, const Variable &variable); public: explicit AssignedVariable(const Variable &variable, const Value &value); diff --git a/include/plasp/sas/AxiomRule.h b/include/plasp/sas/AxiomRule.h index 32875b2..8e73311 100644 --- a/include/plasp/sas/AxiomRule.h +++ b/include/plasp/sas/AxiomRule.h @@ -3,10 +3,11 @@ #include -#include #include #include +#include + namespace plasp { namespace sas @@ -29,7 +30,7 @@ class AxiomRule using Condition = AssignedVariable; using Conditions = AssignedVariables; - static AxiomRule fromSAS(input::Parser<> &parser, const Variables &variables); + static AxiomRule fromSAS(parsebase::Parser<> &parser, const Variables &variables); public: const Conditions &conditions() const; diff --git a/include/plasp/sas/Description.h b/include/plasp/sas/Description.h index 630d6a6..5ab46c0 100644 --- a/include/plasp/sas/Description.h +++ b/include/plasp/sas/Description.h @@ -1,13 +1,12 @@ #ifndef __PLASP__SAS__DESCRIPTION_H #define __PLASP__SAS__DESCRIPTION_H +#include #include #include #include -#include -#include #include #include #include @@ -15,6 +14,8 @@ #include #include +#include + namespace plasp { namespace sas @@ -29,9 +30,9 @@ namespace sas class Description { public: - static Description fromParser(input::Parser<> &&parser); + static Description fromParser(parsebase::Parser<> &&parser); static Description fromStream(std::istream &istream); - static Description fromFile(const boost::filesystem::path &path); + static Description fromFile(const std::experimental::filesystem::path &path); public: bool usesActionCosts() const; @@ -50,16 +51,16 @@ class Description private: Description(); - void parseContent(input::Parser<> &parser); + void parseContent(parsebase::Parser<> &parser); - void parseVersionSection(input::Parser<> &parser) const; - void parseMetricSection(input::Parser<> &parser); - void parseVariablesSection(input::Parser<> &parser); - void parseMutexSection(input::Parser<> &parser); - void parseInitialStateSection(input::Parser<> &parser); - void parseGoalSection(input::Parser<> &parser); - void parseOperatorSection(input::Parser<> &parser); - void parseAxiomSection(input::Parser<> &parser); + void parseVersionSection(parsebase::Parser<> &parser) const; + void parseMetricSection(parsebase::Parser<> &parser); + void parseVariablesSection(parsebase::Parser<> &parser); + void parseMutexSection(parsebase::Parser<> &parser); + void parseInitialStateSection(parsebase::Parser<> &parser); + void parseGoalSection(parsebase::Parser<> &parser); + void parseOperatorSection(parsebase::Parser<> &parser); + void parseAxiomSection(parsebase::Parser<> &parser); bool m_usesActionCosts; diff --git a/include/plasp/sas/Effect.h b/include/plasp/sas/Effect.h index 6fb5d4d..f8f2581 100644 --- a/include/plasp/sas/Effect.h +++ b/include/plasp/sas/Effect.h @@ -3,10 +3,11 @@ #include -#include #include #include +#include + namespace plasp { namespace sas @@ -29,7 +30,7 @@ class Effect using Condition = AssignedVariable; using Conditions = AssignedVariables; - static Effect fromSAS(input::Parser<> &parser, const Variables &variables, Conditions &preconditions); + static Effect fromSAS(parsebase::Parser<> &parser, const Variables &variables, Conditions &preconditions); public: const Conditions &conditions() const; diff --git a/include/plasp/sas/Goal.h b/include/plasp/sas/Goal.h index d3057e3..e59f679 100644 --- a/include/plasp/sas/Goal.h +++ b/include/plasp/sas/Goal.h @@ -1,9 +1,10 @@ #ifndef __PLASP__SAS__GOAL_H #define __PLASP__SAS__GOAL_H -#include #include +#include + namespace plasp { namespace sas @@ -21,7 +22,7 @@ class Goal using Fact = AssignedVariable; using Facts = AssignedVariables; - static Goal fromSAS(input::Parser<> &parser, const Variables &variables); + static Goal fromSAS(parsebase::Parser<> &parser, const Variables &variables); public: const Facts &facts() const; diff --git a/include/plasp/sas/InitialState.h b/include/plasp/sas/InitialState.h index c1b78e5..dea4c0f 100644 --- a/include/plasp/sas/InitialState.h +++ b/include/plasp/sas/InitialState.h @@ -1,9 +1,10 @@ #ifndef __PLASP__SAS__INITIAL_STATE_H #define __PLASP__SAS__INITIAL_STATE_H -#include #include +#include + namespace plasp { namespace sas @@ -21,7 +22,7 @@ class InitialState using Fact = AssignedVariable; using Facts = AssignedVariables; - static InitialState fromSAS(input::Parser<> &parser, const Variables &variables); + static InitialState fromSAS(parsebase::Parser<> &parser, const Variables &variables); public: const Facts &facts() const; diff --git a/include/plasp/sas/MutexGroup.h b/include/plasp/sas/MutexGroup.h index ea09316..729c73f 100644 --- a/include/plasp/sas/MutexGroup.h +++ b/include/plasp/sas/MutexGroup.h @@ -3,9 +3,10 @@ #include -#include #include +#include + namespace plasp { namespace sas @@ -28,7 +29,7 @@ class MutexGroup using Fact = AssignedVariable; using Facts = AssignedVariables; - static MutexGroup fromSAS(input::Parser<> &parser, const Variables &variables); + static MutexGroup fromSAS(parsebase::Parser<> &parser, const Variables &variables); public: const Facts &facts() const; diff --git a/include/plasp/sas/Operator.h b/include/plasp/sas/Operator.h index 2c528a7..090cef5 100644 --- a/include/plasp/sas/Operator.h +++ b/include/plasp/sas/Operator.h @@ -4,13 +4,14 @@ #include #include -#include #include #include #include #include #include +#include + namespace plasp { namespace sas @@ -33,7 +34,7 @@ class Operator using Condition = AssignedVariable; using Conditions = AssignedVariables; - static Operator fromSAS(input::Parser<> &parser, const Variables &variables); + static Operator fromSAS(parsebase::Parser<> &parser, const Variables &variables); public: void printPredicateAsASP(output::ColorStream &stream) const; diff --git a/include/plasp/sas/Predicate.h b/include/plasp/sas/Predicate.h index acd82f4..eefbf12 100644 --- a/include/plasp/sas/Predicate.h +++ b/include/plasp/sas/Predicate.h @@ -5,9 +5,10 @@ #include #include -#include #include +#include + namespace plasp { namespace sas @@ -22,7 +23,7 @@ namespace sas class Predicate { public: - static Predicate fromSAS(input::Parser<> &parser); + static Predicate fromSAS(parsebase::Parser<> &parser); using Arguments = std::vector; diff --git a/include/plasp/sas/TranslatorASP.h b/include/plasp/sas/TranslatorASP.h index 17287df..a2283e9 100644 --- a/include/plasp/sas/TranslatorASP.h +++ b/include/plasp/sas/TranslatorASP.h @@ -1,11 +1,11 @@ #ifndef __PLASP__SAS__TRANSLATOR_ASP_H #define __PLASP__SAS__TRANSLATOR_ASP_H +#include + #include #include -#include - namespace plasp { namespace sas diff --git a/include/plasp/sas/Value.h b/include/plasp/sas/Value.h index ea9cfd9..22db9a2 100644 --- a/include/plasp/sas/Value.h +++ b/include/plasp/sas/Value.h @@ -5,9 +5,10 @@ #include #include -#include #include +#include + namespace plasp { namespace sas @@ -39,8 +40,8 @@ struct Value static const Value Any; static const Value None; - static Value fromSAS(input::Parser<> &parser); - static const Value &referenceFromSAS(input::Parser<> &parser, const Variable &variable); + static Value fromSAS(parsebase::Parser<> &parser); + static const Value &referenceFromSAS(parsebase::Parser<> &parser, const Variable &variable); public: Value negated() const; diff --git a/include/plasp/sas/Variable.h b/include/plasp/sas/Variable.h index 4a0d719..01f0238 100644 --- a/include/plasp/sas/Variable.h +++ b/include/plasp/sas/Variable.h @@ -5,10 +5,11 @@ #include #include -#include #include #include +#include + namespace plasp { namespace sas @@ -28,8 +29,8 @@ using Variables = std::vector; class Variable { public: - static Variable fromSAS(input::Parser<> &parser); - static const Variable &referenceFromSAS(input::Parser<> &parser, const Variables &variables); + static Variable fromSAS(parsebase::Parser<> &parser); + static const Variable &referenceFromSAS(parsebase::Parser<> &parser, const Variables &variables); public: void printNameAsASPPredicate(output::ColorStream &outputStream) const; diff --git a/include/plasp/sas/VariableTransition.h b/include/plasp/sas/VariableTransition.h index a57eaba..fd9dc5b 100644 --- a/include/plasp/sas/VariableTransition.h +++ b/include/plasp/sas/VariableTransition.h @@ -3,10 +3,11 @@ #include -#include #include #include +#include + namespace plasp { namespace sas @@ -26,7 +27,7 @@ using VariableTransitions = std::vector; class VariableTransition { public: - static VariableTransition fromSAS(input::Parser<> &parser, const Variables &variables); + static VariableTransition fromSAS(parsebase::Parser<> &parser, const Variables &variables); public: const Variable &variable() const; diff --git a/lib/parsebase/CMakeLists.txt b/lib/parsebase/CMakeLists.txt new file mode 100644 index 0000000..51091c4 --- /dev/null +++ b/lib/parsebase/CMakeLists.txt @@ -0,0 +1,28 @@ +cmake_minimum_required(VERSION 2.6) +project(parsebase) + +option(PARSEBASE_BUILD_TESTS "Build unit tests" OFF) + +set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic -Werror") +set(CMAKE_CXX_FLAGS_DEBUG "-g") + +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + +if (CMAKE_GENERATOR STREQUAL "Ninja" AND + ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) OR + (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5))) + # Force colored warnings in Ninja's output, if the compiler has -fdiagnostics-color support. + # Rationale in https://github.com/ninja-build/ninja/issues/814 + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always") +endif() + +add_subdirectory(src) +if(PARSEBASE_BUILD_TESTS) + add_subdirectory(tests) +endif(PARSEBASE_BUILD_TESTS) diff --git a/include/plasp/input/Location.h b/lib/parsebase/include/parsebase/Location.h similarity index 84% rename from include/plasp/input/Location.h rename to lib/parsebase/include/parsebase/Location.h index 9c17789..ef07a08 100644 --- a/include/plasp/input/Location.h +++ b/lib/parsebase/include/parsebase/Location.h @@ -1,11 +1,9 @@ -#ifndef __PLASP__INPUT__LOCATION_H -#define __PLASP__INPUT__LOCATION_H +#ifndef __PARSE_BASE__LOCATION_H +#define __PARSE_BASE__LOCATION_H #include -namespace plasp -{ -namespace input +namespace parsebase { //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -28,7 +26,6 @@ struct Location //////////////////////////////////////////////////////////////////////////////////////////////////// -} } #endif diff --git a/include/plasp/input/Parser.h b/lib/parsebase/include/parsebase/Parser.h similarity index 97% rename from include/plasp/input/Parser.h rename to lib/parsebase/include/parsebase/Parser.h index fc0c096..749024b 100644 --- a/include/plasp/input/Parser.h +++ b/lib/parsebase/include/parsebase/Parser.h @@ -1,20 +1,18 @@ -#ifndef __PLASP__INPUT__PARSER_H -#define __PLASP__INPUT__PARSER_H +#ifndef __PARSE_BASE__PARSER_H +#define __PARSE_BASE__PARSER_H +#include +#include #include #include #include #include -#include +#include +#include +#include -#include -#include -#include - -namespace plasp -{ -namespace input +namespace parsebase { template @@ -286,7 +284,7 @@ void Parser::removeComments(const std::string &startSequence, cons const auto removeRange = [&](const auto &start, const auto &end) { - BOOST_ASSERT(start != -1); + assert(start != -1); m_stream.clear(); m_stream.seekp(start); @@ -564,7 +562,6 @@ bool Parser::testImpl(bool expectedValue) //////////////////////////////////////////////////////////////////////////////////////////////////// -} } #endif diff --git a/include/plasp/input/ParserException.h b/lib/parsebase/include/parsebase/ParserException.h similarity index 70% rename from include/plasp/input/ParserException.h rename to lib/parsebase/include/parsebase/ParserException.h index 81a0ea6..f62c54c 100644 --- a/include/plasp/input/ParserException.h +++ b/lib/parsebase/include/parsebase/ParserException.h @@ -1,14 +1,12 @@ -#ifndef __PLASP__INPUT__PARSER_EXCEPTION_H -#define __PLASP__INPUT__PARSER_EXCEPTION_H +#ifndef __PARSE_BASE__PARSER_EXCEPTION_H +#define __PARSE_BASE__PARSER_EXCEPTION_H #include #include -#include +#include -namespace plasp -{ -namespace input +namespace parsebase { //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -20,17 +18,17 @@ namespace input class ParserException: public std::exception { public: - explicit ParserException(const input::Location &location) + explicit ParserException(const Location &location) : ParserException(location, "unspecified parser error") { } - explicit ParserException(const input::Location &location, const char *message) + explicit ParserException(const Location &location, const char *message) : ParserException(location, static_cast(message)) { } - explicit ParserException(const input::Location &location, const std::string &message) + explicit ParserException(const Location &location, const std::string &message) : m_location{location}, m_message{message}, // TODO: refactor @@ -48,7 +46,7 @@ class ParserException: public std::exception return m_plainMessage.c_str(); } - const input::Location &location() const + const Location &location() const { return m_location; } @@ -59,14 +57,13 @@ class ParserException: public std::exception } private: - input::Location m_location; + Location m_location; std::string m_message; std::string m_plainMessage; }; //////////////////////////////////////////////////////////////////////////////////////////////////// -} } #endif diff --git a/include/plasp/input/ParserPolicy.h b/lib/parsebase/include/parsebase/ParserPolicy.h similarity index 91% rename from include/plasp/input/ParserPolicy.h rename to lib/parsebase/include/parsebase/ParserPolicy.h index 8b829c5..a45c862 100644 --- a/include/plasp/input/ParserPolicy.h +++ b/lib/parsebase/include/parsebase/ParserPolicy.h @@ -1,11 +1,9 @@ -#ifndef __PLASP__INPUT__PARSER_POLICY_H -#define __PLASP__INPUT__PARSER_POLICY_H +#ifndef __PARSE_BASE__PARSER_POLICY_H +#define __PARSE_BASE__PARSER_POLICY_H #include -namespace plasp -{ -namespace input +namespace parsebase { //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -66,7 +64,6 @@ class CaseInsensitiveParserPolicy //////////////////////////////////////////////////////////////////////////////////////////////////// -} } #endif diff --git a/include/plasp/input/Stream.h b/lib/parsebase/include/parsebase/Stream.h similarity index 86% rename from include/plasp/input/Stream.h rename to lib/parsebase/include/parsebase/Stream.h index f52e20c..702bfed 100644 --- a/include/plasp/input/Stream.h +++ b/lib/parsebase/include/parsebase/Stream.h @@ -1,18 +1,15 @@ -#ifndef __PLASP__INPUT__STREAM_H -#define __PLASP__INPUT__STREAM_H +#ifndef __PARSE_BASE__STREAM_H +#define __PARSE_BASE__STREAM_H +#include #include #include #include #include -#include +#include -#include - -namespace plasp -{ -namespace input +namespace parsebase { //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -56,7 +53,7 @@ class Stream ~Stream() = default; void read(std::string streamName, std::istream &istream); - void read(const boost::filesystem::path &path); + void read(const std::experimental::filesystem::path &path); void reset(); void seek(Position position); @@ -77,7 +74,6 @@ class Stream //////////////////////////////////////////////////////////////////////////////////////////////////// -} } #endif diff --git a/lib/parsebase/src/CMakeLists.txt b/lib/parsebase/src/CMakeLists.txt new file mode 100644 index 0000000..f7b5f6a --- /dev/null +++ b/lib/parsebase/src/CMakeLists.txt @@ -0,0 +1,21 @@ +set(target parsebase) + +file(GLOB core_sources "parsebase/*.cpp") +file(GLOB core_headers "../include/parsebase/*.h") + +set(includes + ${PROJECT_SOURCE_DIR}/include +) + +set(sources + ${core_sources} + ${core_headers} +) + +set(libraries + stdc++fs +) + +add_library(${target} ${sources}) +target_include_directories(${target} PRIVATE ${includes}) +target_link_libraries(${target} ${libraries}) diff --git a/src/plasp/input/Stream.cpp b/lib/parsebase/src/parsebase/Stream.cpp similarity index 94% rename from src/plasp/input/Stream.cpp rename to lib/parsebase/src/parsebase/Stream.cpp index 8b66aba..7267e94 100644 --- a/src/plasp/input/Stream.cpp +++ b/lib/parsebase/src/parsebase/Stream.cpp @@ -1,12 +1,11 @@ -#include +#include +#include #include -#include +#include -namespace plasp -{ -namespace input +namespace parsebase { //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -44,9 +43,9 @@ void Stream::read(std::string streamName, std::istream &istream) //////////////////////////////////////////////////////////////////////////////////////////////////// -void Stream::read(const boost::filesystem::path &path) +void Stream::read(const std::experimental::filesystem::path &path) { - if (!boost::filesystem::is_regular_file(path)) + if (!std::experimental::filesystem::is_regular_file(path)) throw std::runtime_error("File does not exist: “" + path.string() + "”"); std::ifstream fileStream(path.string(), std::ios::in); @@ -161,4 +160,3 @@ void Stream::advance() //////////////////////////////////////////////////////////////////////////////////////////////////// } -} diff --git a/lib/parsebase/tests/CMakeLists.txt b/lib/parsebase/tests/CMakeLists.txt new file mode 100644 index 0000000..46f68ca --- /dev/null +++ b/lib/parsebase/tests/CMakeLists.txt @@ -0,0 +1,22 @@ +set(target parsebase-tests) + +file(GLOB core_sources "*.cpp") + +set(includes + ${Boost_INCLUDE_DIRS} + ${PROJECT_SOURCE_DIR}/include + ${PROJECT_SOURCE_DIR}/../../lib/catch/single_include +) + +set(libraries + parsebase +) + +add_executable(${target} ${core_sources}) +target_include_directories(${target} PRIVATE ${includes}) +target_link_libraries(${target} ${libraries}) + +add_custom_target(run-parsebase-tests + COMMAND ${CMAKE_BINARY_DIR}/bin/parsebase-tests + DEPENDS ${target} + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/tests) diff --git a/tests/TestUtils.cpp b/lib/parsebase/tests/TestParser.cpp similarity index 80% rename from tests/TestUtils.cpp rename to lib/parsebase/tests/TestParser.cpp index 20d7eeb..c014d6e 100644 --- a/tests/TestUtils.cpp +++ b/lib/parsebase/tests/TestParser.cpp @@ -1,14 +1,14 @@ #include -#include -#include +#include +#include //////////////////////////////////////////////////////////////////////////////////////////////////// TEST_CASE("[parser] Simple strings are parsed correctly", "[parser]") { std::stringstream s(" identifier 5 \n-51\t 0 1 100 200 -300 -400"); - plasp::input::Parser<> p("input", s); + parsebase::Parser<> p("input", s); REQUIRE(p.parse() == "identifier"); REQUIRE(p.parse() == 5u); @@ -19,7 +19,7 @@ TEST_CASE("[parser] Simple strings are parsed correctly", "[parser]") REQUIRE(p.parse() == 100); REQUIRE(p.parse() == 200u); REQUIRE(p.parse() == -300); - REQUIRE_THROWS_AS(p.parse(), plasp::input::ParserException); + REQUIRE_THROWS_AS(p.parse(), parsebase::ParserException); } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -27,7 +27,7 @@ TEST_CASE("[parser] Simple strings are parsed correctly", "[parser]") TEST_CASE("[parser] Parsing exceptions are correctly reported", "[parser]") { std::stringstream s(" identifier 5 \n-51\t 0 1 100 200 -300 -400"); - plasp::input::Parser<> p("input", s); + parsebase::Parser<> p("input", s); REQUIRE_NOTHROW(p.expect("identifier")); REQUIRE_NOTHROW(p.expect(5u)); @@ -38,31 +38,31 @@ TEST_CASE("[parser] Parsing exceptions are correctly reported", "[parser]") REQUIRE_NOTHROW(p.expect(100)); REQUIRE_NOTHROW(p.expect(200u)); REQUIRE_NOTHROW(p.expect(-300)); - REQUIRE_THROWS_AS(p.expect(-400), plasp::input::ParserException); + REQUIRE_THROWS_AS(p.expect(-400), parsebase::ParserException); p.seek(0); - REQUIRE_THROWS_AS(p.expect("error"), plasp::input::ParserException); + REQUIRE_THROWS_AS(p.expect("error"), parsebase::ParserException); p.seek(14); - REQUIRE_THROWS_AS(p.expect(6u), plasp::input::ParserException); + REQUIRE_THROWS_AS(p.expect(6u), parsebase::ParserException); p.seek(17); - REQUIRE_THROWS_AS(p.expect(-50), plasp::input::ParserException); + REQUIRE_THROWS_AS(p.expect(-50), parsebase::ParserException); p.seek(24); - REQUIRE_THROWS_AS(p.expect(true), plasp::input::ParserException); + REQUIRE_THROWS_AS(p.expect(true), parsebase::ParserException); p.seek(26); - REQUIRE_THROWS_AS(p.expect(false), plasp::input::ParserException); + REQUIRE_THROWS_AS(p.expect(false), parsebase::ParserException); p.seek(28); - REQUIRE_THROWS_AS(p.expect(101), plasp::input::ParserException); + REQUIRE_THROWS_AS(p.expect(101), parsebase::ParserException); p.seek(31); - REQUIRE_THROWS_AS(p.expect(201), plasp::input::ParserException); + REQUIRE_THROWS_AS(p.expect(201), parsebase::ParserException); p.seek(34); - REQUIRE_THROWS_AS(p.expect(-299), plasp::input::ParserException); + REQUIRE_THROWS_AS(p.expect(-299), parsebase::ParserException); } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -70,9 +70,9 @@ TEST_CASE("[parser] Parsing exceptions are correctly reported", "[parser]") TEST_CASE("[parser] While parsing, the cursor position is as expected", "[parser]") { std::stringstream s(" identifier 5 \n-51\t 0 1"); - plasp::input::Parser<> p("input", s); + parsebase::Parser<> p("input", s); - plasp::input::Parser<>::Position pos; + parsebase::Parser<>::Position pos; pos = p.position(); REQUIRE(p.testAndReturn("error") == false); @@ -130,46 +130,46 @@ TEST_CASE("[parser] While parsing, the cursor position is as expected", "[parser TEST_CASE("[parser] The end of the input stream is correctly handled", "[parser]") { std::stringstream s1("test"); - plasp::input::Parser<> p1("input", s1); + parsebase::Parser<> p1("input", s1); REQUIRE_NOTHROW(p1.expect("test")); - REQUIRE_THROWS_AS(p1.parse(), plasp::input::ParserException); + REQUIRE_THROWS_AS(p1.parse(), parsebase::ParserException); std::stringstream s2("test1 test2 test3"); - plasp::input::Parser<> p2("input", s2); + parsebase::Parser<> p2("input", s2); REQUIRE_NOTHROW(p2.expect("test1")); REQUIRE_NOTHROW(p2.expect("test2")); REQUIRE_NOTHROW(p2.expect("test3")); - REQUIRE_THROWS_AS(p2.parse(), plasp::input::ParserException); + REQUIRE_THROWS_AS(p2.parse(), parsebase::ParserException); std::stringstream s3("-127"); - plasp::input::Parser<> p3("input", s3); + parsebase::Parser<> p3("input", s3); p3.expect(-127); - REQUIRE_THROWS_AS(p3.parse(), plasp::input::ParserException); + REQUIRE_THROWS_AS(p3.parse(), parsebase::ParserException); std::stringstream s4("128 -1023 -4095"); - plasp::input::Parser<> p4("input", s4); + parsebase::Parser<> p4("input", s4); REQUIRE_NOTHROW(p4.expect(128)); REQUIRE_NOTHROW(p4.expect(-1023)); REQUIRE_NOTHROW(p4.expect(-4095)); - REQUIRE_THROWS_AS(p4.parse(), plasp::input::ParserException); + REQUIRE_THROWS_AS(p4.parse(), parsebase::ParserException); std::stringstream s5("0"); - plasp::input::Parser<> p5("input", s5); + parsebase::Parser<> p5("input", s5); p5.expect(false); - REQUIRE_THROWS_AS(p5.parse(), plasp::input::ParserException); + REQUIRE_THROWS_AS(p5.parse(), parsebase::ParserException); std::stringstream s6("0 1 0"); - plasp::input::Parser<> p6("input", s6); + parsebase::Parser<> p6("input", s6); REQUIRE_NOTHROW(p6.expect(false)); REQUIRE_NOTHROW(p6.expect(true)); REQUIRE_NOTHROW(p6.expect(false)); - REQUIRE_THROWS_AS(p6.parse(), plasp::input::ParserException); + REQUIRE_THROWS_AS(p6.parse(), parsebase::ParserException); } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -177,11 +177,11 @@ TEST_CASE("[parser] The end of the input stream is correctly handled", "[parser] TEST_CASE("[parser] While parsing, the cursor location is as expcected", "[parser]") { std::stringstream s("123 \n4\ntest1\n test2\ntest3 \ntest4\n\n\n\n"); - plasp::input::Parser<> p("input", s); + parsebase::Parser<> p("input", s); const auto startPosition = p.position(); - plasp::input::Location l; + parsebase::Location l; l = p.location(); REQUIRE(l.rowStart == 1u); @@ -285,11 +285,11 @@ TEST_CASE("[parser] While parsing, the cursor location is as expcected", "[parse TEST_CASE("[parser] Comments are correctly removed", "[parser]") { std::stringstream s1("; comment at beginning\ntest1; comment in between\ntest2; comment at end"); - plasp::input::Parser<> p1("input", s1); + parsebase::Parser<> p1("input", s1); p1.removeComments(";", "\n", false); - plasp::input::Location l; + parsebase::Location l; REQUIRE_NOTHROW(p1.expect("test1")); @@ -308,7 +308,7 @@ TEST_CASE("[parser] Comments are correctly removed", "[parser]") REQUIRE(p1.atEnd()); std::stringstream s2("test;"); - plasp::input::Parser<> p2("input", s2); + parsebase::Parser<> p2("input", s2); p2.removeComments(";", "\n", false); @@ -319,7 +319,7 @@ TEST_CASE("[parser] Comments are correctly removed", "[parser]") REQUIRE(p2.atEnd()); std::stringstream s3("/* comment at start */ test1 /* comment in between */ test2 /*"); - plasp::input::Parser<> p3("input", s3); + parsebase::Parser<> p3("input", s3); p3.removeComments("/*", "*/", true); diff --git a/lib/parsebase/tests/main.cpp b/lib/parsebase/tests/main.cpp new file mode 100644 index 0000000..b3143fb --- /dev/null +++ b/lib/parsebase/tests/main.cpp @@ -0,0 +1,2 @@ +#define CATCH_CONFIG_MAIN +#include diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2a46f71..e7622c4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,6 +27,7 @@ file(GLOB utils_headers "../include/plasp/utils/*.h") set(includes ${Boost_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/include + ${PROJECT_SOURCE_DIR}/lib/parsebase/include ) set(sources @@ -57,6 +58,7 @@ set(sources set(libraries ${Boost_LIBRARIES} + parsebase pthread ) diff --git a/src/plasp/output/Logger.cpp b/src/plasp/output/Logger.cpp index 634ff98..9ddd3b7 100644 --- a/src/plasp/output/Logger.cpp +++ b/src/plasp/output/Logger.cpp @@ -123,7 +123,7 @@ void Logger::log(Priority priority, const std::string &message) //////////////////////////////////////////////////////////////////////////////////////////////////// -void Logger::log(Priority priority, const input::Location &location, const char *message) +void Logger::log(Priority priority, const parsebase::Location &location, const char *message) { const auto priorityID = static_cast(priority); @@ -150,7 +150,7 @@ void Logger::log(Priority priority, const input::Location &location, const char //////////////////////////////////////////////////////////////////////////////////////////////////// -void Logger::log(Priority priority, const input::Location &location, const std::string &message) +void Logger::log(Priority priority, const parsebase::Location &location, const std::string &message) { log(priority, location, message.c_str()); } diff --git a/src/plasp/pddl/Description.cpp b/src/plasp/pddl/Description.cpp index 25db03f..bf84b1e 100644 --- a/src/plasp/pddl/Description.cpp +++ b/src/plasp/pddl/Description.cpp @@ -5,10 +5,11 @@ #include -#include #include #include +#include + namespace plasp { namespace pddl @@ -168,7 +169,7 @@ void Description::findSections() if (parser.testAndSkip("domain")) { if (m_domainPosition != -1) - throw input::ParserException(parser.location(), "PDDL description may not contain two domains"); + throw parsebase::ParserException(parser.location(), "PDDL description may not contain two domains"); m_domainPosition = position; @@ -178,7 +179,7 @@ void Description::findSections() else if (m_context.parser.testAndSkip("problem")) { if (m_problemPosition != -1) - throw input::ParserException(parser.location(), "PDDL description may currently not contain two problems"); + throw parsebase::ParserException(parser.location(), "PDDL description may currently not contain two problems"); m_problem = std::make_unique(Problem(m_context, *m_domain)); @@ -190,7 +191,7 @@ void Description::findSections() else { const auto sectionIdentifier = parser.parse(); - throw input::ParserException(parser.location(), "unknown PDDL section “" + sectionIdentifier + "”"); + throw parsebase::ParserException(parser.location(), "unknown PDDL section “" + sectionIdentifier + "”"); } m_context.parser.skipWhiteSpace(); diff --git a/src/plasp/pddl/Domain.cpp b/src/plasp/pddl/Domain.cpp index 216f3ce..07c034a 100644 --- a/src/plasp/pddl/Domain.cpp +++ b/src/plasp/pddl/Domain.cpp @@ -2,7 +2,6 @@ #include -#include #include #include #include @@ -10,6 +9,8 @@ #include #include +#include + namespace plasp { namespace pddl @@ -51,7 +52,7 @@ void Domain::findSections() if (unique && sectionPosition != -1) { parser.seek(value); - throw input::ParserException(parser.location(), "only one “:" + sectionName + "” section allowed"); + throw parsebase::ParserException(parser.location(), "only one “:" + sectionName + "” section allowed"); } sectionPosition = value; @@ -101,7 +102,7 @@ void Domain::findSections() const auto sectionIdentifier = parser.parseIdentifier(); parser.seek(position); - throw input::ParserException(parser.location(), "unknown domain section “" + sectionIdentifier + "”"); + throw parsebase::ParserException(parser.location(), "unknown domain section “" + sectionIdentifier + "”"); } // Skip section for now and parse it later @@ -354,7 +355,7 @@ void Domain::parseTypeSection() while (parser.currentCharacter() != ')') { if (parser.currentCharacter() == '(') - throw input::ParserException(parser.location(), "only primitive types are allowed in type section"); + throw parsebase::ParserException(parser.location(), "only primitive types are allowed in type section"); expressions::PrimitiveType::parseTypedDeclaration(m_context, *this); diff --git a/src/plasp/pddl/Expression.cpp b/src/plasp/pddl/Expression.cpp index 82d3703..7f0f52c 100644 --- a/src/plasp/pddl/Expression.cpp +++ b/src/plasp/pddl/Expression.cpp @@ -1,6 +1,5 @@ #include -#include #include #include #include @@ -17,6 +16,8 @@ #include #include +#include + namespace plasp { namespace pddl @@ -181,7 +182,7 @@ ExpressionPointer parseExpression(Context &context, ExpressionContext &expressio const auto expressionIdentifier = parser.parseIdentifier(); parser.seek(position); - throw input::ParserException(parser.location(), "expression type “" + expressionIdentifier + "” unknown or not allowed in this context"); + throw parsebase::ParserException(parser.location(), "expression type “" + expressionIdentifier + "” unknown or not allowed in this context"); } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -256,7 +257,7 @@ ExpressionPointer parseEffectBodyExpression(Context &context, ExpressionContext const auto expressionIdentifier = parser.parseIdentifier(); parser.seek(position); - throw input::ParserException(parser.location(), "expression type “" + expressionIdentifier + "” unknown or not allowed in this context"); + throw parsebase::ParserException(parser.location(), "expression type “" + expressionIdentifier + "” unknown or not allowed in this context"); } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -282,7 +283,7 @@ ExpressionPointer parsePredicate(Context &context, ExpressionContext &expression if ((expression = expressions::Predicate::parse(context, expressionContext))) return expression; - throw input::ParserException(parser.location(), "expected predicate"); + throw parsebase::ParserException(parser.location(), "expected predicate"); } //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/plasp/pddl/InitialState.cpp b/src/plasp/pddl/InitialState.cpp index 847e8b0..d433b8d 100644 --- a/src/plasp/pddl/InitialState.cpp +++ b/src/plasp/pddl/InitialState.cpp @@ -1,6 +1,5 @@ #include -#include #include #include #include @@ -9,6 +8,8 @@ #include #include +#include + namespace plasp { namespace pddl @@ -58,7 +59,7 @@ std::unique_ptr InitialState::parseDeclaration(Context &context, const auto expressionIdentifier = parser.parseIdentifier(); parser.seek(position); - throw input::ParserException(parser.location(), "expression type “" + expressionIdentifier + "” unknown or not allowed in this context"); + throw parsebase::ParserException(parser.location(), "expression type “" + expressionIdentifier + "” unknown or not allowed in this context"); }; parser.skipWhiteSpace(); diff --git a/src/plasp/pddl/Problem.cpp b/src/plasp/pddl/Problem.cpp index 1af3523..2665d5b 100644 --- a/src/plasp/pddl/Problem.cpp +++ b/src/plasp/pddl/Problem.cpp @@ -2,13 +2,14 @@ #include -#include #include #include #include #include #include +#include + namespace plasp { namespace pddl @@ -52,7 +53,7 @@ void Problem::findSections() if (unique && sectionPosition != -1) { parser.seek(value); - throw input::ParserException(parser.location(), "only one “:" + sectionName + "” section allowed"); + throw parsebase::ParserException(parser.location(), "only one “:" + sectionName + "” section allowed"); } sectionPosition = value; @@ -97,7 +98,7 @@ void Problem::findSections() const auto sectionIdentifier = parser.parseIdentifier(); parser.seek(position); - throw input::ParserException(parser.location(), "unknown problem section “" + sectionIdentifier + "”"); + throw parsebase::ParserException(parser.location(), "unknown problem section “" + sectionIdentifier + "”"); } // Skip section for now and parse it later @@ -203,7 +204,7 @@ void Problem::parseDomainSection() const auto domainName = parser.parseIdentifier(); if (m_domain.name() != domainName) - throw input::ParserException(parser.location(), "domains do not match (“" + m_domain.name() + "” and “" + domainName + "”)"); + throw parsebase::ParserException(parser.location(), "domains do not match (“" + m_domain.name() + "” and “" + domainName + "”)"); parser.expect(")"); } diff --git a/src/plasp/pddl/Requirement.cpp b/src/plasp/pddl/Requirement.cpp index 0c21dd9..9e03dd9 100644 --- a/src/plasp/pddl/Requirement.cpp +++ b/src/plasp/pddl/Requirement.cpp @@ -4,7 +4,7 @@ #include #include -#include +#include namespace plasp { @@ -89,7 +89,7 @@ Requirement Requirement::parse(Context &context) const auto match = requirementTypesToPDDL.right.find(requirementName); if (match == requirementTypesToPDDL.right.end()) - throw input::ParserException(parser.location(), "unknown PDDL requirement “" + requirementName + "”"); + throw parsebase::ParserException(parser.location(), "unknown PDDL requirement “" + requirementName + "”"); const auto requirementType = match->second; diff --git a/src/plasp/pddl/VariableStack.cpp b/src/plasp/pddl/VariableStack.cpp index 3220528..938c0ef 100644 --- a/src/plasp/pddl/VariableStack.cpp +++ b/src/plasp/pddl/VariableStack.cpp @@ -53,7 +53,7 @@ expressions::VariablePointer VariableStack::parseAndFind(plasp::pddl::Context &c return match->get(); } - throw input::ParserException(parser.location(), "variable “" + variableName + "” used but never declared"); + throw parsebase::ParserException(parser.location(), "variable “" + variableName + "” used but never declared"); } //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/plasp/pddl/expressions/Constant.cpp b/src/plasp/pddl/expressions/Constant.cpp index 4c22f20..1326189 100644 --- a/src/plasp/pddl/expressions/Constant.cpp +++ b/src/plasp/pddl/expressions/Constant.cpp @@ -4,13 +4,14 @@ #include -#include #include #include #include #include #include +#include + namespace plasp { namespace pddl @@ -114,7 +115,7 @@ void Constant::parseTypedDeclarations(Context &context, Domain &domain) domain.checkRequirement(Requirement::Type::Typing); // If no types are given, check that typing is not a requirement else if (domain.hasRequirement(Requirement::Type::Typing)) - throw input::ParserException(parser.location(), "constant has undeclared type"); + throw parsebase::ParserException(parser.location(), "constant has undeclared type"); } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -141,7 +142,7 @@ void Constant::parseTypedDeclarations(Context &context, Problem &problem) problem.checkRequirement(Requirement::Type::Typing); // If no types are given, check that typing is not a requirement else if (problem.hasRequirement(Requirement::Type::Typing)) - throw input::ParserException(parser.location(), "constant has undeclared type"); + throw parsebase::ParserException(parser.location(), "constant has undeclared type"); } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -159,7 +160,7 @@ ConstantPointer Constant::parseAndFind(Context &context, const Domain &domain) if (constant != nullptr) return constant; - throw input::ParserException(parser.location(), "constant “" + constantName + "” used but never declared"); + throw parsebase::ParserException(parser.location(), "constant “" + constantName + "” used but never declared"); } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -182,7 +183,7 @@ ConstantPointer Constant::parseAndFind(Context &context, const Problem &problem) if (constant) return constant; - throw input::ParserException(parser.location(), "constant “" + constantName + "” used but never declared"); + throw parsebase::ParserException(parser.location(), "constant “" + constantName + "” used but never declared"); } //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/plasp/pddl/expressions/Predicate.cpp b/src/plasp/pddl/expressions/Predicate.cpp index aea2335..62539ac 100644 --- a/src/plasp/pddl/expressions/Predicate.cpp +++ b/src/plasp/pddl/expressions/Predicate.cpp @@ -126,7 +126,7 @@ PredicatePointer Predicate::parse(Context &context, const Problem &problem) while (parser.currentCharacter() != ')') { if (parser.currentCharacter() == '?') - throw input::ParserException(parser.location(), "variables not allowed in this context"); + throw parsebase::ParserException(parser.location(), "variables not allowed in this context"); // Parse objects and constants const auto constant = Constant::parseAndFind(context, problem); diff --git a/src/plasp/pddl/expressions/PrimitiveType.cpp b/src/plasp/pddl/expressions/PrimitiveType.cpp index b6e84cb..57deab6 100644 --- a/src/plasp/pddl/expressions/PrimitiveType.cpp +++ b/src/plasp/pddl/expressions/PrimitiveType.cpp @@ -4,11 +4,12 @@ #include -#include #include #include #include +#include + namespace plasp { namespace pddl @@ -112,7 +113,7 @@ PrimitiveTypePointer PrimitiveType::parseAndFind(Context &context, Domain &domai const auto typeName = parser.parseIdentifier(); if (typeName.empty()) - throw input::ParserException(parser.location(), "no type supplied"); + throw parsebase::ParserException(parser.location(), "no type supplied"); const auto match = std::find_if(types.cbegin(), types.cend(), [&](const auto &primitiveType) @@ -129,7 +130,7 @@ PrimitiveTypePointer PrimitiveType::parseAndFind(Context &context, Domain &domai types.emplace_back(PrimitiveTypePointer(new PrimitiveType(typeName))); } else - throw input::ParserException(parser.location(), "type “" + typeName + "” used but never declared"); + throw parsebase::ParserException(parser.location(), "type “" + typeName + "” used but never declared"); return types.back().get(); } diff --git a/src/plasp/pddl/expressions/Variable.cpp b/src/plasp/pddl/expressions/Variable.cpp index 15b70e9..a999863 100644 --- a/src/plasp/pddl/expressions/Variable.cpp +++ b/src/plasp/pddl/expressions/Variable.cpp @@ -4,7 +4,6 @@ #include -#include #include #include #include @@ -12,6 +11,8 @@ #include #include +#include + namespace plasp { namespace pddl @@ -60,7 +61,7 @@ void Variable::parseDeclaration(Context &context, Variables ¶meters) }); if (match != parameters.cend()) - throw input::ParserException(parser.location(), "variable “" + variable->m_name + "” already declared in this scope"); + throw parsebase::ParserException(parser.location(), "variable “" + variable->m_name + "” already declared in this scope"); // Flag variable for potentially upcoming type declaration variable->setDirty(); @@ -137,7 +138,7 @@ void Variable::parseTypedDeclarations(Context &context, ExpressionContext &expre expressionContext.checkRequirement(Requirement::Type::Typing); // If no types are given, check that typing is not a requirement else if (expressionContext.hasRequirement(Requirement::Type::Typing)) - throw input::ParserException(parser.location(), "variable has undeclared type"); + throw parsebase::ParserException(parser.location(), "variable has undeclared type"); } //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/plasp/sas/AssignedVariable.cpp b/src/plasp/sas/AssignedVariable.cpp index 6494dae..9e7117f 100644 --- a/src/plasp/sas/AssignedVariable.cpp +++ b/src/plasp/sas/AssignedVariable.cpp @@ -31,7 +31,7 @@ AssignedVariable::AssignedVariable(const Variable &variable, const Value &value) //////////////////////////////////////////////////////////////////////////////////////////////////// -AssignedVariable AssignedVariable::fromSAS(input::Parser<> &parser, const Variables &variables) +AssignedVariable AssignedVariable::fromSAS(parsebase::Parser<> &parser, const Variables &variables) { AssignedVariable assignedVariable; @@ -43,7 +43,7 @@ AssignedVariable AssignedVariable::fromSAS(input::Parser<> &parser, const Variab //////////////////////////////////////////////////////////////////////////////////////////////////// -AssignedVariable AssignedVariable::fromSAS(input::Parser<> &parser, const Variable &variable) +AssignedVariable AssignedVariable::fromSAS(parsebase::Parser<> &parser, const Variable &variable) { AssignedVariable assignedVariable; diff --git a/src/plasp/sas/AxiomRule.cpp b/src/plasp/sas/AxiomRule.cpp index 1f508e8..3a3a315 100644 --- a/src/plasp/sas/AxiomRule.cpp +++ b/src/plasp/sas/AxiomRule.cpp @@ -23,7 +23,7 @@ AxiomRule::AxiomRule(AxiomRule::Conditions conditions, AxiomRule::Condition post //////////////////////////////////////////////////////////////////////////////////////////////////// -AxiomRule AxiomRule::fromSAS(input::Parser<> &parser, const Variables &variables) +AxiomRule AxiomRule::fromSAS(parsebase::Parser<> &parser, const Variables &variables) { parser.expect("begin_rule"); diff --git a/src/plasp/sas/Description.cpp b/src/plasp/sas/Description.cpp index 5315c53..aa4e144 100644 --- a/src/plasp/sas/Description.cpp +++ b/src/plasp/sas/Description.cpp @@ -5,11 +5,10 @@ #include #include -#include - -#include #include +#include + namespace plasp { namespace sas @@ -28,7 +27,7 @@ Description::Description() //////////////////////////////////////////////////////////////////////////////////////////////////// -Description Description::fromParser(input::Parser<> &&parser) +Description Description::fromParser(parsebase::Parser<> &&parser) { Description description; description.parseContent(parser); @@ -40,7 +39,7 @@ Description Description::fromParser(input::Parser<> &&parser) Description Description::fromStream(std::istream &istream) { - input::Parser<> parser; + parsebase::Parser<> parser; parser.read("std::cin", istream); Description description; @@ -51,12 +50,12 @@ Description Description::fromStream(std::istream &istream) //////////////////////////////////////////////////////////////////////////////////////////////////// -Description Description::fromFile(const boost::filesystem::path &path) +Description Description::fromFile(const std::experimental::filesystem::path &path) { - if (!boost::filesystem::is_regular_file(path)) + if (!std::experimental::filesystem::is_regular_file(path)) throw std::runtime_error("File does not exist: “" + path.string() + "”"); - input::Parser<> parser; + parsebase::Parser<> parser; parser.read(path); Description description; @@ -160,7 +159,7 @@ bool Description::hasRequirements() const //////////////////////////////////////////////////////////////////////////////////////////////////// -void Description::parseContent(input::Parser<> &parser) +void Description::parseContent(parsebase::Parser<> &parser) { parseVersionSection(parser); parseMetricSection(parser); @@ -174,26 +173,26 @@ void Description::parseContent(input::Parser<> &parser) parser.skipWhiteSpace(); if (!parser.atEnd()) - throw input::ParserException(parser.location(), "expected end of SAS description (perhaps, input contains two SAS descriptions?)"); + throw parsebase::ParserException(parser.location(), "expected end of SAS description (perhaps, input contains two SAS descriptions?)"); } //////////////////////////////////////////////////////////////////////////////////////////////////// -void Description::parseVersionSection(input::Parser<> &parser) const +void Description::parseVersionSection(parsebase::Parser<> &parser) const { parser.expect("begin_version"); const auto formatVersion = parser.parse(); if (formatVersion != 3) - throw input::ParserException(parser.location(), "unsupported SAS format version (" + std::to_string(formatVersion) + ")"); + throw parsebase::ParserException(parser.location(), "unsupported SAS format version (" + std::to_string(formatVersion) + ")"); parser.expect("end_version"); } //////////////////////////////////////////////////////////////////////////////////////////////////// -void Description::parseMetricSection(input::Parser<> &parser) +void Description::parseMetricSection(parsebase::Parser<> &parser) { parser.expect("begin_metric"); @@ -204,7 +203,7 @@ void Description::parseMetricSection(input::Parser<> &parser) //////////////////////////////////////////////////////////////////////////////////////////////////// -void Description::parseVariablesSection(input::Parser<> &parser) +void Description::parseVariablesSection(parsebase::Parser<> &parser) { const auto numberOfVariables = parser.parse(); m_variables.reserve(numberOfVariables); @@ -215,7 +214,7 @@ void Description::parseVariablesSection(input::Parser<> &parser) //////////////////////////////////////////////////////////////////////////////////////////////////// -void Description::parseMutexSection(input::Parser<> &parser) +void Description::parseMutexSection(parsebase::Parser<> &parser) { const auto numberOfMutexGroups = parser.parse(); m_mutexGroups.reserve(numberOfMutexGroups); @@ -226,21 +225,21 @@ void Description::parseMutexSection(input::Parser<> &parser) //////////////////////////////////////////////////////////////////////////////////////////////////// -void Description::parseInitialStateSection(input::Parser<> &parser) +void Description::parseInitialStateSection(parsebase::Parser<> &parser) { m_initialState = std::make_unique(InitialState::fromSAS(parser, m_variables)); } //////////////////////////////////////////////////////////////////////////////////////////////////// -void Description::parseGoalSection(input::Parser<> &parser) +void Description::parseGoalSection(parsebase::Parser<> &parser) { m_goal = std::make_unique(Goal::fromSAS(parser, m_variables)); } //////////////////////////////////////////////////////////////////////////////////////////////////// -void Description::parseOperatorSection(input::Parser<> &parser) +void Description::parseOperatorSection(parsebase::Parser<> &parser) { const auto numberOfOperators = parser.parse(); m_operators.reserve(numberOfOperators); @@ -251,7 +250,7 @@ void Description::parseOperatorSection(input::Parser<> &parser) //////////////////////////////////////////////////////////////////////////////////////////////////// -void Description::parseAxiomSection(input::Parser<> &parser) +void Description::parseAxiomSection(parsebase::Parser<> &parser) { const auto numberOfAxiomRules = parser.parse(); m_axiomRules.reserve(numberOfAxiomRules); diff --git a/src/plasp/sas/Effect.cpp b/src/plasp/sas/Effect.cpp index 0fe0e92..9192c15 100644 --- a/src/plasp/sas/Effect.cpp +++ b/src/plasp/sas/Effect.cpp @@ -23,7 +23,7 @@ Effect::Effect(Conditions conditions, Condition postcondition) //////////////////////////////////////////////////////////////////////////////////////////////////// -Effect Effect::fromSAS(input::Parser<> &parser, const Variables &variables, Conditions &preconditions) +Effect Effect::fromSAS(parsebase::Parser<> &parser, const Variables &variables, Conditions &preconditions) { Effect::Conditions conditions; diff --git a/src/plasp/sas/Goal.cpp b/src/plasp/sas/Goal.cpp index 56f0221..46c2d13 100644 --- a/src/plasp/sas/Goal.cpp +++ b/src/plasp/sas/Goal.cpp @@ -13,7 +13,7 @@ namespace sas // //////////////////////////////////////////////////////////////////////////////////////////////////// -Goal Goal::fromSAS(input::Parser<> &parser, const Variables &variables) +Goal Goal::fromSAS(parsebase::Parser<> &parser, const Variables &variables) { Goal goal; diff --git a/src/plasp/sas/InitialState.cpp b/src/plasp/sas/InitialState.cpp index 7dc46d5..5006c0c 100644 --- a/src/plasp/sas/InitialState.cpp +++ b/src/plasp/sas/InitialState.cpp @@ -11,7 +11,7 @@ namespace sas // //////////////////////////////////////////////////////////////////////////////////////////////////// -InitialState InitialState::fromSAS(input::Parser<> &parser, const Variables &variables) +InitialState InitialState::fromSAS(parsebase::Parser<> &parser, const Variables &variables) { InitialState initialState; diff --git a/src/plasp/sas/MutexGroup.cpp b/src/plasp/sas/MutexGroup.cpp index cf45bb5..c34b998 100644 --- a/src/plasp/sas/MutexGroup.cpp +++ b/src/plasp/sas/MutexGroup.cpp @@ -2,7 +2,7 @@ #include -#include +#include namespace plasp { @@ -15,7 +15,7 @@ namespace sas // //////////////////////////////////////////////////////////////////////////////////////////////////// -MutexGroup MutexGroup::fromSAS(input::Parser<> &parser, const Variables &variables) +MutexGroup MutexGroup::fromSAS(parsebase::Parser<> &parser, const Variables &variables) { MutexGroup mutexGroup; @@ -29,7 +29,7 @@ MutexGroup MutexGroup::fromSAS(input::Parser<> &parser, const Variables &variabl mutexGroup.m_facts.emplace_back(Fact::fromSAS(parser, variables)); if (mutexGroup.m_facts[j].value() == Value::None) - throw input::ParserException(parser.location(), "mutex groups must not contain values"); + throw parsebase::ParserException(parser.location(), "mutex groups must not contain values"); } parser.expect("end_mutex_group"); diff --git a/src/plasp/sas/Operator.cpp b/src/plasp/sas/Operator.cpp index 2602151..c773425 100644 --- a/src/plasp/sas/Operator.cpp +++ b/src/plasp/sas/Operator.cpp @@ -17,7 +17,7 @@ namespace sas // //////////////////////////////////////////////////////////////////////////////////////////////////// -Operator Operator::fromSAS(input::Parser<> &parser, const Variables &variables) +Operator Operator::fromSAS(parsebase::Parser<> &parser, const Variables &variables) { Operator operator_; diff --git a/src/plasp/sas/Predicate.cpp b/src/plasp/sas/Predicate.cpp index f522ef1..ffef43e 100644 --- a/src/plasp/sas/Predicate.cpp +++ b/src/plasp/sas/Predicate.cpp @@ -4,9 +4,10 @@ #include #include -#include #include +#include + namespace plasp { namespace sas @@ -18,7 +19,7 @@ namespace sas // //////////////////////////////////////////////////////////////////////////////////////////////////// -Predicate Predicate::fromSAS(input::Parser<> &parser) +Predicate Predicate::fromSAS(parsebase::Parser<> &parser) { Predicate predicate; @@ -43,7 +44,7 @@ Predicate Predicate::fromSAS(input::Parser<> &parser) } catch (const std::exception &e) { - throw input::ParserException(parser.location(), "could not parse operator predicate"); + throw parsebase::ParserException(parser.location(), "could not parse operator predicate"); } return predicate; diff --git a/src/plasp/sas/TranslatorASP.cpp b/src/plasp/sas/TranslatorASP.cpp index f185a3b..c152f12 100644 --- a/src/plasp/sas/TranslatorASP.cpp +++ b/src/plasp/sas/TranslatorASP.cpp @@ -1,5 +1,7 @@ #include +#include + #include namespace plasp diff --git a/src/plasp/sas/Value.cpp b/src/plasp/sas/Value.cpp index 322cac4..2ac6d58 100644 --- a/src/plasp/sas/Value.cpp +++ b/src/plasp/sas/Value.cpp @@ -2,10 +2,11 @@ #include -#include #include #include +#include + namespace plasp { namespace sas @@ -54,7 +55,7 @@ Value Value::negated() const //////////////////////////////////////////////////////////////////////////////////////////////////// -Value Value::fromSAS(input::Parser<> &parser) +Value Value::fromSAS(parsebase::Parser<> &parser) { const auto sasSign = parser.parse(); @@ -74,7 +75,7 @@ Value Value::fromSAS(input::Parser<> &parser) else if (sasSign == "NegatedAtom") value.m_sign = Value::Sign::Negative; else - throw input::ParserException(parser.location(), "invalid value sign “" + sasSign + "”"); + throw parsebase::ParserException(parser.location(), "invalid value sign “" + sasSign + "”"); try { @@ -90,7 +91,7 @@ Value Value::fromSAS(input::Parser<> &parser) } catch (const std::exception &e) { - throw input::ParserException(parser.location(), std::string("could not parse variable value (") + e.what() + ")"); + throw parsebase::ParserException(parser.location(), std::string("could not parse variable value (") + e.what() + ")"); } return value; @@ -98,7 +99,7 @@ Value Value::fromSAS(input::Parser<> &parser) //////////////////////////////////////////////////////////////////////////////////////////////////// -const Value &Value::referenceFromSAS(input::Parser<> &parser, const Variable &variable) +const Value &Value::referenceFromSAS(parsebase::Parser<> &parser, const Variable &variable) { const auto valueID = parser.parse(); @@ -106,7 +107,7 @@ const Value &Value::referenceFromSAS(input::Parser<> &parser, const Variable &va return Value::Any; if (valueID < 0 || static_cast(valueID) >= variable.values().size()) - throw input::ParserException(parser.location(), "value index out of range (variable " + variable.name() + ", index " + std::to_string(valueID) + ")"); + throw parsebase::ParserException(parser.location(), "value index out of range (variable " + variable.name() + ", index " + std::to_string(valueID) + ")"); return variable.values()[valueID]; } diff --git a/src/plasp/sas/Variable.cpp b/src/plasp/sas/Variable.cpp index 59071cc..d81dea1 100644 --- a/src/plasp/sas/Variable.cpp +++ b/src/plasp/sas/Variable.cpp @@ -2,9 +2,10 @@ #include -#include #include +#include + namespace plasp { namespace sas @@ -23,7 +24,7 @@ Variable::Variable() //////////////////////////////////////////////////////////////////////////////////////////////////// -Variable Variable::fromSAS(input::Parser<> &parser) +Variable Variable::fromSAS(parsebase::Parser<> &parser) { Variable variable; @@ -42,7 +43,7 @@ Variable Variable::fromSAS(input::Parser<> &parser) // values are only allowed at the end if (j < numberOfValues - 1 && variable.m_values[j] == Value::None) - throw input::ParserException(parser.location(), " value must be the last value of a variable"); + throw parsebase::ParserException(parser.location(), " value must be the last value of a variable"); } parser.expect("end_variable"); @@ -60,12 +61,12 @@ void Variable::printNameAsASPPredicate(output::ColorStream &stream) const //////////////////////////////////////////////////////////////////////////////////////////////////// -const Variable &Variable::referenceFromSAS(input::Parser<> &parser, const Variables &variables) +const Variable &Variable::referenceFromSAS(parsebase::Parser<> &parser, const Variables &variables) { const auto variableID = parser.parse(); if (variableID >= variables.size()) - throw input::ParserException(parser.location(), "variable index out of range (index " + std::to_string(variableID) + ")"); + throw parsebase::ParserException(parser.location(), "variable index out of range (index " + std::to_string(variableID) + ")"); return variables[variableID]; } diff --git a/src/plasp/sas/VariableTransition.cpp b/src/plasp/sas/VariableTransition.cpp index 4f6ad26..8d07374 100644 --- a/src/plasp/sas/VariableTransition.cpp +++ b/src/plasp/sas/VariableTransition.cpp @@ -24,7 +24,7 @@ VariableTransition::VariableTransition() //////////////////////////////////////////////////////////////////////////////////////////////////// -VariableTransition VariableTransition::fromSAS(input::Parser<> &parser, const Variables &variables) +VariableTransition VariableTransition::fromSAS(parsebase::Parser<> &parser, const Variables &variables) { VariableTransition variableTransition; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index df36400..6c5f7a3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -6,6 +6,7 @@ set(includes ${Boost_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/lib/catch/single_include + ${PROJECT_SOURCE_DIR}/lib/parsebase/include ) set(libraries diff --git a/tests/TestPDDLParser.cpp b/tests/TestPDDLParser.cpp index 253cb19..2baf5ea 100644 --- a/tests/TestPDDLParser.cpp +++ b/tests/TestPDDLParser.cpp @@ -373,7 +373,7 @@ TEST_CASE("[PDDL parser] Missing or unmatching domain descriptions are detected" } SECTION("") { - CHECK_THROWS_AS(Description::fromFiles({"data/blocksworld-problem.pddl", "data/storage-domain.pddl"}, context), plasp::input::ParserException); + CHECK_THROWS_AS(Description::fromFiles({"data/blocksworld-problem.pddl", "data/storage-domain.pddl"}, context), parsebase::ParserException); } }