From 0beab67bd46ed5f2c7878c3b4bd07d85bed8c5ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Tue, 27 Jun 2017 17:50:42 +0200 Subject: [PATCH] Made effect variant more concise. --- lib/pddlparse/include/pddlparse/ASTForward.h | 3 +-- .../src/pddlparse/detail/parsing/Effect.cpp | 2 +- .../tests/TestOfficialPDDLInstances.cpp | 18 +++++++++--------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/pddlparse/include/pddlparse/ASTForward.h b/lib/pddlparse/include/pddlparse/ASTForward.h index 762a37f..280259b 100644 --- a/lib/pddlparse/include/pddlparse/ASTForward.h +++ b/lib/pddlparse/include/pddlparse/ASTForward.h @@ -219,10 +219,9 @@ namespace detail { // TODO: add missing types using EffectT = Variant< - AtomicFormula, + Literal, AndPointer, ForAllPointer, - NotPointer, WhenPointer>; } diff --git a/lib/pddlparse/src/pddlparse/detail/parsing/Effect.cpp b/lib/pddlparse/src/pddlparse/detail/parsing/Effect.cpp index 7b927e1..9090439 100644 --- a/lib/pddlparse/src/pddlparse/detail/parsing/Effect.cpp +++ b/lib/pddlparse/src/pddlparse/detail/parsing/Effect.cpp @@ -72,7 +72,7 @@ std::experimental::optional parseEffectBody(Context &context, ASTCo // Now, test supported expressions std::experimental::optional effect; - if ((effect = parseNot(context, astContext, variableStack, parseAtomicFormula)) + if ((effect = parseNot(context, astContext, variableStack, parseAtomicFormula)) || (effect = parseAtomicFormula(context, astContext, variableStack))) { return std::move(effect.value()); diff --git a/lib/pddlparse/tests/TestOfficialPDDLInstances.cpp b/lib/pddlparse/tests/TestOfficialPDDLInstances.cpp index 93f70c3..90c45c6 100644 --- a/lib/pddlparse/tests/TestOfficialPDDLInstances.cpp +++ b/lib/pddlparse/tests/TestOfficialPDDLInstances.cpp @@ -87,25 +87,25 @@ TEST_CASE("[PDDL instances] The official PDDL instances are parsed correctly", " REQUIRE(precondition2->arguments.empty()); const auto &effectAnd = actions[3]->effect.value().get>(); - const auto &effect0 = effectAnd->arguments[0].get().get(); + const auto &effect0 = effectAnd->arguments[0].get().get().get(); // TODO: check declaration once implemented REQUIRE(effect0->arguments.size() == 1); CHECK(effect0->arguments[0].get()->declaration->name == "x"); CHECK(effect0->arguments[0].get()->declaration->type.value().get()->declaration == typeBlock.get()); - const auto &effect1 = effectAnd->arguments[1].get().get(); + const auto &effect1 = effectAnd->arguments[1].get().get().get(); // TODO: check declaration once implemented REQUIRE(effect1->arguments.size() == 1); CHECK(effect1->arguments[0].get()->declaration->name == "y"); CHECK(effect1->arguments[0].get()->declaration->type.value().get()->declaration == typeBlock.get()); - const auto &effectNot2 = effectAnd->arguments[2].get>()->argument.get().get(); + const auto &effectNot2 = effectAnd->arguments[2].get().get>()->argument.get(); // TODO: check declaration once implemented REQUIRE(effectNot2->arguments.size() == 1); CHECK(effectNot2->arguments[0].get()->declaration->name == "x"); CHECK(effectNot2->arguments[0].get()->declaration->type.value().get()->declaration == typeBlock.get()); - const auto &effectNot3 = effectAnd->arguments[3].get>()->argument.get().get(); + const auto &effectNot3 = effectAnd->arguments[3].get().get>()->argument.get(); // TODO: check declaration once implemented REQUIRE(effectNot3->arguments.empty()); - const auto &effectNot4 = effectAnd->arguments[4].get>()->argument.get().get(); + const auto &effectNot4 = effectAnd->arguments[4].get().get>()->argument.get(); // TODO: check declaration once implemented REQUIRE(effectNot4->arguments.size() == 2); CHECK(effectNot4->arguments[0].get()->declaration->name == "x"); @@ -351,10 +351,10 @@ TEST_CASE("[PDDL instances] The official PDDL instances are parsed correctly", " CHECK(actions[1]->name == "do-roll"); const auto &effectAnd = actions[1]->effect.value().get>(); REQUIRE(effectAnd->arguments.size() == 10); - CHECK(effectAnd->arguments[0].get().get()->arguments[0].get()->declaration->name == "roller"); - CHECK(effectAnd->arguments[1].get().is()); - CHECK(effectAnd->arguments[2].get().is()); - CHECK(effectAnd->arguments[3].get().is()); + CHECK(effectAnd->arguments[0].get().get().get()->arguments[0].get()->declaration->name == "roller"); + CHECK(effectAnd->arguments[1].get().get().is()); + CHECK(effectAnd->arguments[2].get().get().is()); + CHECK(effectAnd->arguments[3].get().get().is()); const auto &effectWhen4 = effectAnd->arguments[4].get>(); // TODO: check name of declaration CHECK(effectWhen4->argumentLeft.get>()->argument.get().is());