Skip to content

Commit

Permalink
fixed parsing derived predicates
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed May 26, 2024
1 parent 0191959 commit b10e9fc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions include/loki/details/pddl/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ struct Context
ScopeStack& scopes;
// For strict error checking
bool strict;
// Toggle error checks during parsing
bool allow_free_variables;
// For checking that certain PDDL objects were referenced at least once
ReferencedPDDLObjects references;
// For convenience, to avoid an additional parameter during semantic parsing
Expand All @@ -47,6 +49,7 @@ struct Context
positions(positions_),
scopes(scopes_),
strict(strict_),
allow_free_variables(false),
references(ReferencedPDDLObjects()),
requirements(nullptr)
{
Expand Down
5 changes: 4 additions & 1 deletion src/pddl/parser/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ Term TermReferenceTermVisitor::operator()(const ast::Name& node) const
Term TermReferenceTermVisitor::operator()(const ast::Variable& node) const
{
const auto variable = parse(node, context);
test_undefined_variable(variable, node, context);
if (!context.allow_free_variables)
{
test_undefined_variable(variable, node, context);
}
const auto term = context.factories.get_or_create_term_variable(variable);
context.positions.push_back(term, node);
return term;
Expand Down
5 changes: 5 additions & 0 deletions src/pddl/parser/structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,14 @@ Axiom parse(const ast::Axiom& node, Context& context)
{
test_undefined_requirement(RequirementEnum::DERIVED_PREDICATES, node, context);
context.references.untrack(RequirementEnum::DERIVED_PREDICATES);

// Allow free variables in axiom head and body
context.allow_free_variables = true;
const auto literal = parse(node.literal, context);
test_expected_derived_predicate(literal->get_atom()->get_predicate(), node, context);
const auto condition = parse(node.goal_descriptor, context);
context.allow_free_variables = false;

// Free variables and literal variables become explicit parameters
auto variables = collect_free_variables(*condition);
for (const auto& term : literal->get_atom()->get_terms())
Expand Down

0 comments on commit b10e9fc

Please sign in to comment.