diff --git a/include/plasp/pddl/Problem.h b/include/plasp/pddl/Problem.h index 836554e..565c220 100644 --- a/include/plasp/pddl/Problem.h +++ b/include/plasp/pddl/Problem.h @@ -34,12 +34,16 @@ class Problem bool hasRequirement(Requirement::Type requirementType) const; void computeDerivedRequirements(); + void parseObjectSection(); + void checkConsistency(); Context &m_context; std::string m_name; Requirements m_requirements; + + expressions::Constants m_objects; }; //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/include/plasp/pddl/expressions/Constant.h b/include/plasp/pddl/expressions/Constant.h index 939afca..eeebb2a 100644 --- a/include/plasp/pddl/expressions/Constant.h +++ b/include/plasp/pddl/expressions/Constant.h @@ -23,7 +23,7 @@ class Constant: public Expression { public: static ConstantPointer parseDeclaration(Context &context); - static void parseTypedDeclaration(Context &context); + static void parseTypedDeclaration(Context &context, Constants &constants); static Constant *parseExisting(Context &context); diff --git a/include/plasp/pddl/expressions/InitialState.h b/include/plasp/pddl/expressions/InitialState.h new file mode 100644 index 0000000..ff94409 --- /dev/null +++ b/include/plasp/pddl/expressions/InitialState.h @@ -0,0 +1,27 @@ +#ifndef __PLASP__PDDL__EXPRESSIONS__INITIAL_STATE_H +#define __PLASP__PDDL__EXPRESSIONS__INITIAL_STATE_H + +#include + +namespace plasp +{ +namespace pddl +{ +namespace expressions +{ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Type +// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +ExpressionPointer parseInitialState(Context &context); + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +} +} +} + +#endif diff --git a/src/plasp/pddl/Domain.cpp b/src/plasp/pddl/Domain.cpp index 334fc7c..493689c 100644 --- a/src/plasp/pddl/Domain.cpp +++ b/src/plasp/pddl/Domain.cpp @@ -259,7 +259,7 @@ void Domain::parseConstantSection() // Store constants while (m_context.parser.currentCharacter() != ')') { - expressions::Constant::parseTypedDeclaration(m_context); + expressions::Constant::parseTypedDeclaration(m_context, m_context.constants); m_context.parser.skipWhiteSpace(); } diff --git a/src/plasp/pddl/Problem.cpp b/src/plasp/pddl/Problem.cpp index 62dedf2..75611ba 100644 --- a/src/plasp/pddl/Problem.cpp +++ b/src/plasp/pddl/Problem.cpp @@ -103,7 +103,7 @@ void Problem::parseSection() else if (sectionIdentifier == "requirements") parseRequirementSection(); else if (sectionIdentifier == "objects") - skipSection(); + parseObjectSection(); else if (sectionIdentifier == "init") skipSection(); else if (sectionIdentifier == "goal") @@ -196,6 +196,23 @@ void Problem::computeDerivedRequirements() //////////////////////////////////////////////////////////////////////////////////////////////////// +void Problem::parseObjectSection() +{ + m_context.parser.skipWhiteSpace(); + + // Store constants + while (m_context.parser.currentCharacter() != ')') + { + expressions::Constant::parseTypedDeclaration(m_context); + + m_context.parser.skipWhiteSpace(); + } + + m_context.parser.expect(")"); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + void Problem::checkConsistency() { } diff --git a/src/plasp/pddl/expressions/Constant.cpp b/src/plasp/pddl/expressions/Constant.cpp index 6dfdee2..18af058 100644 --- a/src/plasp/pddl/expressions/Constant.cpp +++ b/src/plasp/pddl/expressions/Constant.cpp @@ -50,12 +50,12 @@ ConstantPointer Constant::parseDeclaration(Context &context) //////////////////////////////////////////////////////////////////////////////////////////////////// -void Constant::parseTypedDeclaration(Context &context) +void Constant::parseTypedDeclaration(Context &context, Constants &constants) { // Parse and store constant - context.constants.emplace_back(parseDeclaration(context)); + constants.emplace_back(parseDeclaration(context)); - const auto &constant = context.constants.back(); + const auto &constant = constants.back(); // Flag constant as correctly declared in the types section constant->setDeclared(); @@ -70,7 +70,7 @@ void Constant::parseTypedDeclaration(Context &context) auto *type = PrimitiveType::parseExisting(context); // Assign parent type to all types that were previously flagged - std::for_each(context.constants.begin(), context.constants.end(), + std::for_each(constants.begin(), constants.end(), [&](auto &constant) { if (!constant->isDirty()) diff --git a/src/plasp/pddl/expressions/InitialState.cpp b/src/plasp/pddl/expressions/InitialState.cpp new file mode 100644 index 0000000..4b4f449 --- /dev/null +++ b/src/plasp/pddl/expressions/InitialState.cpp @@ -0,0 +1,52 @@ +#include + +#include +#include +#include + +namespace plasp +{ +namespace pddl +{ +namespace expressions +{ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// +// InitialState +// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +void throwUnsupported(const utils::Parser &parser, const std::string &expressionIdentifier) +{ + throw utils::ParserException(parser, "Expression type \"" + expressionIdentifier + "\" currently unsupported in this context"); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +ExpressionPointer parseInitialState(Context &context) +{ + context.parser.expect("("); + + const auto expressionIdentifier = context.parser.parseIdentifier(isIdentifier); + + ExpressionPointer expression; + + if (expressionIdentifier == "at" + || expressionIdentifier == "=") + { + throwUnsupported(context.parser, expressionIdentifier); + } + + // TODO: implement predicate parsing + + context.parser.expect(")"); + + return expression; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +} +} +}