Allowing atomic formulas and not just predicates in preconditions and effects.

This commit is contained in:
Patrick Lühne 2017-06-17 19:36:02 +02:00
parent 10e658a922
commit d376c1a993
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
4 changed files with 84 additions and 11 deletions

View File

@ -0,0 +1,27 @@
#ifndef __PDDL_PARSE__DETAIL__PARSING__ATOMIC_FORMULA_H
#define __PDDL_PARSE__DETAIL__PARSING__ATOMIC_FORMULA_H
#include <pddlparse/ASTForward.h>
#include <pddlparse/Context.h>
#include <pddlparse/detail/ASTContext.h>
#include <pddlparse/detail/VariableStack.h>
namespace pddl
{
namespace detail
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// AtomicFormula
//
////////////////////////////////////////////////////////////////////////////////////////////////////
std::experimental::optional<ast::AtomicFormula> parseAtomicFormula(Context &context, ASTContext &astContext, VariableStack &variableStack);
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@ -0,0 +1,49 @@
#include <pddlparse/detail/parsing/AtomicFormula.h>
#include <pddlparse/AST.h>
#include <pddlparse/detail/parsing/Predicate.h>
#include <pddlparse/detail/parsing/Unsupported.h>
namespace pddl
{
namespace detail
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// AtomicFormula
//
////////////////////////////////////////////////////////////////////////////////////////////////////
std::experimental::optional<ast::AtomicFormula> parseAtomicFormula(Context &context, ASTContext &astContext, VariableStack &variableStack)
{
auto &tokenizer = context.tokenizer;
// Test unsupported expressions first
const auto position = tokenizer.position();
tokenizer.expect<std::string>("(");
tokenizer.skipWhiteSpace();
if (tokenizer.testIdentifierAndReturn("="))
{
tokenizer.seek(position);
return parseUnsupported(context);
}
tokenizer.seek(position);
// Now, test supported expressions
std::experimental::optional<ast::AtomicFormula> atomicFormula;
if ((atomicFormula = parsePredicate(context, astContext, variableStack)))
return std::move(atomicFormula.value());
tokenizer.seek(position);
return std::experimental::nullopt;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}

View File

@ -1,9 +1,9 @@
#include <pddlparse/detail/parsing/Effect.h>
#include <pddlparse/AST.h>
#include <pddlparse/detail/parsing/AtomicFormula.h>
#include <pddlparse/detail/parsing/Expressions.h>
#include <pddlparse/detail/parsing/Precondition.h>
#include <pddlparse/detail/parsing/Predicate.h>
#include <pddlparse/detail/parsing/Unsupported.h>
#include <pddlparse/detail/parsing/Utils.h>
@ -58,8 +58,7 @@ std::experimental::optional<ast::Effect> parseEffectBody(Context &context, ASTCo
const auto expressionIdentifierPosition = tokenizer.position();
if (tokenizer.testIdentifierAndReturn("=")
|| tokenizer.testIdentifierAndReturn("assign")
if (tokenizer.testIdentifierAndReturn("assign")
|| tokenizer.testIdentifierAndReturn("scale-up")
|| tokenizer.testIdentifierAndReturn("scale-down")
|| tokenizer.testIdentifierAndReturn("increase")
@ -74,8 +73,8 @@ std::experimental::optional<ast::Effect> parseEffectBody(Context &context, ASTCo
// Now, test supported expressions
std::experimental::optional<ast::Effect> effect;
if ((effect = parseNot<ast::Effect>(context, astContext, variableStack, parsePredicate))
|| (effect = parsePredicate(context, astContext, variableStack)))
if ((effect = parseNot<ast::Effect>(context, astContext, variableStack, parseAtomicFormula))
|| (effect = parseAtomicFormula(context, astContext, variableStack)))
{
return std::move(effect.value());
}
@ -135,8 +134,8 @@ std::experimental::optional<ast::ConditionalEffect> parseConditionalEffectBody(C
// Now, test supported expressions
std::experimental::optional<ast::ConditionalEffect> conditionalEffect;
if ((conditionalEffect = parseNot<ast::ConditionalEffect>(context, astContext, variableStack, parsePredicate))
|| (conditionalEffect = parsePredicate(context, astContext, variableStack)))
if ((conditionalEffect = parseNot<ast::ConditionalEffect>(context, astContext, variableStack, parseAtomicFormula))
|| (conditionalEffect = parseAtomicFormula(context, astContext, variableStack)))
{
return std::move(conditionalEffect.value());
}

View File

@ -1,8 +1,8 @@
#include <pddlparse/detail/parsing/Precondition.h>
#include <pddlparse/AST.h>
#include <pddlparse/detail/parsing/AtomicFormula.h>
#include <pddlparse/detail/parsing/Expressions.h>
#include <pddlparse/detail/parsing/Predicate.h>
#include <pddlparse/detail/parsing/Unsupported.h>
#include <pddlparse/detail/parsing/Utils.h>
@ -66,14 +66,12 @@ std::experimental::optional<ast::Precondition> parsePreconditionBody(Context &co
const auto expressionIdentifierPosition = tokenizer.position();
if (tokenizer.testIdentifierAndReturn("-")
|| tokenizer.testIdentifierAndReturn("=")
|| tokenizer.testIdentifierAndReturn("*")
|| tokenizer.testIdentifierAndReturn("+")
|| tokenizer.testIdentifierAndReturn("-")
|| tokenizer.testIdentifierAndReturn("/")
|| tokenizer.testIdentifierAndReturn(">")
|| tokenizer.testIdentifierAndReturn("<")
|| tokenizer.testIdentifierAndReturn("=")
|| tokenizer.testIdentifierAndReturn(">=")
|| tokenizer.testIdentifierAndReturn("<="))
{
@ -92,7 +90,7 @@ std::experimental::optional<ast::Precondition> parsePreconditionBody(Context &co
|| (precondition = parseForAll<ast::Precondition>(context, astContext, variableStack, parsePrecondition))
|| (precondition = parseNot<ast::Precondition>(context, astContext, variableStack, parsePrecondition))
|| (precondition = parseImply<ast::Precondition>(context, astContext, variableStack, parsePrecondition))
|| (precondition = parsePredicate(context, astContext, variableStack)))
|| (precondition = parseAtomicFormula(context, astContext, variableStack)))
{
return std::move(precondition.value());
}