From 8d2d66cbc2b466cc7aee27f9ea57cbfc5db2dad2 Mon Sep 17 00:00:00 2001 From: Dominik Drexler Date: Fri, 12 Apr 2024 22:35:44 +0200 Subject: [PATCH] added test to ensure literal in axiom uses a derived predicate --- include/loki/pddl/exceptions.hpp | 10 ++++++++-- src/pddl/exceptions.cpp | 7 ++++++- src/pddl/parser/effects.cpp | 2 +- src/pddl/parser/structure.cpp | 4 ++++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/include/loki/pddl/exceptions.hpp b/include/loki/pddl/exceptions.hpp index a57f1fc1..122d2666 100644 --- a/include/loki/pddl/exceptions.hpp +++ b/include/loki/pddl/exceptions.hpp @@ -157,10 +157,16 @@ class MismatchedFunctionSkeletonTermListError : public SemanticParserError const std::string& error_handler_output); }; -class DerivedPredicateInEffectError : public SemanticParserError +class UnexpectedDerivedPredicateInEffect : public SemanticParserError { public: - DerivedPredicateInEffectError(const std::string& name, const std::string& error_handler_output); + UnexpectedDerivedPredicateInEffect(const std::string& name, const std::string& error_handler_output); +}; + +class ExpectedDerivedPredicate : public SemanticParserError +{ +public: + ExpectedDerivedPredicate(const std::string& name, const std::string& error_handler_output); }; /* Object */ diff --git a/src/pddl/exceptions.cpp b/src/pddl/exceptions.cpp index 2bac787d..de8e73d5 100644 --- a/src/pddl/exceptions.cpp +++ b/src/pddl/exceptions.cpp @@ -145,11 +145,16 @@ MismatchedFunctionSkeletonTermListError::MismatchedFunctionSkeletonTermListError { } -DerivedPredicateInEffectError::DerivedPredicateInEffectError(const std::string& name, const std::string& error_handler_output) : +UnexpectedDerivedPredicateInEffect::UnexpectedDerivedPredicateInEffect(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) { } +ExpectedDerivedPredicate::ExpectedDerivedPredicate(const std::string& name, const std::string& error_handler_output) : + SemanticParserError("The predicate with name \"" + name + "\" is not a derived predicate.", error_handler_output) +{ +} + /** * Problem */ diff --git a/src/pddl/parser/effects.cpp b/src/pddl/parser/effects.cpp index 63607252..d32e1a93 100644 --- a/src/pddl/parser/effects.cpp +++ b/src/pddl/parser/effects.cpp @@ -59,7 +59,7 @@ pddl::Effect parse(const ast::EffectProductionLiteral& node, Context& context) 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, "")); + throw UnexpectedDerivedPredicateInEffect(literal->get_atom()->get_predicate()->get_name(), context.scopes.get_error_handler()(node, "")); } context.positions.push_back(effect, node); diff --git a/src/pddl/parser/structure.cpp b/src/pddl/parser/structure.cpp index e0e3ba93..5973b69c 100644 --- a/src/pddl/parser/structure.cpp +++ b/src/pddl/parser/structure.cpp @@ -69,6 +69,10 @@ pddl::Axiom parse(const ast::Axiom& node, Context& context) context.references.untrack(pddl::RequirementEnum::DERIVED_PREDICATES); const auto literal = parse(node.literal, context); + if (context.derived_predicates.count(literal->get_atom()->get_predicate()) == 0) + { + throw ExpectedDerivedPredicate(literal->get_atom()->get_predicate()->get_name(), context.scopes.get_error_handler()(node, "")); + } const auto condition = parse(node.goal_descriptor, context); const auto axiom = context.factories.axioms.get_or_create(literal, condition);