diff --git a/Config.cmake.in b/Config.cmake.in index 367f05b9..64bf94df 100644 --- a/Config.cmake.in +++ b/Config.cmake.in @@ -3,6 +3,13 @@ include(CMakeFindDependencyMacro) +############################################################## +# Debug prints +############################################################## + +message("CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}") + + ############################################################## # CMake modules and macro files ############################################################## @@ -16,11 +23,8 @@ include("${CMAKE_CURRENT_LIST_DIR}/cmake/configure_boost.cmake") # Boost # Find Boost headers only according to https://cmake.org/cmake/help/latest/module/FindBoost.html -message("PACKAGE_PREFIX_DIR: ${PACKAGE_PREFIX_DIR}") -message("CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}") configure_boost() find_dependency(Boost ${BOOST_MIN_VERSION} REQUIRED PATHS ${CMAKE_PREFIX_PATH} NO_DEFAULT_PATH) - if(Boost_FOUND) include_directories(${Boost_INCLUDE_DIRS}) message(STATUS "Found Boost: ${Boost_DIR} (found version ${Boost_VERSION})") diff --git a/cmake/configure_boost.cmake b/cmake/configure_boost.cmake index 82c23a90..efcebfb9 100644 --- a/cmake/configure_boost.cmake +++ b/cmake/configure_boost.cmake @@ -1,4 +1,4 @@ set(Boost_NO_SYSTEM_PATHS ON) macro(configure_boost) - set(BOOST_MIN_VERSION "1.84.0") + set(BOOST_MIN_VERSION "1.74.0") endmacro() diff --git a/include/loki/ast/ast.hpp b/include/loki/ast/ast.hpp index b1836101..bd7a1752 100644 --- a/include/loki/ast/ast.hpp +++ b/include/loki/ast/ast.hpp @@ -41,7 +41,6 @@ struct FunctionSymbol; struct Term; struct Number; struct Predicate; -struct DerivedPredicate; // ok struct RequirementStrips; struct RequirementTyping; @@ -74,7 +73,6 @@ struct TypedListOfVariablesRecursively; // :typing struct TypedListOfVariables; struct AtomicFormulaSkeleton; -struct DerivedAtomicFormulaSkeleton; // ok struct AtomicFunctionSkeletonTotalCost; struct AtomicFunctionSkeletonGeneral; @@ -89,11 +87,6 @@ struct Atom; struct NegatedAtom; struct Literal; -struct DerivedAtomicFormulaOfTerms; // new -struct DerivedAtom; // new -struct DerivedNegatedAtom; // new -struct DerivedLiteral; // new - struct MultiOperatorMul; struct MultiOperatorPlus; struct MultiOperator; @@ -117,8 +110,7 @@ struct FunctionExpressionHead; struct GoalDescriptor; struct GoalDescriptorAtom; -struct GoalDescriptorLiteral; // :negative-preconditions -struct GoalDescriptorDerivedLiteral; // new +struct GoalDescriptorLiteral; // :negative-preconditions struct GoalDescriptorAnd; struct GoalDescriptorOr; // :disjunctive-preconditions struct GoalDescriptorNot; // :disjunctive-preconditions @@ -271,11 +263,6 @@ struct Predicate : x3::position_tagged Name name; }; -struct DerivedPredicate : x3::position_tagged -{ - Name name; -}; - /* */ struct RequirementStrips : x3::position_tagged { @@ -441,12 +428,6 @@ struct AtomicFormulaSkeleton : x3::position_tagged TypedListOfVariables typed_list_of_variables; }; -struct DerivedAtomicFormulaSkeleton : x3::position_tagged -{ - DerivedPredicate derived_predicate; - TypedListOfVariables typed_list_of_variables; -}; - /* */ struct AtomicFunctionSkeletonTotalCost : x3::position_tagged { @@ -516,28 +497,6 @@ struct Literal : x3::position_tagged, x3::variant using base_type::operator=; }; -struct DerivedAtomicFormulaOfTerms : x3::position_tagged -{ - DerivedPredicate derived_predicate; - std::vector terms; -}; - -struct DerivedAtom : x3::position_tagged -{ - DerivedAtomicFormulaOfTerms derived_atomic_formula_of_terms; -}; - -struct DerivedNegatedAtom : x3::position_tagged -{ - DerivedAtomicFormulaOfTerms derived_atomic_formula_of_terms; -}; - -struct DerivedLiteral : x3::position_tagged, x3::variant -{ - using base_type::base_type; - using base_type::operator=; -}; - /* Operators */ struct MultiOperatorMul : x3::position_tagged { @@ -661,11 +620,6 @@ struct GoalDescriptorLiteral : x3::position_tagged Literal literal; }; -struct GoalDescriptorDerivedLiteral : x3::position_tagged -{ - DerivedLiteral derived_literal; -}; - struct GoalDescriptorAnd : x3::position_tagged { std::vector goal_descriptors; @@ -938,7 +892,7 @@ struct Action : x3::position_tagged /* */ struct Axiom : x3::position_tagged { - DerivedLiteral derived_literal; + Literal literal; GoalDescriptor goal_descriptor; }; @@ -962,7 +916,7 @@ struct Predicates : x3::position_tagged struct DerivedPredicates : x3::position_tagged { - std::vector derived_atomic_formula_skeletons; + std::vector atomic_formula_skeletons; }; /* */ diff --git a/include/loki/ast/printer.hpp b/include/loki/ast/printer.hpp index 8fb251f3..86f52d1c 100644 --- a/include/loki/ast/printer.hpp +++ b/include/loki/ast/printer.hpp @@ -34,7 +34,6 @@ extern std::string parse_text(const ast::Number& node, const FormattingOptions& extern std::string parse_text(const ast::FunctionSymbol& node, const FormattingOptions& options = {}); extern std::string parse_text(const ast::Term& node, const FormattingOptions& options = {}); extern std::string parse_text(const ast::Predicate& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::DerivedPredicate& node, const FormattingOptions& options = {}); extern std::string parse_text(const ast::RequirementStrips& node, const FormattingOptions& options = {}); extern std::string parse_text(const ast::RequirementTyping& node, const FormattingOptions& options = {}); @@ -67,7 +66,6 @@ extern std::string parse_text(const ast::TypedListOfVariablesRecursively& node, extern std::string parse_text(const ast::TypedListOfVariables& node, const FormattingOptions& options = {}); extern std::string parse_text(const ast::AtomicFormulaSkeleton& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::DerivedAtomicFormulaSkeleton& node, const FormattingOptions& options = {}); extern std::string parse_text(const ast::AtomicFunctionSkeletonTotalCost& node, const FormattingOptions& options = {}); extern std::string parse_text(const ast::AtomicFunctionSkeletonGeneral& node, const FormattingOptions& options = {}); @@ -81,10 +79,6 @@ extern std::string parse_text(const ast::AtomicFormulaOfTerms& node, const Forma extern std::string parse_text(const ast::Atom& node, const FormattingOptions& options = {}); extern std::string parse_text(const ast::NegatedAtom& node, const FormattingOptions& options = {}); extern std::string parse_text(const ast::Literal& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::DerivedAtomicFormulaOfTerms& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::DerivedAtom& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::DerivedNegatedAtom& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::DerivedLiteral& node, const FormattingOptions& options = {}); extern std::string parse_text(const ast::MultiOperatorMul& node, const FormattingOptions& options = {}); extern std::string parse_text(const ast::MultiOperatorPlus& node, const FormattingOptions& options = {}); @@ -110,7 +104,6 @@ extern std::string parse_text(const ast::FunctionExpressionHead& node, const For extern std::string parse_text(const ast::GoalDescriptor& node, const FormattingOptions& options = {}); extern std::string parse_text(const ast::GoalDescriptorAtom& node, const FormattingOptions& options = {}); extern std::string parse_text(const ast::GoalDescriptorLiteral& node, const FormattingOptions& options = {}); -extern std::string parse_text(const ast::GoalDescriptorDerivedLiteral& node, const FormattingOptions& options = {}); extern std::string parse_text(const ast::GoalDescriptorAnd& node, const FormattingOptions& options = {}); extern std::string parse_text(const ast::GoalDescriptorOr& node, const FormattingOptions& options = {}); extern std::string parse_text(const ast::GoalDescriptorNot& node, const FormattingOptions& options = {}); diff --git a/include/loki/pddl/axiom.hpp b/include/loki/pddl/axiom.hpp index 6ef6033e..a37a92d8 100644 --- a/include/loki/pddl/axiom.hpp +++ b/include/loki/pddl/axiom.hpp @@ -35,10 +35,10 @@ namespace loki::pddl class AxiomImpl : public Base { private: - Condition m_condition; Literal m_literal; + Condition m_condition; - AxiomImpl(int identifier, Condition condition, Literal literal); + AxiomImpl(int identifier, Literal literal, Condition condition); // Give access to the constructor. friend class loki::PDDLFactory, loki::EqualTo>; @@ -52,8 +52,8 @@ class AxiomImpl : public Base friend class Base; public: - const Condition& get_condition() const; const Literal& get_literal() const; + const Condition& get_condition() const; }; } diff --git a/include/loki/pddl/context.hpp b/include/loki/pddl/context.hpp index 355c21b6..9ac3e62e 100644 --- a/include/loki/pddl/context.hpp +++ b/include/loki/pddl/context.hpp @@ -38,6 +38,7 @@ struct Context ReferencedPDDLObjects references; // For convenience, to avoid an additional parameter during semantic parsing pddl::Requirements requirements; + std::unordered_set derived_predicates; Context(PDDLFactories& factories_, PDDLPositionCache& positions_, ScopeStack& scopes_) : factories(factories_), diff --git a/include/loki/pddl/exceptions.hpp b/include/loki/pddl/exceptions.hpp index 26324028..a57f1fc1 100644 --- a/include/loki/pddl/exceptions.hpp +++ b/include/loki/pddl/exceptions.hpp @@ -157,6 +157,12 @@ class MismatchedFunctionSkeletonTermListError : public SemanticParserError const std::string& error_handler_output); }; +class DerivedPredicateInEffectError : public SemanticParserError +{ +public: + DerivedPredicateInEffectError(const std::string& name, const std::string& error_handler_output); +}; + /* Object */ class UnusedObjectError : public SemanticParserError { diff --git a/include/loki/pddl/factories.hpp b/include/loki/pddl/factories.hpp index 97fef036..4dab9e95 100644 --- a/include/loki/pddl/factories.hpp +++ b/include/loki/pddl/factories.hpp @@ -106,14 +106,10 @@ struct PDDLFactories AtomFactory atoms; AtomFactory derived_atoms; GroundAtomFactory ground_atoms; - GroundAtomFactory derived_ground_atoms; LiteralFactory literals; - LiteralFactory derived_literals; GroundLiteralFactory ground_literals; - GroundLiteralFactory derived_ground_literals; ParameterFactory parameters; PredicateFactory predicates; - PredicateFactory derived_predicates; FunctionExpressionFactory function_expressions; FunctionFactory functions; FunctionSkeletonFactory function_skeletons; @@ -135,14 +131,10 @@ struct PDDLFactories atoms(AtomFactory(1000)), derived_atoms(AtomFactory(1000)), ground_atoms(GroundAtomFactory(1000)), - derived_ground_atoms(GroundAtomFactory(1000)), literals(LiteralFactory(1000)), - derived_literals(LiteralFactory(1000)), ground_literals(GroundLiteralFactory(1000)), - derived_ground_literals(GroundLiteralFactory(1000)), parameters(ParameterFactory(1000)), predicates(PredicateFactory(1000)), - derived_predicates(PredicateFactory(1000)), function_expressions(FunctionExpressionFactory(1000)), functions(FunctionFactory(1000)), function_skeletons(FunctionSkeletonFactory(1000)), diff --git a/src/ast/ast_adapted.hpp b/src/ast/ast_adapted.hpp index 4321041c..951c4f3f 100644 --- a/src/ast/ast_adapted.hpp +++ b/src/ast/ast_adapted.hpp @@ -33,7 +33,6 @@ BOOST_FUSION_ADAPT_STRUCT(loki::ast::Name, characters) BOOST_FUSION_ADAPT_STRUCT(loki::ast::Variable, characters) BOOST_FUSION_ADAPT_STRUCT(loki::ast::FunctionSymbol, name) BOOST_FUSION_ADAPT_STRUCT(loki::ast::Predicate, name) -BOOST_FUSION_ADAPT_STRUCT(loki::ast::DerivedPredicate, name) BOOST_FUSION_ADAPT_STRUCT(loki::ast::Number, value) BOOST_FUSION_ADAPT_STRUCT(loki::ast::TypeEither, types) @@ -42,7 +41,6 @@ BOOST_FUSION_ADAPT_STRUCT(loki::ast::TypedListOfNamesRecursively, names, type, t BOOST_FUSION_ADAPT_STRUCT(loki::ast::TypedListOfVariablesRecursively, variables, type, typed_list_of_variables) BOOST_FUSION_ADAPT_STRUCT(loki::ast::AtomicFormulaSkeleton, predicate, typed_list_of_variables) -BOOST_FUSION_ADAPT_STRUCT(loki::ast::DerivedAtomicFormulaSkeleton, derived_predicate, typed_list_of_variables) BOOST_FUSION_ADAPT_STRUCT(loki::ast::AtomicFunctionSkeletonTotalCost, function_symbol) BOOST_FUSION_ADAPT_STRUCT(loki::ast::AtomicFunctionSkeletonGeneral, function_symbol, arguments) @@ -55,9 +53,6 @@ BOOST_FUSION_ADAPT_STRUCT(loki::ast::AtomicFormulaOfTermsPredicate, predicate, t BOOST_FUSION_ADAPT_STRUCT(loki::ast::AtomicFormulaOfTermsEquality, term_left, term_right) BOOST_FUSION_ADAPT_STRUCT(loki::ast::Atom, atomic_formula_of_terms) BOOST_FUSION_ADAPT_STRUCT(loki::ast::NegatedAtom, atomic_formula_of_terms) -BOOST_FUSION_ADAPT_STRUCT(loki::ast::DerivedAtomicFormulaOfTerms, derived_predicate, terms) -BOOST_FUSION_ADAPT_STRUCT(loki::ast::DerivedAtom, derived_atomic_formula_of_terms) -BOOST_FUSION_ADAPT_STRUCT(loki::ast::DerivedNegatedAtom, derived_atomic_formula_of_terms) BOOST_FUSION_ADAPT_STRUCT(loki::ast::FunctionHead, function_symbol, terms) BOOST_FUSION_ADAPT_STRUCT(loki::ast::FunctionExpressionNumber, number) @@ -67,7 +62,6 @@ BOOST_FUSION_ADAPT_STRUCT(loki::ast::FunctionExpressionHead, function_head) BOOST_FUSION_ADAPT_STRUCT(loki::ast::GoalDescriptorAtom, atom) BOOST_FUSION_ADAPT_STRUCT(loki::ast::GoalDescriptorLiteral, literal) -BOOST_FUSION_ADAPT_STRUCT(loki::ast::GoalDescriptorDerivedLiteral, derived_literal) BOOST_FUSION_ADAPT_STRUCT(loki::ast::GoalDescriptorAnd, goal_descriptors) BOOST_FUSION_ADAPT_STRUCT(loki::ast::GoalDescriptorOr, goal_descriptors) BOOST_FUSION_ADAPT_STRUCT(loki::ast::GoalDescriptorNot, goal_descriptor) @@ -105,14 +99,14 @@ BOOST_FUSION_ADAPT_STRUCT(loki::ast::ActionSymbol, name) BOOST_FUSION_ADAPT_STRUCT(loki::ast::ActionBody, precondition_goal_descriptor, effect) BOOST_FUSION_ADAPT_STRUCT(loki::ast::Action, action_symbol, typed_list_of_variables, action_body) -BOOST_FUSION_ADAPT_STRUCT(loki::ast::Axiom, derived_literal, goal_descriptor) +BOOST_FUSION_ADAPT_STRUCT(loki::ast::Axiom, literal, goal_descriptor) BOOST_FUSION_ADAPT_STRUCT(loki::ast::DomainName, name) BOOST_FUSION_ADAPT_STRUCT(loki::ast::Requirements, requirements) BOOST_FUSION_ADAPT_STRUCT(loki::ast::Types, typed_list_of_names) BOOST_FUSION_ADAPT_STRUCT(loki::ast::Constants, typed_list_of_names) BOOST_FUSION_ADAPT_STRUCT(loki::ast::Predicates, atomic_formula_skeletons) -BOOST_FUSION_ADAPT_STRUCT(loki::ast::DerivedPredicates, derived_atomic_formula_skeletons) +BOOST_FUSION_ADAPT_STRUCT(loki::ast::DerivedPredicates, atomic_formula_skeletons) BOOST_FUSION_ADAPT_STRUCT(loki::ast::Functions, function_types_list_of_atomic_function_skeletons) BOOST_FUSION_ADAPT_STRUCT(loki::ast::Constraints, constraint_goal_descriptor) BOOST_FUSION_ADAPT_STRUCT(loki::ast::Domain, domain_name, requirements, types, constants, predicates, derived_predicates, functions, constraints, structures) diff --git a/src/ast/parser.hpp b/src/ast/parser.hpp index dfaad691..ecddd3c7 100644 --- a/src/ast/parser.hpp +++ b/src/ast/parser.hpp @@ -55,7 +55,6 @@ struct FunctionSymbolClass; struct TermClass; struct NumberClass; struct PredicateClass; -struct DerivedPredicateClass; struct RequirementStripsClass; struct RequirementTypingClass; @@ -88,7 +87,6 @@ struct TypedListOfVariablesRecursivelyClass; struct TypedListOfVariablesClass; struct AtomicFormulaSkeletonClass; -struct DerivedAtomicFormulaSkeletonClass; struct AtomicFunctionSkeletonTotalCostClass; struct AtomicFunctionSkeletonGeneralClass; @@ -102,10 +100,6 @@ struct AtomicFormulaOfTermsClass; struct AtomClass; struct NegatedAtomClass; struct LiteralClass; -struct DerivedAtomicFormulaOfTermsClass; -struct DerivedAtomClass; -struct DerivedNegatedAtomClass; -struct DerivedLiteralClass; struct MultiOperatorMulClass; struct MultiOperatorPlusClass; @@ -131,7 +125,6 @@ struct FunctionExpressionHeadClass; struct GoalDescriptorClass; struct GoalDescriptorAtomClass; struct GoalDescriptorLiteralClass; -struct GoalDescriptorDerivedLiteralClass; struct GoalDescriptorAndClass; struct GoalDescriptorOrClass; struct GoalDescriptorNotClass; @@ -257,7 +250,6 @@ typedef x3::rule function_symbol_type; typedef x3::rule term_type; typedef x3::rule number_type; typedef x3::rule predicate_type; -typedef x3::rule derived_predicate_type; typedef x3::rule requirement_strips_type; typedef x3::rule requirement_typing_type; @@ -290,7 +282,6 @@ typedef x3::rule typed_list_of_variables_type; typedef x3::rule atomic_formula_skeleton_type; -typedef x3::rule derived_atomic_formula_skeleton_type; typedef x3::rule atomic_function_skeleton_total_cost_type; typedef x3::rule atomic_function_skeleton_general_type; @@ -306,10 +297,6 @@ typedef x3::rule atomic_fo typedef x3::rule atom_type; typedef x3::rule negated_atom_type; typedef x3::rule literal_type; -typedef x3::rule derived_atomic_formula_of_terms_type; -typedef x3::rule derived_atom_type; -typedef x3::rule derived_negated_atom_type; -typedef x3::rule derived_literal_type; typedef x3::rule multi_operator_mul_type; typedef x3::rule multi_operator_plus_type; @@ -335,7 +322,6 @@ typedef x3::rule funct typedef x3::rule goal_descriptor_type; typedef x3::rule goal_descriptor_atom_type; typedef x3::rule goal_descriptor_literal_type; -typedef x3::rule goal_descriptor_derived_literal_type; typedef x3::rule goal_descriptor_and_type; typedef x3::rule goal_descriptor_or_type; typedef x3::rule goal_descriptor_not_type; @@ -459,8 +445,7 @@ BOOST_SPIRIT_DECLARE(name_type, function_symbol_type, term_type, number_type, - predicate_type, - derived_predicate_type) + predicate_type) BOOST_SPIRIT_DECLARE(requirement_strips_type, requirement_typing_type, @@ -492,7 +477,7 @@ BOOST_SPIRIT_DECLARE(type_type, typed_list_of_variables_recursively_type, typed_list_of_variables_type) -BOOST_SPIRIT_DECLARE(atomic_formula_skeleton_type, derived_atomic_formula_skeleton_type) +BOOST_SPIRIT_DECLARE(atomic_formula_skeleton_type) BOOST_SPIRIT_DECLARE(atomic_function_skeleton_total_cost_type, atomic_function_skeleton_general_type, @@ -500,14 +485,7 @@ BOOST_SPIRIT_DECLARE(atomic_function_skeleton_total_cost_type, function_typed_list_of_atomic_function_skeletons_recursively_type, function_typed_list_of_atomic_function_skeletons_type) -BOOST_SPIRIT_DECLARE(atomic_formula_of_terms_type, - atom_type, - negated_atom_type, - literal_type, - derived_atomic_formula_of_terms_type, - derived_atom_type, - derived_negated_atom_type, - derived_literal_type) +BOOST_SPIRIT_DECLARE(atomic_formula_of_terms_type, atom_type, negated_atom_type, literal_type) BOOST_SPIRIT_DECLARE(multi_operator_mul_type, multi_operator_plus_type, @@ -534,7 +512,6 @@ BOOST_SPIRIT_DECLARE(function_expression_type, BOOST_SPIRIT_DECLARE(goal_descriptor_type, goal_descriptor_atom_type, goal_descriptor_literal_type, - goal_descriptor_derived_literal_type, goal_descriptor_and_type, goal_descriptor_or_type, goal_descriptor_not_type, @@ -664,7 +641,6 @@ parser::function_symbol_total_cost_type const& function_symbol_total_cost(); parser::function_symbol_type const& function_symbol(); parser::term_type const& term(); parser::predicate_type const& predicate(); -parser::derived_predicate_type const& derived_predicate(); parser::requirement_strips_type const& requirement_strips(); parser::requirement_typing_type const& requirement_typing(); @@ -697,7 +673,6 @@ parser::typed_list_of_variables_recursively_type const& typed_list_of_variables_ parser::typed_list_of_variables_type const& typed_list_of_variables(); parser::atomic_formula_skeleton_type const& atomic_formula_skeleton(); -parser::derived_atomic_formula_skeleton_type const& derived_atomic_formula_skeleton(); parser::multi_operator_mul_type const& multi_operator_mul(); parser::multi_operator_plus_type const& multi_operator_plus(); @@ -725,10 +700,6 @@ parser::atomic_formula_of_terms_type const& atomic_formula_of_terms(); parser::atom_type const& atom(); parser::negated_atom_type const& negated_atom(); parser::literal_type const& literal(); -parser::derived_atomic_formula_of_terms_type const& derived_atomic_formula_of_terms(); -parser::derived_atom_type const& derived_atom(); -parser::derived_negated_atom_type const& derived_negated_atom(); -parser::derived_literal_type const& derived_literal(); parser::function_expression_type const& function_expression(); parser::function_head_type const& function_head(); @@ -740,7 +711,6 @@ parser::function_expression_head_type const& function_expression_head(); parser::goal_descriptor_type const& goal_descriptor(); parser::goal_descriptor_atom_type const& goal_descriptor_atom(); parser::goal_descriptor_literal_type const& goal_descriptor_literal(); -parser::goal_descriptor_derived_literal_type const& goal_descriptor_derived_literal(); parser::goal_descriptor_and_type const& goal_descriptor_and(); parser::goal_descriptor_or_type const& goal_descriptor_or(); parser::goal_descriptor_not_type const& goal_descriptor_not(); diff --git a/src/ast/parser_def.hpp b/src/ast/parser_def.hpp index 1f838445..5f1cb477 100644 --- a/src/ast/parser_def.hpp +++ b/src/ast/parser_def.hpp @@ -69,7 +69,6 @@ function_symbol_type const function_symbol = "function_symbol"; term_type const term = "term"; number_type const number = "number"; predicate_type const predicate = "predicate"; -derived_predicate_type const derived_predicate = "derived_predicate"; requirement_strips_type const requirement_strips = "requirement_strips"; requirement_typing_type const requirement_typing = "requirement_typing"; @@ -102,7 +101,6 @@ typed_list_of_variables_recursively_type const typed_list_of_variables_recursive typed_list_of_variables_type const typed_list_of_variables = "typed_list_of_variables"; atomic_formula_skeleton_type const atomic_formula_skeleton = "atomic_formula_skeleton"; -derived_atomic_formula_skeleton_type const derived_atomic_formula_skeleton = "derived_atomic_formula_skeleton"; atomic_function_skeleton_total_cost_type const atomic_function_skeleton_total_cost = "atomic_function_skeleton_total_cost"; atomic_function_skeleton_general_type const atomic_function_skeleton_general = "atomic_function_skeleton_general"; @@ -118,10 +116,6 @@ atomic_formula_of_terms_type const atomic_formula_of_terms = "atomic_formula_of_ atom_type const atom = "atom"; negated_atom_type const negated_atom = "negated_atom"; literal_type const literal = "literal"; -derived_atomic_formula_of_terms_type const derived_atomic_formula_of_terms = "derived_atomic_formula_of_terms"; -derived_atom_type const derived_atom = "derived_atom"; -derived_negated_atom_type const derived_negated_atom = "derived_negated_atom"; -derived_literal_type const derived_literal = "derived_literal"; multi_operator_mul_type const multi_operator_mul = "multi_operator_mul"; multi_operator_plus_type const multi_operator_plus = "multi_operator_plus"; @@ -147,7 +141,6 @@ function_expression_head_type const function_expression_head = "function_express goal_descriptor_type const goal_descriptor = "goal_descriptor"; goal_descriptor_atom_type const goal_descriptor_atom = "goal_descriptor_atom"; goal_descriptor_literal_type const goal_descriptor_literal = "goal_descriptor_literal"; -goal_descriptor_derived_literal_type const goal_descriptor_derived_literal = "goal_descriptor_derived_literal"; goal_descriptor_and_type const goal_descriptor_and = "goal_descriptor_and"; goal_descriptor_or_type const goal_descriptor_or = "goal_descriptor_or"; goal_descriptor_not_type const goal_descriptor_not = "goal_descriptor_not"; @@ -276,7 +269,6 @@ const auto function_symbol_def = name; const auto term_def = name | variable; const auto number_def = double_; const auto predicate_def = name; -const auto derived_predicate_def = name; const auto requirement_strips_def = keyword_lit(":strips") > x3::attr(ast::RequirementStrips {}); const auto requirement_typing_def = keyword_lit(":typing") > x3::attr(ast::RequirementTyping {}); @@ -313,7 +305,6 @@ const auto typed_list_of_variables_recursively_def = (+variable >> lit('-')) > t const auto typed_list_of_variables_def = typed_list_of_variables_recursively | *variable; const auto atomic_formula_skeleton_def = lit('(') > predicate > typed_list_of_variables > lit(')'); -const auto derived_atomic_formula_skeleton_def = lit('(') > derived_predicate > typed_list_of_variables > lit(')'); const auto atomic_function_skeleton_total_cost_def = lit('(') >> function_symbol_total_cost > lit(')'); const auto atomic_function_skeleton_general_def = lit('(') > function_symbol > typed_list_of_variables > lit(')'); @@ -328,10 +319,6 @@ const auto atomic_formula_of_terms_def = atomic_formula_of_terms_equality | atom const auto atom_def = atomic_formula_of_terms; const auto negated_atom_def = (lit('(') >> keyword_lit("not")) > atomic_formula_of_terms > lit(')'); const auto literal_def = negated_atom | atom; -const auto derived_atomic_formula_of_terms_def = (lit('(') >> derived_predicate) > *term > lit(')'); -const auto derived_atom_def = derived_atomic_formula_of_terms; -const auto derived_negated_atom_def = (lit('(') >> keyword_lit("not")) > derived_atomic_formula_of_terms > lit(')'); -const auto derived_literal_def = derived_negated_atom | derived_atom; const auto multi_operator_mul_def = lit('*') > x3::attr(ast::MultiOperatorMul {}); const auto multi_operator_plus_def = lit('+') > x3::attr(ast::MultiOperatorPlus {}); @@ -360,7 +347,6 @@ const auto goal_descriptor_def = goal_descriptor_not | goal_descriptor_and | goa | goal_descriptor_forall | goal_descriptor_function_comparison | goal_descriptor_atom | goal_descriptor_literal; const auto goal_descriptor_atom_def = atom; const auto goal_descriptor_literal_def = literal; -const auto goal_descriptor_derived_literal_def = derived_literal; const auto goal_descriptor_and_def = (lit('(') >> keyword_lit("and")) > *goal_descriptor > lit(')'); const auto goal_descriptor_or_def = (lit('(') >> keyword_lit("or") > *goal_descriptor) > lit(')'); const auto goal_descriptor_not_def = (lit('(') >> keyword_lit("not")) > goal_descriptor > lit(')'); @@ -424,7 +410,7 @@ const auto action_body_def = -(keyword_lit(":precondition") > ((lit('(') >> lit( const auto action_def = (lit('(') >> keyword_lit(":action")) > action_symbol > keyword_lit(":parameters") > lit('(') > typed_list_of_variables > lit(')') > action_body >> lit(')'); -const auto axiom_def = (lit('(') >> keyword_lit(":derived")) > derived_literal > goal_descriptor > lit(')'); +const auto axiom_def = (lit('(') >> keyword_lit(":derived")) > literal > goal_descriptor > lit(')'); const auto define_keyword_def = keyword_lit("define"); const auto domain_keyword_def = keyword_lit("domain"); @@ -433,7 +419,7 @@ const auto requirements_def = lit('(') >> keyword_lit(":requirements") > *requir const auto types_def = (lit('(') >> keyword_lit(":types") > typed_list_of_names) > lit(')'); const auto constants_def = (lit('(') >> keyword_lit(":constants") > typed_list_of_names) > lit(')'); const auto predicates_def = (lit('(') >> keyword_lit(":predicates") > *atomic_formula_skeleton) > lit(')'); -const auto derived_predicates_def = (lit('(') >> keyword_lit(":derived-predicates") > *derived_atomic_formula_skeleton) > lit(')'); +const auto derived_predicates_def = (lit('(') >> keyword_lit(":derived-predicates") > *atomic_formula_skeleton) > lit(')'); const auto functions_def = (lit('(') >> keyword_lit(":functions") > *function_typed_list_of_atomic_function_skeletons) > lit(')'); const auto constraints_def = (lit('(') >> keyword_lit(":constraints")) > constraint_goal_descriptor > lit(')'); const auto structure_def = action | axiom; @@ -504,7 +490,7 @@ const auto problem_def = lit('(') > define_keyword > problem_name > problem_doma /** * Domain */ -BOOST_SPIRIT_DEFINE(name, variable, name_total_cost, function_symbol_total_cost, function_symbol, term, number, predicate, derived_predicate) +BOOST_SPIRIT_DEFINE(name, variable, name_total_cost, function_symbol_total_cost, function_symbol, term, number, predicate) BOOST_SPIRIT_DEFINE(requirement_strips, requirement_typing, @@ -536,7 +522,7 @@ BOOST_SPIRIT_DEFINE(type, typed_list_of_variables_recursively, typed_list_of_variables) -BOOST_SPIRIT_DEFINE(atomic_formula_skeleton, derived_atomic_formula_skeleton) +BOOST_SPIRIT_DEFINE(atomic_formula_skeleton) BOOST_SPIRIT_DEFINE(atomic_function_skeleton_total_cost, atomic_function_skeleton_general, @@ -544,16 +530,7 @@ BOOST_SPIRIT_DEFINE(atomic_function_skeleton_total_cost, function_typed_list_of_atomic_function_skeletons_recursively, function_typed_list_of_atomic_function_skeletons) -BOOST_SPIRIT_DEFINE(atomic_formula_of_terms_predicate, - atomic_formula_of_terms_equality, - atomic_formula_of_terms, - atom, - negated_atom, - literal, - derived_atomic_formula_of_terms, - derived_atom, - derived_negated_atom, - derived_literal) +BOOST_SPIRIT_DEFINE(atomic_formula_of_terms_predicate, atomic_formula_of_terms_equality, atomic_formula_of_terms, atom, negated_atom, literal) BOOST_SPIRIT_DEFINE(multi_operator_mul, multi_operator_plus, multi_operator, binary_operator_minus, binary_operator_div, binary_operator) @@ -574,7 +551,6 @@ BOOST_SPIRIT_DEFINE(function_head, BOOST_SPIRIT_DEFINE(goal_descriptor, goal_descriptor_atom, goal_descriptor_literal, - goal_descriptor_derived_literal, goal_descriptor_and, goal_descriptor_or, goal_descriptor_not, @@ -707,9 +683,6 @@ struct NumberClass : x3::annotate_on_success struct PredicateClass : x3::annotate_on_success { }; -struct DerivedPredicateClass : x3::annotate_on_success -{ -}; struct RequirementStripsClass : x3::annotate_on_success { @@ -800,9 +773,6 @@ struct TypedListOfVariablesClass : x3::annotate_on_success struct AtomicFormulaSkeletonClass : x3::annotate_on_success { }; -struct DerivedAtomicFormulaSkeletonClass : x3::annotate_on_success -{ -}; struct AtomicFunctionSkeletonTotalCostClass : x3::annotate_on_success { @@ -838,18 +808,6 @@ struct NegatedAtomClass : x3::annotate_on_success struct LiteralClass : x3::annotate_on_success { }; -struct DerivedAtomicFormulaOfTermsClass : x3::annotate_on_success -{ -}; -struct DerivedAtomClass : x3::annotate_on_success -{ -}; -struct DerivedNegatedAtomClass : x3::annotate_on_success -{ -}; -struct DerivedLiteralClass : x3::annotate_on_success -{ -}; struct MultiOperatorMulClass : x3::annotate_on_success { @@ -917,9 +875,6 @@ struct GoalDescriptorAtomClass : x3::annotate_on_success struct GoalDescriptorLiteralClass : x3::annotate_on_success { }; -struct GoalDescriptorDerivedLiteralClass : x3::annotate_on_success -{ -}; struct GoalDescriptorAndClass : x3::annotate_on_success { }; @@ -1270,7 +1225,6 @@ parser::typed_list_of_variables_recursively_type const& typed_list_of_variables_ parser::typed_list_of_variables_type const& typed_list_of_variables() { return parser::typed_list_of_variables; } parser::atomic_formula_skeleton_type const& atomic_formula_skeleton() { return parser::atomic_formula_skeleton; } -parser::derived_atomic_formula_skeleton_type const& derived_atomic_formula_skeleton() { return parser::derived_atomic_formula_skeleton; } parser::atomic_function_skeleton_total_cost_type const& atomic_function_skeleton_total_cost() { return parser::atomic_function_skeleton_total_cost; } parser::atomic_function_skeleton_general_type const& atomic_function_skeleton_general() { return parser::atomic_function_skeleton_general; } @@ -1290,10 +1244,6 @@ parser::atomic_formula_of_terms_type const& atomic_formula_of_terms() { return p parser::atom_type const& atom() { return parser::atom; } parser::negated_atom_type const& negated_atom() { return parser::negated_atom; } parser::literal_type const& literal() { return parser::literal; } -parser::derived_atomic_formula_of_terms_type const& derived_atomic_formula_of_terms() { return parser::derived_atomic_formula_of_terms; } -parser::derived_atom_type const& derived_atom() { return parser::derived_atom; } -parser::derived_negated_atom_type const& derived_negated_atom() { return parser::derived_negated_atom; } -parser::derived_literal_type const& derived_literal() { return parser::derived_literal; } parser::multi_operator_mul_type const& multi_operator_mul() { return parser::multi_operator_mul; } parser::multi_operator_plus_type const& multi_operator_plus() { return parser::multi_operator_plus; } @@ -1319,7 +1269,6 @@ parser::function_expression_head_type const& function_expression_head() { return parser::goal_descriptor_type const& goal_descriptor() { return parser::goal_descriptor; } parser::goal_descriptor_atom_type const& goal_descriptor_atom() { return parser::goal_descriptor_atom; } parser::goal_descriptor_literal_type const& goal_descriptor_literal() { return parser::goal_descriptor_literal; } -parser::goal_descriptor_derived_literal_type const& goal_descriptor_derived_literal() { return parser::goal_descriptor_derived_literal; } parser::goal_descriptor_and_type const& goal_descriptor_and() { return parser::goal_descriptor_and; } parser::goal_descriptor_or_type const& goal_descriptor_or() { return parser::goal_descriptor_or; } parser::goal_descriptor_not_type const& goal_descriptor_not() { return parser::goal_descriptor_not; } diff --git a/src/ast/parser_instantiations.cpp b/src/ast/parser_instantiations.cpp index bbbe3d96..23c345db 100644 --- a/src/ast/parser_instantiations.cpp +++ b/src/ast/parser_instantiations.cpp @@ -36,7 +36,6 @@ BOOST_SPIRIT_INSTANTIATE(function_symbol_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(term_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(number_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(predicate_type, iterator_type, context_type) -BOOST_SPIRIT_INSTANTIATE(derived_predicate_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(requirement_strips_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(requirement_typing_type, iterator_type, context_type) @@ -69,7 +68,6 @@ BOOST_SPIRIT_INSTANTIATE(typed_list_of_variables_recursively_type, iterator_type BOOST_SPIRIT_INSTANTIATE(typed_list_of_variables_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(atomic_formula_skeleton_type, iterator_type, context_type) -BOOST_SPIRIT_INSTANTIATE(derived_atomic_formula_skeleton_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(atomic_function_skeleton_total_cost_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(atomic_function_skeleton_general_type, iterator_type, context_type) @@ -83,10 +81,6 @@ BOOST_SPIRIT_INSTANTIATE(atomic_formula_of_terms_type, iterator_type, context_ty BOOST_SPIRIT_INSTANTIATE(atom_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(negated_atom_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(literal_type, iterator_type, context_type) -BOOST_SPIRIT_INSTANTIATE(derived_atomic_formula_of_terms_type, iterator_type, context_type) -BOOST_SPIRIT_INSTANTIATE(derived_atom_type, iterator_type, context_type) -BOOST_SPIRIT_INSTANTIATE(derived_negated_atom_type, iterator_type, context_type) -BOOST_SPIRIT_INSTANTIATE(derived_literal_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(multi_operator_mul_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(multi_operator_plus_type, iterator_type, context_type) @@ -112,7 +106,6 @@ BOOST_SPIRIT_INSTANTIATE(function_expression_head_type, iterator_type, context_t BOOST_SPIRIT_INSTANTIATE(goal_descriptor_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(goal_descriptor_atom_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(goal_descriptor_literal_type, iterator_type, context_type) -BOOST_SPIRIT_INSTANTIATE(goal_descriptor_derived_literal_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(goal_descriptor_and_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(goal_descriptor_or_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(goal_descriptor_not_type, iterator_type, context_type) diff --git a/src/ast/printer.cpp b/src/ast/printer.cpp index 299f1229..ed3e4667 100644 --- a/src/ast/printer.cpp +++ b/src/ast/printer.cpp @@ -54,8 +54,6 @@ string parse_text(const ast::Term& node, const FormattingOptions& options) { ret std::string parse_text(const ast::Predicate& node, const FormattingOptions& options) { return parse_text(node.name, options); } -std::string parse_text(const ast::DerivedPredicate& node, const FormattingOptions& options) { return parse_text(node.name, options); } - string parse_text(const ast::Number& node, const FormattingOptions&) { stringstream ss; @@ -163,13 +161,6 @@ std::string parse_text(const ast::AtomicFormulaSkeleton& node, const FormattingO return ss.str(); } -std::string parse_text(const ast::DerivedAtomicFormulaSkeleton& node, const FormattingOptions& options) -{ - std::stringstream ss; - ss << "(" << parse_text(node.derived_predicate, options) << " " << parse_text(node.typed_list_of_variables, options) << ")"; - return ss.str(); -} - std::string parse_text(const ast::AtomicFunctionSkeletonTotalCost& node, const FormattingOptions& /*options*/) { std::stringstream ss; @@ -250,23 +241,6 @@ std::string parse_text(const ast::NegatedAtom& node, const FormattingOptions& op std::string parse_text(const ast::Literal& node, const FormattingOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } -std::string parse_text(const ast::DerivedAtomicFormulaOfTerms& node, const FormattingOptions& options) -{ - std::stringstream ss; - ss << "(" << parse_text(node.derived_predicate, options) << " " << parse_text(node.terms, options) << ")"; - return ss.str(); -} - -std::string parse_text(const ast::DerivedAtom& node, const FormattingOptions& options) { return parse_text(node.derived_atomic_formula_of_terms, options); } - -std::string parse_text(const ast::DerivedNegatedAtom& node, const FormattingOptions& options) -{ - std::stringstream ss; - ss << "(not " << parse_text(node.derived_atomic_formula_of_terms, options) << ")"; - return ss.str(); -} -std::string parse_text(const ast::DerivedLiteral& node, const FormattingOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } - std::string parse_text(const ast::MultiOperatorMul&, const FormattingOptions&) { return "*"; } std::string parse_text(const ast::MultiOperatorPlus&, const FormattingOptions&) { return "+"; } std::string parse_text(const ast::MultiOperator& node, const FormattingOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } @@ -326,8 +300,6 @@ std::string parse_text(const ast::GoalDescriptorAtom& node, const FormattingOpti std::string parse_text(const ast::GoalDescriptorLiteral& node, const FormattingOptions& options) { return parse_text(node.literal, options); } -std::string parse_text(const ast::GoalDescriptorDerivedLiteral& node, const FormattingOptions& options) { return parse_text(node.derived_literal, options); } - std::string parse_text(const ast::GoalDescriptorAnd& node, const FormattingOptions& options) { std::stringstream ss; @@ -578,7 +550,7 @@ std::string parse_text(const ast::Action& node, const FormattingOptions& options std::string parse_text(const ast::Axiom& node, const FormattingOptions& options) { std::stringstream ss; - ss << std::string(options.indent, ' ') << "(:derived " << parse_text(node.derived_literal, options) << "\n"; + ss << std::string(options.indent, ' ') << "(:derived " << parse_text(node.literal, options) << "\n"; FormattingOptions nested_options { options.indent + options.add_indent, options.add_indent }; ss << std::string(nested_options.indent, ' ') << parse_text(node.goal_descriptor, options) << ")\n"; return ss.str(); diff --git a/src/pddl/axiom.cpp b/src/pddl/axiom.cpp index 44cf131c..df81c6cd 100644 --- a/src/pddl/axiom.cpp +++ b/src/pddl/axiom.cpp @@ -28,16 +28,16 @@ namespace loki::pddl { -AxiomImpl::AxiomImpl(int identifier, Condition condition, Literal literal) : Base(identifier), m_condition(std::move(condition)), m_literal(std::move(literal)) +AxiomImpl::AxiomImpl(int identifier, Literal literal, Condition condition) : Base(identifier), m_literal(std::move(literal)), m_condition(std::move(condition)) { } bool AxiomImpl::is_structurally_equivalent_to_impl(const AxiomImpl& other) const { - return (m_condition == other.m_condition) && (m_literal == other.m_literal); + return (m_literal == other.m_literal) && (m_condition == other.m_condition); } -size_t AxiomImpl::hash_impl() const { return hash_combine(m_condition, m_literal); } +size_t AxiomImpl::hash_impl() const { return hash_combine(m_literal, m_condition); } void AxiomImpl::str_impl(std::ostream& out, const FormattingOptions& options) const { @@ -48,8 +48,8 @@ void AxiomImpl::str_impl(std::ostream& out, const FormattingOptions& options) co out << ")\n"; } -const Condition& AxiomImpl::get_condition() const { return m_condition; } - const Literal& AxiomImpl::get_literal() const { return m_literal; } +const Condition& AxiomImpl::get_condition() const { return m_condition; } + } diff --git a/src/pddl/exceptions.cpp b/src/pddl/exceptions.cpp index df6fe05c..2bac787d 100644 --- a/src/pddl/exceptions.cpp +++ b/src/pddl/exceptions.cpp @@ -145,6 +145,11 @@ MismatchedFunctionSkeletonTermListError::MismatchedFunctionSkeletonTermListError { } +DerivedPredicateInEffectError::DerivedPredicateInEffectError(const std::string& name, const std::string& error_handler_output) : + SemanticParserError("The derived predicate with name \"" + name + "\" is not allowed in an effect.", error_handler_output) +{ +} + /** * Problem */ diff --git a/src/pddl/parser/effects.cpp b/src/pddl/parser/effects.cpp index 874777ec..63607252 100644 --- a/src/pddl/parser/effects.cpp +++ b/src/pddl/parser/effects.cpp @@ -56,6 +56,12 @@ pddl::Effect parse(const ast::EffectProductionLiteral& node, Context& context) { auto literal = parse(node.literal, context); const auto effect = context.factories.effects.get_or_create(literal); + + if (context.derived_predicates.count(literal->get_atom()->get_predicate())) + { + throw DerivedPredicateInEffectError(literal->get_atom()->get_predicate()->get_name(), context.scopes.get_error_handler()(node, "")); + } + context.positions.push_back(effect, node); return effect; } diff --git a/src/pddl/parser/literal.cpp b/src/pddl/parser/literal.cpp index 2a7b40ec..8e5e2894 100644 --- a/src/pddl/parser/literal.cpp +++ b/src/pddl/parser/literal.cpp @@ -66,30 +66,6 @@ pddl::Atom parse(const ast::AtomicFormulaOfTermsEquality& node, Context& context pddl::Atom parse(const ast::AtomicFormulaOfTerms& node, Context& context) { return boost::apply_visitor(AtomicFormulaOfTermsVisitor(context), node); } -pddl::Atom parse(const ast::DerivedAtomicFormulaOfTerms& node, Context& context) -{ - auto predicate_name = parse(node.derived_predicate.name); - auto binding = context.scopes.get(predicate_name); - if (!binding.has_value()) - { - throw UndefinedPredicateError(predicate_name, context.scopes.get_error_handler()(node.derived_predicate, "")); - } - auto term_list = pddl::TermList(); - for (const auto& term_node : node.terms) - { - term_list.push_back(boost::apply_visitor(TermReferenceTermVisitor(context), term_node)); - } - const auto [predicate, _position, _error_handler] = binding.value(); - if (predicate->get_parameters().size() != term_list.size()) - { - throw MismatchedPredicateTermListError(predicate, term_list, context.scopes.get_error_handler()(node, "")); - } - context.references.untrack(predicate); - const auto atom = context.factories.derived_atoms.get_or_create(predicate, term_list); - context.positions.push_back(atom, node); - return atom; -} - AtomicFormulaOfTermsVisitor::AtomicFormulaOfTermsVisitor(Context& context_) : context(context_) {} pddl::Literal parse(const ast::Atom& node, Context& context) @@ -108,22 +84,6 @@ pddl::Literal parse(const ast::NegatedAtom& node, Context& context) pddl::Literal parse(const ast::Literal& node, Context& context) { return boost::apply_visitor(LiteralVisitor(context), node); } -pddl::Literal parse(const ast::DerivedAtom& node, Context& context) -{ - const auto literal = context.factories.derived_literals.get_or_create(false, parse(node.derived_atomic_formula_of_terms, context)); - context.positions.push_back(literal, node); - return literal; -} - -pddl::Literal parse(const ast::DerivedNegatedAtom& node, Context& context) -{ - const auto literal = context.factories.derived_literals.get_or_create(true, parse(node.derived_atomic_formula_of_terms, context)); - context.positions.push_back(literal, node); - return literal; -} - -pddl::Literal parse(const ast::DerivedLiteral& node, Context& context) { return boost::apply_visitor(LiteralVisitor(context), node); } - LiteralVisitor::LiteralVisitor(Context& context_) : context(context_) {} } \ No newline at end of file diff --git a/src/pddl/parser/literal.hpp b/src/pddl/parser/literal.hpp index 6462cce7..34b8bd57 100644 --- a/src/pddl/parser/literal.hpp +++ b/src/pddl/parser/literal.hpp @@ -29,8 +29,6 @@ extern pddl::Atom parse(const ast::AtomicFormulaOfTermsPredicate& node, Context& extern pddl::Atom parse(const ast::AtomicFormulaOfTermsEquality& node, Context& context); extern pddl::Atom parse(const ast::AtomicFormulaOfTerms& node, Context& context); -extern pddl::Atom parse(const ast::DerivedAtomicFormulaOfTerms& node, Context& context); - struct AtomicFormulaOfTermsVisitor : boost::static_visitor { Context& context; @@ -49,10 +47,6 @@ extern pddl::Literal parse(const ast::Atom& node, Context& context); extern pddl::Literal parse(const ast::NegatedAtom& node, Context& context); extern pddl::Literal parse(const ast::Literal& node, Context& context); -extern pddl::Literal parse(const ast::DerivedAtom& node, Context& context); -extern pddl::Literal parse(const ast::DerivedNegatedAtom& node, Context& context); -extern pddl::Literal parse(const ast::DerivedLiteral& node, Context& context); - struct LiteralVisitor : boost::static_visitor { Context& context; diff --git a/src/pddl/parser/predicates.cpp b/src/pddl/parser/predicates.cpp index 7c4967ce..c3972ae4 100644 --- a/src/pddl/parser/predicates.cpp +++ b/src/pddl/parser/predicates.cpp @@ -75,54 +75,11 @@ pddl::PredicateList parse(const ast::Predicates& predicates_node, Context& conte return predicate_list; } -static void test_multiple_definition(const pddl::Predicate& predicate, const ast::DerivedPredicate& node, const Context& context) -{ - const auto predicate_name = predicate->get_name(); - const auto binding = context.scopes.get(predicate_name); - if (binding.has_value()) - { - const auto message_1 = context.scopes.get_error_handler()(node, "Defined here:"); - auto message_2 = std::string(""); - const auto [_predicate, position, error_handler] = binding.value(); - if (position.has_value()) - { - message_2 = error_handler(position.value(), "First defined here:"); - } - throw MultiDefinitionPredicateError(predicate_name, message_1 + message_2); - } -} - -static void insert_context_information(const pddl::Predicate& predicate, const ast::DerivedPredicate& node, Context& context) -{ - context.positions.push_back(predicate, node); - context.scopes.insert(predicate->get_name(), predicate, node); -} - -static pddl::Predicate parse_predicate_definition(const ast::DerivedAtomicFormulaSkeleton& node, Context& context) -{ - context.scopes.open_scope(); - const auto parameters = boost::apply_visitor(ParameterListVisitor(context), node.typed_list_of_variables); - context.scopes.close_scope(); - const auto predicate_name = parse(node.derived_predicate.name); - const auto predicate = context.factories.derived_predicates.get_or_create(predicate_name, parameters); - test_multiple_definition(predicate, node.derived_predicate, context); - insert_context_information(predicate, node.derived_predicate, context); - return predicate; -} - -static pddl::PredicateList parse_predicate_definitions(const std::vector& nodes, Context& context) -{ - auto predicate_list = pddl::PredicateList(); - for (const auto& node : nodes) - { - predicate_list.push_back(parse_predicate_definition(node, context)); - } - return predicate_list; -} - pddl::PredicateList parse(const ast::DerivedPredicates& derived_predicates_node, Context& context) { - const auto predicate_list = parse_predicate_definitions(derived_predicates_node.derived_atomic_formula_skeletons, context); + const auto predicate_list = parse_predicate_definitions(derived_predicates_node.atomic_formula_skeletons, context); + // Allow distinguishing derived predicates from simple predicates. + context.derived_predicates = std::unordered_set(predicate_list.begin(), predicate_list.end()); return predicate_list; } diff --git a/src/pddl/parser/structure.cpp b/src/pddl/parser/structure.cpp index fd532c06..e0e3ba93 100644 --- a/src/pddl/parser/structure.cpp +++ b/src/pddl/parser/structure.cpp @@ -68,12 +68,10 @@ pddl::Axiom parse(const ast::Axiom& node, Context& context) } context.references.untrack(pddl::RequirementEnum::DERIVED_PREDICATES); - // :context + const auto literal = parse(node.literal, context); const auto condition = parse(node.goal_descriptor, context); - // :implies - const auto literal = parse(node.derived_literal, context); - const auto axiom = context.factories.axioms.get_or_create(condition, literal); + const auto axiom = context.factories.axioms.get_or_create(literal, condition); context.positions.push_back(axiom, node); return axiom; }