Implemented parsing conditional effects.
This commit is contained in:
parent
4fc9b35c13
commit
9cccba42e0
@ -87,6 +87,9 @@ using UnsupportedPointer = boost::intrusive_ptr<Unsupported>;
|
||||
class Variable;
|
||||
using VariablePointer = boost::intrusive_ptr<Variable>;
|
||||
using Variables = std::vector<VariablePointer>;
|
||||
|
||||
class When;
|
||||
using WhenPointer = boost::intrusive_ptr<When>;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -113,6 +116,7 @@ class Expression
|
||||
Reference,
|
||||
Unsupported,
|
||||
Variable,
|
||||
When,
|
||||
};
|
||||
|
||||
public:
|
||||
@ -181,6 +185,9 @@ ExpressionPointer parseExpression(Context &context, ExpressionContext &expressio
|
||||
ExpressionPointer parseEffectExpression(Context &context,
|
||||
ExpressionContext &expressionContext);
|
||||
|
||||
ExpressionPointer parseConditionalEffectExpression(Context &context,
|
||||
ExpressionContext &expressionContext);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
|
67
include/plasp/pddl/expressions/When.h
Normal file
67
include/plasp/pddl/expressions/When.h
Normal file
@ -0,0 +1,67 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__WHEN_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__WHEN_H
|
||||
|
||||
#include <plasp/pddl/expressions/Binary.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// When
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class When: public Binary<When>
|
||||
{
|
||||
public:
|
||||
static const Expression::Type ExpressionType = Expression::Type::When;
|
||||
|
||||
static const std::string Identifier;
|
||||
|
||||
template<typename ConditionExpressionParser, typename ImplicationExpressionParser>
|
||||
static WhenPointer parse(Context &context, ExpressionContext &expressionContext,
|
||||
ConditionExpressionParser parseConditionExpression,
|
||||
ImplicationExpressionParser parseImplicationExpression);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename ConditionExpressionParser, typename ImplicationExpressionParser>
|
||||
WhenPointer When::parse(Context &context, ExpressionContext &expressionContext,
|
||||
ConditionExpressionParser parseConditionExpression,
|
||||
ImplicationExpressionParser parseImplicationExpression)
|
||||
{
|
||||
auto &parser = context.parser;
|
||||
|
||||
const auto position = parser.position();
|
||||
|
||||
if (!parser.testAndSkip<std::string>("(")
|
||||
|| !parser.testIdentifierAndSkip(Identifier))
|
||||
{
|
||||
parser.seek(position);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto expression = WhenPointer(new When);
|
||||
|
||||
// Parse arguments of the expression
|
||||
expression->setArgument(0, parseConditionExpression(context, expressionContext));
|
||||
expression->setArgument(1, parseImplicationExpression(context, expressionContext));
|
||||
|
||||
parser.expect<std::string>(")");
|
||||
|
||||
return expression;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -13,6 +13,7 @@
|
||||
#include <plasp/pddl/expressions/Predicate.h>
|
||||
#include <plasp/pddl/expressions/PredicateDeclaration.h>
|
||||
#include <plasp/pddl/expressions/Unsupported.h>
|
||||
#include <plasp/pddl/expressions/When.h>
|
||||
#include <plasp/utils/ParserException.h>
|
||||
|
||||
namespace plasp
|
||||
@ -230,7 +231,8 @@ ExpressionPointer parseEffectExpression(Context &context, ExpressionContext &exp
|
||||
ExpressionPointer expression;
|
||||
|
||||
if ((expression = expressions::And::parse(context, expressionContext, parseEffectExpression))
|
||||
|| (expression = expressions::ForAll::parse(context, expressionContext, parseEffectExpression)))
|
||||
|| (expression = expressions::ForAll::parse(context, expressionContext, parseEffectExpression))
|
||||
|| (expression = expressions::When::parse(context, expressionContext, parseExpression, parseConditionalEffectExpression)))
|
||||
{
|
||||
return expression;
|
||||
}
|
||||
@ -297,6 +299,18 @@ ExpressionPointer parseEffectBodyExpression(Context &context, ExpressionContext
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExpressionPointer parseConditionalEffectExpression(Context &context, ExpressionContext &expressionContext)
|
||||
{
|
||||
ExpressionPointer expression;
|
||||
|
||||
if ((expression = expressions::And::parse(context, expressionContext, parseEffectBodyExpression)))
|
||||
return expression;
|
||||
|
||||
return parseEffectBodyExpression(context, expressionContext);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExpressionPointer parsePredicate(Context &context, ExpressionContext &expressionContext)
|
||||
{
|
||||
auto &parser = context.parser;
|
||||
|
22
src/plasp/pddl/expressions/When.cpp
Normal file
22
src/plasp/pddl/expressions/When.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include <plasp/pddl/expressions/When.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// When
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const std::string When::Identifier = "when";
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user