Skip to content

Commit

Permalink
added test to ensure literal in axiom uses a derived predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed Apr 12, 2024
1 parent dae5e8e commit 8d2d66c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
10 changes: 8 additions & 2 deletions include/loki/pddl/exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
7 changes: 6 additions & 1 deletion src/pddl/exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/pddl/parser/effects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/pddl/parser/structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<pddl::AxiomImpl>(literal, condition);
Expand Down

0 comments on commit 8d2d66c

Please sign in to comment.