From 010e7bf41ebc2e477a582b779cdfb22a3a9eaf66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Wed, 15 Nov 2017 15:52:10 +0100 Subject: [PATCH] Requiring goal to contain only one statement. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, the parser read the first statement of the goal as its precondition, but didn’t check that it was properly terminated with a closing parenthesis. This allowed arbitrary text to be included within the goal description without error, which was incorrect. This commit fixes this issue and adds a corresponding unit test. --- lib/pddl/src/pddl/detail/parsing/Problem.cpp | 1 + lib/pddl/tests/TestIssues.cpp | 9 +++++++++ tests/data/issues/issue-11.pddl | 15 +++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 tests/data/issues/issue-11.pddl diff --git a/lib/pddl/src/pddl/detail/parsing/Problem.cpp b/lib/pddl/src/pddl/detail/parsing/Problem.cpp index c3eabcc..a5aee27 100644 --- a/lib/pddl/src/pddl/detail/parsing/Problem.cpp +++ b/lib/pddl/src/pddl/detail/parsing/Problem.cpp @@ -283,6 +283,7 @@ void ProblemParser::parseGoalSection(ast::Problem &problem) VariableStack variableStack; problem.goal = parsePrecondition(m_context, astContext, variableStack); + tokenizer.expect(")"); skipSection(tokenizer); } diff --git a/lib/pddl/tests/TestIssues.cpp b/lib/pddl/tests/TestIssues.cpp index 53dc71c..9dbf818 100644 --- a/lib/pddl/tests/TestIssues.cpp +++ b/lib/pddl/tests/TestIssues.cpp @@ -84,4 +84,13 @@ TEST_CASE("[PDDL parser issues] Check past issues", "[PDDL parser issues]") CHECK(!containsInvalidFact); } + + // Check that goal contains just one precondition and is correctly terminated by “)” + SECTION("goal may contain only one precondition") + { + const auto domainFile = fs::path("data") / "issues" / "issue-11.pddl"; + context.tokenizer.read(domainFile); + + CHECK_THROWS(pddl::parseDescription(context)); + } } diff --git a/tests/data/issues/issue-11.pddl b/tests/data/issues/issue-11.pddl new file mode 100644 index 0000000..06e6427 --- /dev/null +++ b/tests/data/issues/issue-11.pddl @@ -0,0 +1,15 @@ +; tests that “imply” statements in preconditions are correctly reduced +(define (domain test-normalization) + (:predicates + (test-predicate-0)) +) + +(define (problem test-normalization) + (:domain test-normalization) + + (:init + (test-predicate-0)) + + (:goal + (test-predicate-0) + (error)))