Started parsing initial state and object sections.

This commit is contained in:
Patrick Lühne 2016-06-06 15:18:06 +02:00
parent e607ca4e8e
commit d5fa00a4a4
7 changed files with 107 additions and 7 deletions

View File

@ -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;
};
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -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);

View File

@ -0,0 +1,27 @@
#ifndef __PLASP__PDDL__EXPRESSIONS__INITIAL_STATE_H
#define __PLASP__PDDL__EXPRESSIONS__INITIAL_STATE_H
#include <plasp/pddl/Expression.h>
namespace plasp
{
namespace pddl
{
namespace expressions
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Type
//
////////////////////////////////////////////////////////////////////////////////////////////////////
ExpressionPointer parseInitialState(Context &context);
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}
#endif

View File

@ -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();
}

View File

@ -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<std::string>(")");
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void Problem::checkConsistency()
{
}

View File

@ -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())

View File

@ -0,0 +1,52 @@
#include <plasp/pddl/expressions/Type.h>
#include <plasp/pddl/Context.h>
#include <plasp/pddl/expressions/Predicate.h>
#include <plasp/utils/IO.h>
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<std::string>("(");
const auto expressionIdentifier = context.parser.parseIdentifier(isIdentifier);
ExpressionPointer expression;
if (expressionIdentifier == "at"
|| expressionIdentifier == "=")
{
throwUnsupported(context.parser, expressionIdentifier);
}
// TODO: implement predicate parsing
context.parser.expect<std::string>(")");
return expression;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}