From 1631a70a0b80c649eeb3df10e3b6d14e5ca9a048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Fri, 27 Oct 2017 17:10:35 +0200 Subject: [PATCH] Ensuring that goal is variable-free. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- include/plasp/pddl/translation/Goal.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/include/plasp/pddl/translation/Goal.h b/include/plasp/pddl/translation/Goal.h index 9c90ba2..df9a5c6 100644 --- a/include/plasp/pddl/translation/Goal.h +++ b/include/plasp/pddl/translation/Goal.h @@ -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 << ")."; };