patrick
/
plasp
Archived
1
0
Fork 0

Ensuring that goal is variable-free.

Even though the parser shouldn’t be able to put variables into the goal
description, the AST theoretically allows for this case. This commit
adds a defensive check that goal descriptions are variable-free.
This commit is contained in:
Patrick Lühne 2017-10-27 17:10:35 +02:00
parent 27f773e091
commit 1631a70a0b
No known key found for this signature in database
GPG Key ID: 05F3611E97A70ABF
1 changed files with 12 additions and 2 deletions

View File

@ -24,11 +24,20 @@ namespace pddl
inline void translateGoal(colorlog::ColorStream &outputStream, const ::pddl::normalizedAST::Goal &goal)
{
const auto ensureNoVariables =
[](const auto &predicate)
{
for (const auto &argument : predicate->arguments)
if (argument.template is<::pddl::normalizedAST::VariablePointer>())
throw TranslatorException("goal descriptions must be variable-free");
};
const auto handlePredicate =
[&](const ::pddl::normalizedAST::PredicatePointer &predicate, bool isPositive = true)
{
ensureNoVariables(predicate);
outputStream << std::endl << colorlog::Function("goal") << "(";
// TODO: assert that goal is variable-free
translatePredicateToVariable(outputStream, *predicate, isPositive);
outputStream << ").";
};
@ -42,8 +51,9 @@ inline void translateGoal(colorlog::ColorStream &outputStream, const ::pddl::nor
const auto handleDerivedPredicate =
[&](const ::pddl::normalizedAST::DerivedPredicatePointer &derivedPredicate, bool isPositive = true)
{
ensureNoVariables(derivedPredicate);
outputStream << std::endl << colorlog::Function("goal") << "(";
// TODO: assert that goal is variable-free
translateDerivedPredicateToVariable(outputStream, *derivedPredicate, isPositive);
outputStream << ").";
};