From 163063879b3d5f452b81f119e7dbd1628b784fe2 Mon Sep 17 00:00:00 2001 From: Dominik Drexler Date: Sat, 21 Oct 2023 14:36:31 +0200 Subject: [PATCH] removed additional parsing context, moved error handler only to the root of a rule --- api/python/src/dlplan/policy/__init__.pyi | 1 + examples/policy/policy.cpp | 22 +-- examples/policy/policy.py | 35 ++-- include/dlplan/common/parsers/config.hpp | 20 +- .../dlplan/common/parsers/error_handler.hpp | 36 +--- .../elements/stage_1/error_handler.hpp | 70 +++++++ .../parsers/policy/stage_1/error_handler.hpp | 22 +++ src/CMakeLists.txt | 2 +- src/core/element_factory.cpp | 38 ++-- src/core/parsers/elements/stage_1/parser.hpp | 36 ++++ .../parsers/elements/stage_1/parser_def.hpp | 183 ++++++++++++------ .../stage_1/parser_instantiations.cpp | 11 ++ src/core/parsers/elements/stage_2/parser.cpp | 9 +- src/policy/parsers/policy/stage_1/parser.hpp | 24 +++ .../parsers/policy/stage_1/parser_def.hpp | 88 +++++---- .../policy/stage_1/parser_instantiations.cpp | 3 + src/policy/parsers/policy/stage_2/parser.cpp | 4 +- src/policy/policy_factory.cpp | 11 +- 18 files changed, 404 insertions(+), 211 deletions(-) create mode 100644 include/dlplan/core/parsers/elements/stage_1/error_handler.hpp create mode 100644 include/dlplan/policy/parsers/policy/stage_1/error_handler.hpp create mode 100644 src/core/parsers/elements/stage_1/parser.hpp create mode 100644 src/policy/parsers/policy/stage_1/parser.hpp diff --git a/api/python/src/dlplan/policy/__init__.pyi b/api/python/src/dlplan/policy/__init__.pyi index 405cded9..778deb41 100644 --- a/api/python/src/dlplan/policy/__init__.pyi +++ b/api/python/src/dlplan/policy/__init__.pyi @@ -79,6 +79,7 @@ class PolicyFactory: def make_bot_effect(self, numerical: Numerical) -> BaseEffect: ... def make_rule(self, conditions: MutableSet[BaseCondition], effects: MutableSet[BaseEffect]) -> Rule: ... def make_policy(self, rules: MutableSet[Rule]) -> Policy: ... + def parse_policy(self, description: str, filename: str = "") -> Policy: ... class PolicyMinimizer: diff --git a/examples/policy/policy.cpp b/examples/policy/policy.cpp index dae7763a..7c10f02e 100644 --- a/examples/policy/policy.cpp +++ b/examples/policy/policy.cpp @@ -85,8 +85,9 @@ static std::string read_from_file(const std::string& filename) { int main() { auto vocabulary = construct_vocabulary_info(); auto instance = construct_instance_info(vocabulary); - auto element_factory = std::make_shared(vocabulary); + + std::cout << "Constructing policy:" << std::endl; // boolean_1 represents whether the hand is empty or not auto boolean_1 = element_factory->parse_boolean("b_nullary(arm-empty)"); // numerical_1 representes the number of blocks on top of another block @@ -122,22 +123,17 @@ int main() { assert(!policy->evaluate(state_2, state_0, caches)); assert(!policy->evaluate(state_2, state_1, caches)); - std::cout << "Write policy:" << std::endl; std::cout << policy->compute_repr() << std::endl << std::endl; std::cout << policy->str() << std::endl << std::endl; - write_to_file("policy.txt", policy->str()); - - std::string pol = - "(:policy\n" - "(:booleans )\n" - "(:numericals (n0 \"n_count(c_primitive(holding,0))\") (n1 \"n_count(c_equal(r_primitive(at,0,1),r_primitive(at_g,0,1)))\") (n2 \"n_count(r_and(r_primitive(at,0,1),r_primitive(at_g,0,1)))\"))\n" - "(:rule (:conditions (:c_n_gt n0) (:c_n_gt n1) (:c_n_gt n2)) (:effects (:e_n_inc n0) (:e_n_bot n1) (:e_n_bot n2)))\n" + std::cout << "Parsing policy:" << std::endl; + std::string policy_str = + "(:policy" + "(:booleans (b0 \"b_nullary(arm-empty)\"))" + "(:numericals (n0 \"n_count(r_primitive(on,0,1))\"))" + "(:rule (:conditions (:c_b_pos b0) (:c_n_gt n0)) (:effects (:e_b_bot b42) (:e_n_dec n0)))" ")"; - // auto policy_in = policy_factory.parse_policy(read_from_file("policy.txt")); - auto policy_in = policy_factory.parse_policy(pol); - - std::cout << "Read policy:" << std::endl; + auto policy_in = policy_factory.parse_policy(policy_str); std::cout << policy_in->compute_repr() << std::endl << std::endl; std::cout << policy_in->str() << std::endl << std::endl; diff --git a/examples/policy/policy.py b/examples/policy/policy.py index 4783f960..5ec71d4f 100755 --- a/examples/policy/policy.py +++ b/examples/policy/policy.py @@ -6,7 +6,7 @@ from dlplan.core import VocabularyInfo, InstanceInfo, State, SyntacticElementFactory, \ DenotationsCaches -from dlplan.policy import PolicyBuilder, PolicyWriter, PolicyReader +from dlplan.policy import PolicyFactory def construct_vocabulary_info(): @@ -51,23 +51,24 @@ def construct_instance_info(vocabulary): def main(): vocabulary = construct_vocabulary_info() instance = construct_instance_info(vocabulary) - element_factory = SyntacticElementFactory(vocabulary) + + print("Constructing policy:") # boolean_1 represents whether the hand is empty or not boolean_1 = element_factory.parse_boolean("b_nullary(arm-empty)") # numerical_1 representes the number of blocks on top of another block numerical_1 = element_factory.parse_numerical("n_count(r_primitive(on,0,1))") - policy_builder = PolicyBuilder(element_factory) - b_pos_condition_0 = policy_builder.make_pos_condition(boolean_1) - b_bot_effect_0 = policy_builder.make_bot_effect(boolean_1) - n_gt_condition_0 = policy_builder.make_gt_condition(numerical_1) - n_dec_effect_0 = policy_builder.make_dec_effect(numerical_1) - rule_1 = policy_builder.make_rule( + policy_factory = PolicyFactory(element_factory) + b_pos_condition_0 = policy_factory.make_pos_condition(boolean_1) + b_bot_effect_0 = policy_factory.make_bot_effect(boolean_1) + n_gt_condition_0 = policy_factory.make_gt_condition(numerical_1) + n_dec_effect_0 = policy_factory.make_dec_effect(numerical_1) + rule_1 = policy_factory.make_rule( {b_pos_condition_0, n_gt_condition_0}, {b_bot_effect_0, n_dec_effect_0} ) - policy = policy_builder.make_policy({rule_1}) + policy = policy_factory.make_policy({rule_1}) atoms = instance.get_atoms() atom_0 = atoms[0] @@ -84,25 +85,25 @@ def main(): caches = DenotationsCaches() assert policy.evaluate(state_0, state_2, caches) - assert not policy.evaluate(state_1, state_2, caches) + assert policy.evaluate(state_1, state_2, caches) assert not policy.evaluate(state_2, state_0, caches) assert not policy.evaluate(state_2, state_1, caches) - print("Write policy:") print(repr(policy)) print(str(policy)) print() - with open("policy.txt", "w", encoding="iso8859-1") as file: - file.write(PolicyWriter().write(policy)) - print("Read policy:") - with open("policy.txt", "r", encoding="iso8859-1") as file: - policy_in = PolicyReader().read("\n".join(file.readlines()), policy_builder, element_factory) + print("Parsing policy:") + policy_str = "(:policy" \ + "(:booleans (b0 \"b_nullary(arm-empty)\"))" \ + "(:numericals (n0 \"n_count(r_primitive(on,0,1))\"))" \ + "(:rule (:conditions (:c_b_pos b0) (:c_n_gt n0)) (:effects (:e_b_bot b42) (:e_n_dec n0)))" \ + ")" + policy_in = policy_factory.parse_policy(policy_str) print(repr(policy_in)) print(str(policy_in)) print() - if __name__ == "__main__": main() diff --git a/include/dlplan/common/parsers/config.hpp b/include/dlplan/common/parsers/config.hpp index e8714df2..0efc7bcb 100644 --- a/include/dlplan/common/parsers/config.hpp +++ b/include/dlplan/common/parsers/config.hpp @@ -8,7 +8,6 @@ /// @brief Defines types of our parsers. /// The configuration is relevant when reusing the parsers instantiated by the library. -/// The additional parsing context can be modified if additional information is needed. namespace dlplan::common::parsers { namespace x3 = boost::spirit::x3; @@ -26,29 +25,16 @@ namespace dlplan::common::parsers typedef error_handler error_handler_type; - /* In case we need to provide context in the future. */ - struct parsing_context_tag; - - struct parsing_context_type { - bool error_reported = false; - }; - /* The phrase parse context */ typedef - x3::phrase_parse_context::type - phrase_context_type; + x3::phrase_parse_context::type phrase_context_type; - - /* Combined error handler, parsing, and phrase parse Context */ + /* Combined error handler and phrase parse Context */ typedef x3::context< error_handler_tag, std::reference_wrapper, - x3::context< - parsing_context_tag, - std::reference_wrapper, - phrase_context_type>> + phrase_context_type> context_type; - } #endif diff --git a/include/dlplan/common/parsers/error_handler.hpp b/include/dlplan/common/parsers/error_handler.hpp index 5ed4c805..eccaa543 100644 --- a/include/dlplan/common/parsers/error_handler.hpp +++ b/include/dlplan/common/parsers/error_handler.hpp @@ -1,5 +1,5 @@ -#ifndef DLPLAN_INCLUDE_DLPLAN_CORE_PARSERS_ELEMENTS_COMMON_ERROR_HANDLER_HPP_ -#define DLPLAN_INCLUDE_DLPLAN_CORE_PARSERS_ELEMENTS_COMMON_ERROR_HANDLER_HPP_ +#ifndef DLPLAN_INCLUDE_DLPLAN_CORE_COMMON_PARSERS_ERROR_HANDLER_HPP_ +#define DLPLAN_INCLUDE_DLPLAN_CORE_COMMON_PARSERS_ERROR_HANDLER_HPP_ #include #include @@ -12,40 +12,24 @@ namespace dlplan::common::parsers namespace x3 = boost::spirit::x3; //////////////////////////////////////////////////////////////////////////// - // Our error handler + // Our error handler //////////////////////////////////////////////////////////////////////////// - /// @brief The error_handler_base only print error message for the first occurence - /// The expectation failures of the parent grammar rules are not printed. - /// We do not throw an exception because, as a general rule, - /// the caller should have the option to recover from a failed parse. struct error_handler_base { - std::string error_message; + std::unordered_map id_map; - // Spirit calls the default constructor - error_handler_base() : error_message("") { } - - error_handler_base(const std::string& message) : error_message(message) { } - - virtual ~error_handler_base() { } + error_handler_base() { } template x3::error_handler_result on_error( Iterator& /*first*/, Iterator const& /*last*/ , Exception const& x, Context const& context) { { - auto& parsing_context = x3::get(context).get(); - if (parsing_context.error_reported) { - // We only print the first occurence of an error - return x3::error_handler_result::fail; - } - parsing_context.error_reported = true; - std::string which = x.which(); - // Use our message if defined - if (error_message != "") { - which = error_message; + auto iter = id_map.find(which); + if (iter != id_map.end()) { + which = iter->second; } std::string message = "Error! Expecting: " + which + " here:"; @@ -56,10 +40,6 @@ namespace dlplan::common::parsers } } }; - - - - } #endif diff --git a/include/dlplan/core/parsers/elements/stage_1/error_handler.hpp b/include/dlplan/core/parsers/elements/stage_1/error_handler.hpp new file mode 100644 index 00000000..c937264c --- /dev/null +++ b/include/dlplan/core/parsers/elements/stage_1/error_handler.hpp @@ -0,0 +1,70 @@ +#ifndef DLPLAN_INCLUDE_DLPLAN_CORE_PARSERS_ELEMENTS_STAGE_1_ERROR_HANDLER_HPP_ +#define DLPLAN_INCLUDE_DLPLAN_CORE_PARSERS_ELEMENTS_STAGE_1_ERROR_HANDLER_HPP_ + +#include +#include + +#include "include/dlplan/common/parsers/error_handler.hpp" + + +namespace dlplan::core::parsers::elements::stage_1 +{ + namespace x3 = boost::spirit::x3; + + struct error_handler_core : dlplan::common::parsers::error_handler_base { + error_handler_core() : dlplan::common::parsers::error_handler_base() { + // TODO: add more precise error messages. + id_map["name"] = "name"; + id_map["constant"] = "constant"; + id_map["predicate"] = "predicate"; + id_map["position"] = "position"; + id_map["boolean_inner"] = "boolean_inner"; + id_map["concept_inner"] = "concept_inner"; + id_map["numerical_inner"] = "numerical_inner"; + id_map["role_inner"] = "role_inner"; + id_map["element_inner"] = "element_inner"; + id_map["concept_or_role_inner"] = "concept_or_role_inner"; + id_map["concept_or_role"] = "concept_or_role"; + id_map["empty_boolean"] = "empty_boolean"; + id_map["inclusion_boolean"] = "inclusion_boolean"; + id_map["nullary_boolean"] = "nullary_boolean"; + id_map["all_concept"] = "all_concept"; + id_map["and_concept"] = "and_concept"; + id_map["bot_concept"] = "bot_concept"; + id_map["diff_concept"] = "diff_concept"; + id_map["equal_concept"] = "equal_concept"; + id_map["not_concept"] = "not_concept"; + id_map["one_of_concept"] = "one_of_concept"; + id_map["or_concept"] = "or_concept"; + id_map["primitive_concept"] = "primitive_concept"; + id_map["projection_concept"] = "projection_concept"; + id_map["some_concept"] = "some_concept"; + id_map["subset_concept"] = "subset_concept"; + id_map["top_concept"] = "top_concept"; + id_map["concept_distance_numerical"] = "concept_distance_numerical"; + id_map["count_numerical"] = "count_numerical"; + id_map["role_distance_numerical"] = "role_distance_numerical"; + id_map["sum_concept_distance_numerical"] = "sum_concept_distance_numerical"; + id_map["sum_role_distance_numerical"] = "sum_role_distance_numerical"; + id_map["and_role"] = "and_role"; + id_map["compose_role"] = "compose_role"; + id_map["diff_role"] = "diff_role"; + id_map["identity_role"] = "identity_role"; + id_map["inverse_role"] = "inverse_role"; + id_map["not_role"] = "not_role"; + id_map["or_role"] = "or_role"; + id_map["primitive_role"] = "primitive_role"; + id_map["restrict_role"] = "restrict_role"; + id_map["top_role"] = "top_role"; + id_map["transitive_closure_role"] = "transitive_closure_role"; + id_map["transitive_reflexive_closure_role"] = "transitive_reflexive_closure_role"; + id_map["boolean"] = "boolean"; + id_map["numerical"] = "numerical"; + id_map["concept"] = "concept"; + id_map["role"] = "role"; + id_map["element"] = "element"; + } + }; +} + +#endif diff --git a/include/dlplan/policy/parsers/policy/stage_1/error_handler.hpp b/include/dlplan/policy/parsers/policy/stage_1/error_handler.hpp new file mode 100644 index 00000000..0e844011 --- /dev/null +++ b/include/dlplan/policy/parsers/policy/stage_1/error_handler.hpp @@ -0,0 +1,22 @@ +#ifndef DLPLAN_INCLUDE_DLPLAN_POLICY_PARSERS_POLICY_STAGE_1_ERROR_HANDLER_HPP_ +#define DLPLAN_INCLUDE_DLPLAN_POLICY_PARSERS_POLICY_STAGE_1_ERROR_HANDLER_HPP_ + +#include +#include + +#include "include/dlplan/core/parsers/elements/stage_1/error_handler.hpp" + + +namespace dlplan::policy::parsers::policy::stage_1 +{ + namespace x3 = boost::spirit::x3; + + struct error_handler_policy : dlplan::core::parsers::elements::stage_1::error_handler_core { + error_handler_policy() : dlplan::core::parsers::elements::stage_1::error_handler_core() { + // TODO: add more precise error messages. + + } + }; +} + +#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0de0adb3..8e4b2495 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,4 +4,4 @@ add_subdirectory(novelty) add_subdirectory(policy) add_subdirectory(serialization) add_subdirectory(state_space) -# add_subdirectory(weisfeiler_lehman) +#add_subdirectory(weisfeiler_lehman) diff --git a/src/core/element_factory.cpp b/src/core/element_factory.cpp index d5d88557..18671e88 100644 --- a/src/core/element_factory.cpp +++ b/src/core/element_factory.cpp @@ -42,7 +42,7 @@ #include "elements/roles/transitive_reflexive_closure.h" #include "include/dlplan/common/parsers/config.hpp" -#include "include/dlplan/core/parsers/elements/stage_1/parser.hpp" +#include "parsers/elements/stage_1/parser.hpp" #include "include/dlplan/core/parsers/elements/stage_2/parser.hpp" #include "include/dlplan/common/parsers/utility.hpp" @@ -75,14 +75,11 @@ std::shared_ptr SyntacticElementFactoryImpl::parse_concept(Syntac // Our error handler error_handler_type error_handler(iter, end, std::cerr, filename); - parsing_context_type parsing_context; auto const parser = // we pass our error handler to the parser so we can access // it later on in our on_error and on_sucess handlers - with(std::ref(parsing_context)) [ - with(std::ref(error_handler)) [ - dlplan::core::parsers::elements::stage_1::concept() - ] + with(std::ref(error_handler)) [ + dlplan::core::parsers::elements::stage_1::concept_root() ]; // Our AST @@ -93,7 +90,7 @@ std::shared_ptr SyntacticElementFactoryImpl::parse_concept(Syntac bool success = phrase_parse(iter, end, parser, space, ast); if (!success) { throw std::runtime_error("Failed parse."); - } + } if (iter != end) { throw std::runtime_error("Failed parse. Did not consume whole input."); } @@ -119,14 +116,11 @@ std::shared_ptr SyntacticElementFactoryImpl::parse_role(SyntacticEle // Our error handler error_handler_type error_handler(iter, end, std::cerr, filename); - parsing_context_type parsing_context; auto const parser = // we pass our error handler to the parser so we can access // it later on in our on_error and on_sucess handlers - with(std::ref(parsing_context)) [ - with(std::ref(error_handler)) [ - dlplan::core::parsers::elements::stage_1::role() - ] + with(std::ref(error_handler)) [ + dlplan::core::parsers::elements::stage_1::role_root() ]; // Our AST @@ -137,7 +131,7 @@ std::shared_ptr SyntacticElementFactoryImpl::parse_role(SyntacticEle bool success = phrase_parse(iter, end, parser, space, ast); if (!success) { throw std::runtime_error("Failed parse."); - } + } if (iter != end) { throw std::runtime_error("Failed parse. Did not consume whole input."); } @@ -163,14 +157,11 @@ std::shared_ptr SyntacticElementFactoryImpl::parse_boolean(Syntac // Our error handler error_handler_type error_handler(iter, end, std::cerr, filename); - parsing_context_type parsing_context; auto const parser = // we pass our error handler to the parser so we can access // it later on in our on_error and on_sucess handlers - with(std::ref(parsing_context)) [ - with(std::ref(error_handler)) [ - dlplan::core::parsers::elements::stage_1::boolean() - ] + with(std::ref(error_handler)) [ + dlplan::core::parsers::elements::stage_1::boolean_root() ]; // Our AST @@ -181,7 +172,7 @@ std::shared_ptr SyntacticElementFactoryImpl::parse_boolean(Syntac bool success = phrase_parse(iter, end, parser, space, ast); if (!success) { throw std::runtime_error("Failed parse."); - } + } if (iter != end) { throw std::runtime_error("Failed parse. Did not consume whole input."); } @@ -207,14 +198,11 @@ std::shared_ptr SyntacticElementFactoryImpl::parse_numerical(Sy // Our error handler error_handler_type error_handler(iter, end, std::cerr, filename); - parsing_context_type parsing_context; auto const parser = // we pass our error handler to the parser so we can access // it later on in our on_error and on_sucess handlers - with(std::ref(parsing_context)) [ - with(std::ref(error_handler)) [ - dlplan::core::parsers::elements::stage_1::numerical() - ] + with(std::ref(error_handler)) [ + dlplan::core::parsers::elements::stage_1::numerical_root() ]; // Our AST @@ -225,7 +213,7 @@ std::shared_ptr SyntacticElementFactoryImpl::parse_numerical(Sy bool success = phrase_parse(iter, end, parser, space, ast); if (!success) { throw std::runtime_error("Failed parse."); - } + } if (iter != end) { throw std::runtime_error("Failed parse. Did not consume whole input."); } diff --git a/src/core/parsers/elements/stage_1/parser.hpp b/src/core/parsers/elements/stage_1/parser.hpp new file mode 100644 index 00000000..238c5ac5 --- /dev/null +++ b/src/core/parsers/elements/stage_1/parser.hpp @@ -0,0 +1,36 @@ +#ifndef DLPLAN_SRC_CORE_PARSERS_ELEMENTS_STAGE_1_PARSER_API_HPP_ +#define DLPLAN_SRC_CORE_PARSERS_ELEMENTS_STAGE_1_PARSER_API_HPP_ + +#include + +#include "include/dlplan/core/parsers/elements/stage_1/ast.hpp" + + +namespace dlplan::core::parsers::elements::stage_1 +{ + namespace x3 = boost::spirit::x3; + + namespace parser { + struct ElementRootClass; + struct BooleanRootClass; + struct NumericalRootClass; + struct ConceptRootClass; + struct RoleRootClass; + + typedef x3::rule element_root_type; + typedef x3::rule boolean_root_type; + typedef x3::rule numerical_root_type; + typedef x3::rule concept_root_type; + typedef x3::rule role_root_type; + + BOOST_SPIRIT_DECLARE(element_root_type, boolean_root_type, numerical_root_type, concept_root_type, role_root_type) + } + + parser::element_root_type const& element_root(); + parser::boolean_root_type const& boolean_root(); + parser::numerical_root_type const& numerical_root(); + parser::concept_root_type const& concept_root(); + parser::role_root_type const& role_root(); +} + +#endif \ No newline at end of file diff --git a/src/core/parsers/elements/stage_1/parser_def.hpp b/src/core/parsers/elements/stage_1/parser_def.hpp index a170d733..838ac750 100644 --- a/src/core/parsers/elements/stage_1/parser_def.hpp +++ b/src/core/parsers/elements/stage_1/parser_def.hpp @@ -4,11 +4,12 @@ #include #include -#include "include/dlplan/common/parsers/error_handler.hpp" +#include "include/dlplan/core/parsers/elements/stage_1/error_handler.hpp" #include "include/dlplan/core/parsers/elements/stage_1/ast.hpp" #include "include/dlplan/core/parsers/elements/stage_1/parser.hpp" #include "ast_adapted.hpp" +#include "parser.hpp" namespace dlplan::core::parsers::elements::stage_1::parser @@ -26,7 +27,6 @@ namespace dlplan::core::parsers::elements::stage_1::parser using ascii::char_; using ascii::string; - using error_handler_base = dlplan::common::parsers::error_handler_base; /////////////////////////////////////////////////////////////////////////// // Rule IDs @@ -81,6 +81,7 @@ namespace dlplan::core::parsers::elements::stage_1::parser // Rules /////////////////////////////////////////////////////////////////////////// + /* Private rules with annotation */ x3::rule const name = "name"; @@ -213,6 +214,23 @@ namespace dlplan::core::parsers::elements::stage_1::parser x3::rule const transitive_reflexive_closure_role = "transitive_reflexive_closure_role"; + /* Privates rules with annotation and error handling */ + boolean_root_type const + boolean_root = "boolean"; + + numerical_root_type const + numerical_root = "numerical"; + + concept_root_type const + concept_root = "concept"; + + role_root_type const + role_root = "role"; + + element_root_type const + element_root = "element"; + + /* Public rules with annotation */ boolean_type const boolean = "boolean"; @@ -310,35 +328,39 @@ namespace dlplan::core::parsers::elements::stage_1::parser const auto transitive_reflexive_closure_role_def = lit("r_transitive_reflexive_closure") > lit('(') > role > lit(')'); const auto boolean_inner_def = empty_boolean | inclusion_boolean | nullary_boolean; - - const auto boolean_def = boolean_inner_def; + const auto boolean_def = boolean_inner; + const auto boolean_root_def = boolean_inner; // Note: non recursive comes first, i.e., primitive_concept const auto concept_inner_def = primitive_concept | all_concept | and_concept | bot_concept | diff_concept | equal_concept | not_concept | one_of_concept | or_concept | projection_concept | some_concept | subset_concept | top_concept; - - const auto concept_def = concept_inner_def; + const auto concept_def = concept_inner; + const auto concept_root_def = concept_inner; const auto numerical_inner_def = concept_distance_numerical | count_numerical | role_distance_numerical | sum_concept_distance_numerical | sum_role_distance_numerical; - const auto numerical_def = numerical_inner; + const auto numerical_root_def = numerical_inner; // Note: non recursive comes first, i.e., primitive_role const auto role_inner_def = primitive_role | and_role | compose_role | diff_role | identity_role | inverse_role | not_role | or_role | restrict_role | top_role | transitive_closure_role | transitive_reflexive_closure_role; - const auto role_def = role_inner; + const auto role_root_def = role_inner; const auto concept_or_role_inner_def = concept_inner | role_inner; - const auto concept_or_role_def = concept_or_role_inner; const auto element_inner_def = boolean_inner | concept_inner | numerical_inner | role_inner; - const auto element_def = eps > element_inner; + const auto element_root_def = eps > element_inner; BOOST_SPIRIT_DEFINE( name, constant, predicate, position, - boolean_inner, boolean, concept_inner, concept, numerical_inner, numerical, role_inner, role, element_inner, element, concept_or_role_inner, concept_or_role, + boolean_inner, boolean, boolean_root, + concept_inner, concept, concept_root, + numerical_inner, numerical, numerical_root, + role_inner, role, role_root, + element_inner, element, element_root, + concept_or_role_inner, concept_or_role, empty_boolean, inclusion_boolean, nullary_boolean, all_concept, and_concept, bot_concept, diff_concept, equal_concept, not_concept, one_of_concept, or_concept, primitive_concept, projection_concept, some_concept, subset_concept, top_concept, concept_distance_numerical, count_numerical, role_distance_numerical, sum_concept_distance_numerical, sum_role_distance_numerical, @@ -348,55 +370,66 @@ namespace dlplan::core::parsers::elements::stage_1::parser // Annotation and Error handling /////////////////////////////////////////////////////////////////////////// - struct NameClass : x3::annotate_on_success, error_handler_base {}; - struct ConstantClass : x3::annotate_on_success, error_handler_base {}; - struct PredicateClass : x3::annotate_on_success, error_handler_base {}; - struct PositionClass : x3::annotate_on_success, error_handler_base {}; - struct BooleanInnerClass : x3::annotate_on_success, error_handler_base {}; - struct BooleanClass : x3::annotate_on_success, error_handler_base {}; - struct ConceptInnerClass : x3::annotate_on_success, error_handler_base {}; - struct ConceptClass : x3::annotate_on_success, error_handler_base {}; - struct NumericalInnerClass : x3::annotate_on_success, error_handler_base {}; - struct NumericalClass : x3::annotate_on_success, error_handler_base {}; - struct RoleInnerClass : x3::annotate_on_success, error_handler_base {}; - struct RoleClass : x3::annotate_on_success, error_handler_base {}; - struct ConceptOrRoleInnerClass : x3::annotate_on_success, error_handler_base {}; - struct ConceptOrRoleClass : x3::annotate_on_success, error_handler_base {}; - struct EmptyBooleanClass : x3::annotate_on_success, error_handler_base {}; - struct InclusionBooleanClass : x3::annotate_on_success, error_handler_base {}; - struct NullaryBooleanClass : x3::annotate_on_success, error_handler_base {}; - struct AllConceptClass : x3::annotate_on_success, error_handler_base {}; - struct AndConceptClass : x3::annotate_on_success, error_handler_base {}; - struct BotConceptClass : x3::annotate_on_success, error_handler_base {}; - struct DiffConceptClass : x3::annotate_on_success, error_handler_base {}; - struct EqualConceptClass : x3::annotate_on_success, error_handler_base {}; - struct NotConceptClass : x3::annotate_on_success, error_handler_base {}; - struct OneOfConceptClass : x3::annotate_on_success, error_handler_base {}; - struct OrConceptClass : x3::annotate_on_success, error_handler_base {}; - struct PrimitiveConceptClass : x3::annotate_on_success, error_handler_base {}; - struct ProjectionConceptClass : x3::annotate_on_success, error_handler_base {}; - struct SomeConceptClass : x3::annotate_on_success, error_handler_base {}; - struct SubsetConceptClass : x3::annotate_on_success, error_handler_base {}; - struct TopConceptClass : x3::annotate_on_success, error_handler_base {}; - struct ConceptDistanceNumericalClass : x3::annotate_on_success, error_handler_base {}; - struct CountNumericalClass : x3::annotate_on_success, error_handler_base {}; - struct RoleDistanceNumericalClass : x3::annotate_on_success, error_handler_base {}; - struct SumConceptDistanceNumericalClass : x3::annotate_on_success, error_handler_base {}; - struct SumRoleDistanceNumericalClass : x3::annotate_on_success, error_handler_base {}; - struct AndRoleClass : x3::annotate_on_success, error_handler_base {}; - struct ComposeRoleClass : x3::annotate_on_success, error_handler_base {}; - struct DiffRoleClass : x3::annotate_on_success, error_handler_base {}; - struct IdentityRoleClass : x3::annotate_on_success, error_handler_base {}; - struct InverseRoleClass : x3::annotate_on_success, error_handler_base {}; - struct NotRoleClass : x3::annotate_on_success, error_handler_base {}; - struct OrRoleClass : x3::annotate_on_success, error_handler_base {}; - struct PrimitiveRoleClass : x3::annotate_on_success, error_handler_base {}; - struct RestrictRoleClass : x3::annotate_on_success, error_handler_base {}; - struct TopRoleClass : x3::annotate_on_success, error_handler_base {}; - struct TransitiveClosureRoleClass : x3::annotate_on_success, error_handler_base {}; - struct TransitiveReflexiveClosureRoleClass : x3::annotate_on_success, error_handler_base {}; - struct ElementInnerClass : x3::annotate_on_success, error_handler_base {}; - struct ElementClass : x3::annotate_on_success, error_handler_base {}; + struct NameClass : x3::annotate_on_success {}; + struct ConstantClass : x3::annotate_on_success {}; + struct PredicateClass : x3::annotate_on_success {}; + struct PositionClass : x3::annotate_on_success {}; + struct EmptyBooleanClass : x3::annotate_on_success {}; + struct InclusionBooleanClass : x3::annotate_on_success {}; + struct NullaryBooleanClass : x3::annotate_on_success {}; + struct AllConceptClass : x3::annotate_on_success {}; + struct AndConceptClass : x3::annotate_on_success {}; + struct BotConceptClass : x3::annotate_on_success {}; + struct DiffConceptClass : x3::annotate_on_success {}; + struct EqualConceptClass : x3::annotate_on_success {}; + struct NotConceptClass : x3::annotate_on_success {}; + struct OneOfConceptClass : x3::annotate_on_success {}; + struct OrConceptClass : x3::annotate_on_success {}; + struct PrimitiveConceptClass : x3::annotate_on_success {}; + struct ProjectionConceptClass : x3::annotate_on_success {}; + struct SomeConceptClass : x3::annotate_on_success {}; + struct SubsetConceptClass : x3::annotate_on_success {}; + struct TopConceptClass : x3::annotate_on_success {}; + struct ConceptDistanceNumericalClass : x3::annotate_on_success {}; + struct CountNumericalClass : x3::annotate_on_success {}; + struct RoleDistanceNumericalClass : x3::annotate_on_success {}; + struct SumConceptDistanceNumericalClass : x3::annotate_on_success {}; + struct SumRoleDistanceNumericalClass : x3::annotate_on_success {}; + struct AndRoleClass : x3::annotate_on_success {}; + struct ComposeRoleClass : x3::annotate_on_success {}; + struct DiffRoleClass : x3::annotate_on_success {}; + struct IdentityRoleClass : x3::annotate_on_success {}; + struct InverseRoleClass : x3::annotate_on_success {}; + struct NotRoleClass : x3::annotate_on_success {}; + struct OrRoleClass : x3::annotate_on_success {}; + struct PrimitiveRoleClass : x3::annotate_on_success {}; + struct RestrictRoleClass : x3::annotate_on_success {}; + struct TopRoleClass : x3::annotate_on_success {}; + struct TransitiveClosureRoleClass : x3::annotate_on_success {}; + struct TransitiveReflexiveClosureRoleClass : x3::annotate_on_success {}; + + struct BooleanInnerClass : x3::annotate_on_success {}; + struct BooleanClass : x3::annotate_on_success {}; + struct BooleanRootClass : x3::annotate_on_success, error_handler_core {}; + + struct NumericalInnerClass : x3::annotate_on_success {}; + struct NumericalClass : x3::annotate_on_success {}; + struct NumericalRootClass : x3::annotate_on_success, dlplan::common::parsers::error_handler_base {}; + + struct ConceptInnerClass : x3::annotate_on_success {}; + struct ConceptClass : x3::annotate_on_success {}; + struct ConceptRootClass : x3::annotate_on_success, error_handler_core {}; + + struct RoleInnerClass : x3::annotate_on_success {}; + struct RoleClass : x3::annotate_on_success {}; + struct RoleRootClass : x3::annotate_on_success, error_handler_core {}; + + struct ElementInnerClass : x3::annotate_on_success {}; + struct ElementClass : x3::annotate_on_success {}; + struct ElementRootClass : x3::annotate_on_success, error_handler_core {}; + + struct ConceptOrRoleInnerClass : x3::annotate_on_success {}; + struct ConceptOrRoleClass : x3::annotate_on_success {}; } namespace dlplan::core::parsers::elements::stage_1 @@ -427,4 +460,34 @@ namespace dlplan::core::parsers::elements::stage_1 } } + +namespace dlplan::core::parsers::elements::stage_1 +{ + parser::element_root_type const& element_root() + { + return parser::element_root; + } + + parser::boolean_root_type const& boolean_root() + { + return parser::boolean_root; + } + + parser::numerical_root_type const& numerical_root() + { + return parser::numerical_root; + } + + parser::concept_root_type const& concept_root() + { + return parser::concept_root; + } + + parser::role_root_type const& role_root() + { + return parser::role_root; + } +} + + #endif \ No newline at end of file diff --git a/src/core/parsers/elements/stage_1/parser_instantiations.cpp b/src/core/parsers/elements/stage_1/parser_instantiations.cpp index 8936ea4d..5fb9f97d 100644 --- a/src/core/parsers/elements/stage_1/parser_instantiations.cpp +++ b/src/core/parsers/elements/stage_1/parser_instantiations.cpp @@ -6,20 +6,31 @@ namespace dlplan::core::parsers::elements::stage_1::parser { using iterator_type = dlplan::common::parsers::iterator_type; + using phrase_context_type = dlplan::common::parsers::phrase_context_type; using context_type = dlplan::common::parsers::context_type; BOOST_SPIRIT_INSTANTIATE( element_type, iterator_type, context_type) + BOOST_SPIRIT_INSTANTIATE( + element_root_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE( boolean_type, iterator_type, context_type) + BOOST_SPIRIT_INSTANTIATE( + boolean_root_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE( numerical_type, iterator_type, context_type) + BOOST_SPIRIT_INSTANTIATE( + numerical_root_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE( concept_type, iterator_type, context_type) + BOOST_SPIRIT_INSTANTIATE( + concept_root_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE( role_type, iterator_type, context_type) + BOOST_SPIRIT_INSTANTIATE( + role_root_type, iterator_type, context_type) } diff --git a/src/core/parsers/elements/stage_2/parser.cpp b/src/core/parsers/elements/stage_2/parser.cpp index e05c08ed..49cb53d3 100644 --- a/src/core/parsers/elements/stage_2/parser.cpp +++ b/src/core/parsers/elements/stage_2/parser.cpp @@ -22,6 +22,7 @@ parse(const stage_1::ast::Constant& node, const error_handler_type& error_handle auto it = constants_mapping.find(name); if (it == constants_mapping.end()) { error_handler(node, "undefined constant"); + throw std::runtime_error("Failed parse."); } return context.get_vocabulary_info()->get_constant(name); } @@ -33,6 +34,7 @@ parse(const stage_1::ast::Predicate& node, const error_handler_type& error_handl auto it = predicates_mapping.find(name); if (it == predicates_mapping.end()) { error_handler(node, "undefined predicate"); + throw std::runtime_error("Failed parse."); } return context.get_vocabulary_info()->get_predicate(name); } @@ -88,7 +90,7 @@ parse(const stage_1::ast::EmptyBoolean& node, const error_handler_type& error_ha boost::apply_visitor(role_visitor, concept_or_role); if (role_visitor.result != nullptr) return context.make_empty_boolean(role_visitor.result); error_handler(node, "expected two concepts or two roles"); - throw std::runtime_error("Failed parse"); + throw std::runtime_error("Failed parse."); } static std::shared_ptr @@ -110,8 +112,7 @@ parse(const stage_1::ast::InclusionBoolean& node, const error_handler_type& erro return context.make_inclusion_boolean(role_visitor_left.result, role_visitor_right.result); } error_handler(node, "expected two concepts or two roles"); - throw std::runtime_error("Failed parse"); - + throw std::runtime_error("Failed parse."); } static std::shared_ptr @@ -222,7 +223,7 @@ parse(const stage_1::ast::CountNumerical& node, const error_handler_type& error_ boost::apply_visitor(role_visitor, concept_or_role); if (role_visitor.result != nullptr) return context.make_count_numerical(role_visitor.result); error_handler(node, "expected two concepts or two roles"); - throw std::runtime_error("Failed parse"); + throw std::runtime_error("Failed parse."); } static std::shared_ptr diff --git a/src/policy/parsers/policy/stage_1/parser.hpp b/src/policy/parsers/policy/stage_1/parser.hpp new file mode 100644 index 00000000..c77bd4e0 --- /dev/null +++ b/src/policy/parsers/policy/stage_1/parser.hpp @@ -0,0 +1,24 @@ +#ifndef DLPLAN_SRC_CORE_PARSERS_ELEMENTS_STAGE_1_PARSER_API_HPP_ +#define DLPLAN_SRC_CORE_PARSERS_ELEMENTS_STAGE_1_PARSER_API_HPP_ + +#include + +#include "include/dlplan/policy/parsers/policy/stage_1/ast.hpp" + + +namespace dlplan::policy::parsers::policy::stage_1 +{ + namespace x3 = boost::spirit::x3; + + namespace parser { + struct PolicyRootClass; + + typedef x3::rule policy_root_type; + + BOOST_SPIRIT_DECLARE(policy_root_type) + } + + parser::policy_root_type const& policy_root(); +} + +#endif \ No newline at end of file diff --git a/src/policy/parsers/policy/stage_1/parser_def.hpp b/src/policy/parsers/policy/stage_1/parser_def.hpp index e314ec80..20a2f980 100644 --- a/src/policy/parsers/policy/stage_1/parser_def.hpp +++ b/src/policy/parsers/policy/stage_1/parser_def.hpp @@ -4,12 +4,13 @@ #include #include -#include "include/dlplan/common/parsers/error_handler.hpp" #include "include/dlplan/core/parsers/elements/stage_1/parser.hpp" +#include "include/dlplan/policy/parsers/policy/stage_1/error_handler.hpp" #include "include/dlplan/policy/parsers/policy/stage_1/ast.hpp" #include "include/dlplan/policy/parsers/policy/stage_1/parser.hpp" #include "ast_adapted.hpp" +#include "parser.hpp" namespace dlplan::policy::parsers::policy::stage_1::parser @@ -27,8 +28,6 @@ namespace dlplan::policy::parsers::policy::stage_1::parser using ascii::char_; using ascii::string; - using error_handler_base = dlplan::common::parsers::error_handler_base; - /////////////////////////////////////////////////////////////////////////// // Rule IDs /////////////////////////////////////////////////////////////////////////// @@ -41,6 +40,17 @@ namespace dlplan::policy::parsers::policy::stage_1::parser // Rules /////////////////////////////////////////////////////////////////////////// + /* Private rules with annotations */ + x3::rule const + feature_condition_entry_inner = "feature_condition_entry_inner"; + + x3::rule const + feature_effect_entry_inner = "feature_effect_entry_inner"; + + /* Privates rules with annotatations and error handler */ + policy_root_type const policy_root = "policy"; + + /* Public rules with annotations */ name_type const name = "name"; boolean_definition_type const boolean_definition = "boolean_definition"; @@ -75,12 +85,6 @@ namespace dlplan::policy::parsers::policy::stage_1::parser unchanged_numerical_effect_entry_type const unchanged_numerical_effect_entry = "unchanged_numerical_effect_entry"; - x3::rule const - feature_condition_entry_inner = "feature_condition_entry_inner"; - - x3::rule const - feature_effect_entry_inner = "feature_effect_entry_inner"; - feature_condition_entry_type const feature_condition_entry = "feature_condition_entry"; feature_effect_entry_type const feature_effect_entry = "feature_effect_entry"; @@ -140,7 +144,7 @@ namespace dlplan::policy::parsers::policy::stage_1::parser const auto feature_effect_entry_def = lit('(') > feature_effect_entry_inner > lit(')'); - const auto rule_entry_def = lit('(') >> lit(":rule") + const auto rule_entry_def = lit('(') >> lit(":rule") > lit('(') > lit(":conditions") > *feature_condition_entry > lit(')') > lit('(') > lit(":effects") > *feature_effect_entry > lit(')') > lit(')'); @@ -149,44 +153,47 @@ namespace dlplan::policy::parsers::policy::stage_1::parser const auto policy_def = lit('(') > lit(":policy") > booleans_entry - > numericals_entry + > numericals_entry > rules > lit(')'); + const auto policy_root_def = policy; + BOOST_SPIRIT_DEFINE( name, boolean_definition, boolean_reference, booleans_entry, numerical_definition, numerical_reference, numericals_entry, positive_boolean_condition_entry, negative_boolean_condition_entry, greater_numerical_condition_entry, equal_numerical_condition_entry, positive_boolean_effect_entry, negative_boolean_effect_entry, unchanged_boolean_effect_entry, increment_numerical_effect_entry, decrement_numerical_effect_entry, unchanged_numerical_effect_entry, - feature_condition_entry_inner, feature_condition_entry, feature_effect_entry_inner, feature_effect_entry, rule_entry, rules, policy) + feature_condition_entry_inner, feature_condition_entry, feature_effect_entry_inner, feature_effect_entry, rule_entry, rules, policy, policy_root) /////////////////////////////////////////////////////////////////////////// // Annotation and Error handling /////////////////////////////////////////////////////////////////////////// - struct NameClass : x3::annotate_on_success, error_handler_base {}; - struct BooleanDefinitionClass : x3::annotate_on_success, error_handler_base {}; - struct BooleanReferenceClass : x3::annotate_on_success, error_handler_base {}; - struct BooleansEntryClass : x3::annotate_on_success, error_handler_base {}; - struct NumericalDefinitionClass : x3::annotate_on_success, error_handler_base {}; - struct NumericalReferenceClass : x3::annotate_on_success, error_handler_base {}; - struct NumericalsEntryClass : x3::annotate_on_success, error_handler_base {}; - struct PositiveBooleanConditionEntryClass : x3::annotate_on_success, error_handler_base {}; - struct NegativeBooleanConditionEntryClass : x3::annotate_on_success, error_handler_base {}; - struct GreaterNumericalConditionEntryClass : x3::annotate_on_success, error_handler_base {}; - struct EqualNumericalConditionEntryClass : x3::annotate_on_success, error_handler_base {}; - struct PositiveBooleanEffectEntryClass : x3::annotate_on_success, error_handler_base {}; - struct NegativeBooleanEffectEntryClass : x3::annotate_on_success, error_handler_base {}; - struct UnchangedBooleanEffectEntryClass : x3::annotate_on_success, error_handler_base {}; - struct IncrementNumericalEffectEntryClass : x3::annotate_on_success, error_handler_base {}; - struct DecrementNumericalEffectEntryClass : x3::annotate_on_success, error_handler_base {}; - struct UnchangedNumericalEffectEntryClass : x3::annotate_on_success, error_handler_base {}; - struct FeatureConditionEntryInnerClass : x3::annotate_on_success, error_handler_base {}; - struct FeatureConditionEntryClass : x3::annotate_on_success, error_handler_base {}; - struct FeatureEffectEntryInnerClass : x3::annotate_on_success, error_handler_base {}; - struct FeatureEffectEntryClass : x3::annotate_on_success, error_handler_base {}; - struct RuleEntryClass : x3::annotate_on_success, error_handler_base {}; - struct RulesClass : x3::annotate_on_success, error_handler_base {}; - struct PolicyClass : x3::annotate_on_success, error_handler_base {}; + struct NameClass : x3::annotate_on_success {}; + struct BooleanDefinitionClass : x3::annotate_on_success {}; + struct BooleanReferenceClass : x3::annotate_on_success {}; + struct BooleansEntryClass : x3::annotate_on_success {}; + struct NumericalDefinitionClass : x3::annotate_on_success {}; + struct NumericalReferenceClass : x3::annotate_on_success {}; + struct NumericalsEntryClass : x3::annotate_on_success {}; + struct PositiveBooleanConditionEntryClass : x3::annotate_on_success {}; + struct NegativeBooleanConditionEntryClass : x3::annotate_on_success {}; + struct GreaterNumericalConditionEntryClass : x3::annotate_on_success {}; + struct EqualNumericalConditionEntryClass : x3::annotate_on_success {}; + struct PositiveBooleanEffectEntryClass : x3::annotate_on_success {}; + struct NegativeBooleanEffectEntryClass : x3::annotate_on_success {}; + struct UnchangedBooleanEffectEntryClass : x3::annotate_on_success {}; + struct IncrementNumericalEffectEntryClass : x3::annotate_on_success {}; + struct DecrementNumericalEffectEntryClass : x3::annotate_on_success {}; + struct UnchangedNumericalEffectEntryClass : x3::annotate_on_success {}; + struct FeatureConditionEntryInnerClass : x3::annotate_on_success {}; + struct FeatureConditionEntryClass : x3::annotate_on_success {}; + struct FeatureEffectEntryInnerClass : x3::annotate_on_success {}; + struct FeatureEffectEntryClass : x3::annotate_on_success {}; + struct RuleEntryClass : x3::annotate_on_success {}; + struct RulesClass : x3::annotate_on_success {}; + struct PolicyClass : x3::annotate_on_success {}; + struct PolicyRootClass : x3::annotate_on_success, error_handler_policy {}; } namespace dlplan::policy::parsers::policy::stage_1 @@ -280,4 +287,11 @@ namespace dlplan::policy::parsers::policy::stage_1 } } -#endif \ No newline at end of file + +namespace dlplan::policy::parsers::policy::stage_1 { + parser::policy_root_type const& policy_root() { + return parser::policy_root; + } +} + +#endif diff --git a/src/policy/parsers/policy/stage_1/parser_instantiations.cpp b/src/policy/parsers/policy/stage_1/parser_instantiations.cpp index b3ec225e..ea88827c 100644 --- a/src/policy/parsers/policy/stage_1/parser_instantiations.cpp +++ b/src/policy/parsers/policy/stage_1/parser_instantiations.cpp @@ -74,4 +74,7 @@ namespace dlplan::policy::parsers::policy::stage_1::parser BOOST_SPIRIT_INSTANTIATE( policy_type, iterator_type, context_type) + + BOOST_SPIRIT_INSTANTIATE( + policy_root_type, iterator_type, context_type) } diff --git a/src/policy/parsers/policy/stage_2/parser.cpp b/src/policy/parsers/policy/stage_2/parser.cpp index 8066059c..b68002b7 100644 --- a/src/policy/parsers/policy/stage_2/parser.cpp +++ b/src/policy/parsers/policy/stage_2/parser.cpp @@ -30,7 +30,7 @@ std::shared_ptr parse( auto it = context.booleans.find(key); if (it == context.booleans.end()) { error_handler(node, "Undefined boolean " + key); - throw std::runtime_error("Unsuccessful parse."); + throw std::runtime_error("Failed parse."); } return it->second; } @@ -58,7 +58,7 @@ std::shared_ptr parse( auto it = context.numericals.find(key); if (it == context.numericals.end()) { error_handler(node, "Undefined numerical " + key); - throw std::runtime_error("Unsuccessful parse."); + throw std::runtime_error("Failed parse."); } return it->second; } diff --git a/src/policy/policy_factory.cpp b/src/policy/policy_factory.cpp index bd6d5607..3a3eeeaf 100644 --- a/src/policy/policy_factory.cpp +++ b/src/policy/policy_factory.cpp @@ -7,7 +7,7 @@ #include "include/dlplan/policy.h" #include "include/dlplan/policy/parsers/policy/stage_1/ast.hpp" -#include "include/dlplan/policy/parsers/policy/stage_1/parser.hpp" +#include "src/policy/parsers/policy/stage_1/parser.hpp" #include "include/dlplan/policy/parsers/policy/stage_2/context.hpp" #include "include/dlplan/policy/parsers/policy/stage_2/parser.hpp" @@ -44,14 +44,11 @@ std::shared_ptr PolicyFactoryImpl::parse_policy( // Our error handler error_handler_type error_handler(iter, end, std::cerr, filename); - parsing_context_type parsing_context; auto const parser = // we pass our error handler to the parser so we can access // it later on in our on_error and on_sucess handlers - with(std::ref(parsing_context)) [ - with(std::ref(error_handler)) [ - dlplan::policy::parsers::policy::stage_1::policy() - ] + with(std::ref(error_handler)) [ + dlplan::policy::parsers::policy::stage_1::policy_root() ]; // Our AST @@ -62,7 +59,7 @@ std::shared_ptr PolicyFactoryImpl::parse_policy( bool success = phrase_parse(iter, end, parser, space, ast); if (!success) { throw std::runtime_error("Failed parse."); - } + } if (iter != end) { throw std::runtime_error("Failed parse. Did not consume whole input."); }