diff --git a/include/plasp/pddl/Expression.h b/include/plasp/pddl/Expression.h index c7d3d6d..1e48c4d 100644 --- a/include/plasp/pddl/Expression.h +++ b/include/plasp/pddl/Expression.h @@ -5,7 +5,6 @@ #include -#include #include namespace plasp diff --git a/include/plasp/pddl/Predicate.h b/include/plasp/pddl/Predicate.h index 0e1e034..f6038b7 100644 --- a/include/plasp/pddl/Predicate.h +++ b/include/plasp/pddl/Predicate.h @@ -3,7 +3,7 @@ #include -#include +#include #include namespace plasp @@ -39,7 +39,7 @@ class Predicate public: const std::string &name() const; - const Variables &arguments() const; + const expressions::Variables &arguments() const; bool isDeclared() const; @@ -51,7 +51,7 @@ class Predicate bool m_isDeclared; std::string m_name; - Variables m_arguments; + expressions::Variables m_arguments; }; //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/include/plasp/pddl/Variable.h b/include/plasp/pddl/Variable.h deleted file mode 100644 index 0be375d..0000000 --- a/include/plasp/pddl/Variable.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef __PLASP__PDDL__VARIABLE_H -#define __PLASP__PDDL__VARIABLE_H - -#include - -#include -#include - -namespace plasp -{ -namespace pddl -{ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// -// Variable -// -//////////////////////////////////////////////////////////////////////////////////////////////////// - -class Context; - -class Variable; -using Variables = std::vector; - -//////////////////////////////////////////////////////////////////////////////////////////////////// - -class Variable -{ - public: - static Variable parse(utils::Parser &parser); - static void parseTyped(utils::Parser &parser, Context &context, std::vector &variables); - - public: - const std::string &name() const; - TypePtr type() const; - - void setDirty(bool isDirty = true); - bool isDirty() const; - - void setType(TypePtr type); - - private: - Variable(std::string name); - - bool m_isDirty; - - std::string m_name; - - TypePtr m_type; -}; - -//////////////////////////////////////////////////////////////////////////////////////////////////// - -} -} - -#endif diff --git a/include/plasp/pddl/expressions/Variable.h b/include/plasp/pddl/expressions/Variable.h index 35caf4d..ba38fb9 100644 --- a/include/plasp/pddl/expressions/Variable.h +++ b/include/plasp/pddl/expressions/Variable.h @@ -2,6 +2,7 @@ #define __PLASP__PDDL__EXPRESSION__VARIABLE_H #include +#include namespace plasp { diff --git a/src/plasp/pddl/Predicate.cpp b/src/plasp/pddl/Predicate.cpp index ccdbf3d..0bd7e81 100644 --- a/src/plasp/pddl/Predicate.cpp +++ b/src/plasp/pddl/Predicate.cpp @@ -40,7 +40,7 @@ Predicate &Predicate::parseDeclaration(utils::Parser &parser, Context &context) // Parse arguments while (parser.currentCharacter() != ')') { - Variable::parseTyped(parser, context, predicate->m_arguments); + expressions::Variable::parseTypedDeclaration(parser, context, predicate->m_arguments); parser.skipWhiteSpace(); } @@ -82,7 +82,7 @@ const std::string &Predicate::name() const //////////////////////////////////////////////////////////////////////////////////////////////////// -const Variables &Predicate::arguments() const +const expressions::Variables &Predicate::arguments() const { return m_arguments; } diff --git a/src/plasp/pddl/Variable.cpp b/src/plasp/pddl/Variable.cpp deleted file mode 100644 index 69008b3..0000000 --- a/src/plasp/pddl/Variable.cpp +++ /dev/null @@ -1,108 +0,0 @@ -#include - -#include - -#include -#include -#include - -namespace plasp -{ -namespace pddl -{ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// -// Variable -// -//////////////////////////////////////////////////////////////////////////////////////////////////// - -Variable::Variable(std::string name) -: m_isDirty{false}, - m_name(name) -{ -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// - -Variable Variable::parse(utils::Parser &parser) -{ - parser.skipWhiteSpace(); - - parser.expect("?"); - - const auto variableName = parser.parseIdentifier(isIdentifier); - - Variable variable(variableName); - variable.setDirty(); - - return variable; -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// - -void Variable::parseTyped(utils::Parser &parser, Context &context, std::vector &variables) -{ - // Parse and store variable itself - variables.emplace_back(parse(parser)); - - parser.skipWhiteSpace(); - - // Check if the variable has a type declaration - if (!parser.advanceIf('-')) - return; - - // Parse argument type - const auto type = parseType(parser, context); - - // Set the argument type for all previously flagged arguments - std::for_each(variables.begin(), variables.end(), - [&](auto &variable) - { - if (!variable.isDirty()) - return; - - variable.setType(type); - variable.setDirty(false); - }); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// - -void Variable::setDirty(bool isDirty) -{ - m_isDirty = isDirty; -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// - -bool Variable::isDirty() const -{ - return m_isDirty; -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// - -const std::string &Variable::name() const -{ - return m_name; -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// - -void Variable::setType(TypePtr type) -{ - m_type = type; -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// - -TypePtr Variable::type() const -{ - return m_type; -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// - -} -} diff --git a/tests/TestPDDLParser.cpp b/tests/TestPDDLParser.cpp index a95f610..b55dde6 100644 --- a/tests/TestPDDLParser.cpp +++ b/tests/TestPDDLParser.cpp @@ -75,11 +75,11 @@ TEST_F(PDDLParserTests, ParseBlocksWorldDomain) ASSERT_EQ(on.name(), "on"); ASSERT_EQ(on.arguments().size(), 2u); - ASSERT_EQ(on.arguments()[0].name(), "x"); - const auto onArgument0Type = boost::get(on.arguments()[0].type()); + ASSERT_EQ(on.arguments()[0]->name(), "x"); + const auto onArgument0Type = boost::get(on.arguments()[0]->type()); ASSERT_EQ(onArgument0Type, &block); - ASSERT_EQ(on.arguments()[1].name(), "y"); - const auto onArgument1Type = boost::get(on.arguments()[1].type()); + ASSERT_EQ(on.arguments()[1]->name(), "y"); + const auto onArgument1Type = boost::get(on.arguments()[1]->type()); ASSERT_EQ(onArgument1Type, &block); const auto &handempty = *domain.predicates()[3]; @@ -138,18 +138,18 @@ TEST_F(PDDLParserTests, ParseStorageDomain) ASSERT_EQ(on.name(), "on"); ASSERT_EQ(on.arguments().size(), 2u); - ASSERT_EQ(on.arguments()[0].name(), "c"); - const auto onArgument0Type = boost::get(on.arguments()[0].type()); + ASSERT_EQ(on.arguments()[0]->name(), "c"); + const auto onArgument0Type = boost::get(on.arguments()[0]->type()); ASSERT_EQ(onArgument0Type, &crate); - ASSERT_EQ(on.arguments()[1].name(), "s"); - const auto onArgument1Type = boost::get(on.arguments()[1].type()); + ASSERT_EQ(on.arguments()[1]->name(), "s"); + const auto onArgument1Type = boost::get(on.arguments()[1]->type()); ASSERT_EQ(onArgument1Type, &storearea); const auto &in = *domain.predicates()[1]; ASSERT_EQ(in.name(), "in"); ASSERT_EQ(in.arguments().size(), 2u); - ASSERT_EQ(in.arguments()[0].name(), "x"); - const auto inArgument0Type = boost::get(in.arguments()[0].type()); + ASSERT_EQ(in.arguments()[0]->name(), "x"); + const auto inArgument0Type = boost::get(in.arguments()[0]->type()); ASSERT_EQ(inArgument0Type->allowedTypes().size(), 2u); ASSERT_EQ(inArgument0Type->allowedTypes()[0], &storearea); ASSERT_EQ(inArgument0Type->allowedTypes()[1], &crate);