patrick
/
plasp
Archived
1
0
Fork 0
This repository has been archived on 2023-07-19. You can view files and clone it, but cannot push or open issues or pull requests.
plasp/src/plasp/pddl/Expression.cpp

57 lines
1.6 KiB
C++
Raw Normal View History

#include <plasp/pddl/Expression.h>
#include <plasp/pddl/Context.h>
#include <plasp/pddl/Identifier.h>
2016-06-02 17:35:01 +02:00
#include <plasp/pddl/expressions/AndExpression.h>
#include <plasp/utils/ParserException.h>
namespace plasp
{
namespace pddl
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Expression
//
////////////////////////////////////////////////////////////////////////////////////////////////////
2016-06-02 17:35:01 +02:00
std::unique_ptr<Expression> parsePreconditionExpression(utils::Parser &parser, Context &context, const Variables &parameters)
{
parser.skipWhiteSpace();
parser.expect<std::string>("(");
const auto expressionIdentifier = parser.parseIdentifier(isIdentifier);
2016-06-02 17:35:01 +02:00
std::cout << "Parsing identifier " << expressionIdentifier << std::endl;
2016-06-02 17:35:01 +02:00
std::unique_ptr<Expression> expression;
2016-06-02 17:35:01 +02:00
const auto throwNotAllowed =
[&]()
{
throw utils::ParserException(parser.row(), parser.column(), "Expression of type \"" + expressionIdentifier + "\" not allowed in preference declaration");
};
if (expressionIdentifier == "and")
expression = expressions::AndExpression::parse(parser, context, parameters, parsePreconditionExpression);
else if (expressionIdentifier == "or")
throwNotAllowed();
else if (expressionIdentifier == "not")
throwNotAllowed();
else if (expressionIdentifier == "exists")
throwNotAllowed();
else
throw utils::ParserException(parser.row(), parser.column(), "Undeclared expression \"" + expressionIdentifier + "\"");
parser.expect<std::string>(")");
2016-06-02 17:35:01 +02:00
return expression;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}