Fixed further white space issue with empty n-ary predicates.

This commit is contained in:
Patrick Lühne 2016-06-09 18:46:06 +02:00
parent 23170e170a
commit d138e869fc
10 changed files with 61 additions and 56 deletions

View File

@ -4,6 +4,7 @@
#include <plasp/pddl/ConsistencyException.h>
#include <plasp/pddl/Context.h>
#include <plasp/pddl/Expression.h>
#include <plasp/pddl/Identifier.h>
#include <plasp/pddl/expressions/Variable.h>
namespace plasp
@ -48,7 +49,7 @@ std::unique_ptr<Derived> Binary<Derived>::parse(Context &context,
const auto position = parser.position();
if (!parser.probe<std::string>("(")
|| !parser.probeIdentifier(Derived::Identifier))
|| !parser.probeIdentifier(Derived::Identifier, isIdentifier))
{
parser.seek(position);
return nullptr;

View File

@ -4,6 +4,7 @@
#include <plasp/pddl/ConsistencyException.h>
#include <plasp/pddl/Context.h>
#include <plasp/pddl/Expression.h>
#include <plasp/pddl/Identifier.h>
#include <plasp/pddl/expressions/Variable.h>
namespace plasp
@ -46,7 +47,7 @@ std::unique_ptr<Derived> NAry<Derived>::parse(Context &context,
const auto position = parser.position();
if (!parser.probe<std::string>("(")
|| !parser.probeIdentifier(Derived::Identifier))
|| !parser.probeIdentifier(Derived::Identifier, isIdentifier))
{
parser.seek(position);
return nullptr;

View File

@ -3,6 +3,7 @@
#include <plasp/pddl/Context.h>
#include <plasp/pddl/Expression.h>
#include <plasp/pddl/Identifier.h>
namespace plasp
{
@ -44,7 +45,7 @@ NotPointer Not::parse(Context &context, ExpressionContext &expressionContext,
const auto position = parser.position();
if (!parser.probe<std::string>("(")
|| !parser.probeIdentifier("not"))
|| !parser.probeIdentifier("not", isIdentifier))
{
parser.seek(position);
return nullptr;

View File

@ -67,7 +67,8 @@ class Parser
template<typename Type>
bool probe(const Type &expectedValue);
bool probeIdentifier(const std::string &identifier);
template<class CharacterPredicate>
bool probeIdentifier(const std::string &identifier, CharacterPredicate characterPredicate);
template<typename Type>
void expect(const Type &expectedValue);
@ -130,6 +131,14 @@ std::string Parser::parseIdentifier(CharacterPredicate characterPredicate)
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class CharacterPredicate>
bool Parser::probeIdentifier(const std::string &expectedValue, CharacterPredicate characterPredicate)
{
return probe<std::string>(expectedValue) && !characterPredicate(currentCharacter());
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class WhiteSpacePredicate>
void Parser::skipWhiteSpace(WhiteSpacePredicate whiteSpacePredicate)
{

View File

@ -42,9 +42,9 @@ void Action::parseDeclaration(Context &context, Domain &domain)
{
context.parser.expect<std::string>(":");
if (context.parser.probeIdentifier("precondition"))
if (context.parser.probeIdentifier("precondition", isIdentifier))
action->m_precondition = parsePreconditionExpression(context, expressionContext);
else if (context.parser.probeIdentifier("effect"))
else if (context.parser.probeIdentifier("effect", isIdentifier))
action->m_effect = parseEffectExpression(context, expressionContext);
context.parser.skipWhiteSpace();

View File

@ -75,23 +75,23 @@ void Domain::findSections()
const auto sectionIdentifierPosition = parser.position();
// Save the parser position of the individual sections for later parsing
if (parser.probeIdentifier("requirements"))
if (parser.probeIdentifier("requirements", isIdentifier))
setSectionPosition("requirements", m_requirementsPosition, position, true);
else if (parser.probeIdentifier("types"))
else if (parser.probeIdentifier("types", isIdentifier))
setSectionPosition("types", m_typesPosition, position, true);
else if (parser.probeIdentifier("constants"))
else if (parser.probeIdentifier("constants", isIdentifier))
setSectionPosition("constants", m_constantsPosition, position, true);
else if (parser.probeIdentifier("predicates"))
else if (parser.probeIdentifier("predicates", isIdentifier))
setSectionPosition("predicates", m_predicatesPosition, position, true);
else if (parser.probeIdentifier("action"))
else if (parser.probeIdentifier("action", isIdentifier))
{
m_actionPositions.emplace_back(-1);
setSectionPosition("action", m_actionPositions.back(), position);
}
else if (parser.probeIdentifier("functions")
|| parser.probeIdentifier("constraints")
|| parser.probeIdentifier("durative-action")
|| parser.probeIdentifier("derived"))
else if (parser.probeIdentifier("functions", isIdentifier)
|| parser.probeIdentifier("constraints", isIdentifier)
|| parser.probeIdentifier("durative-action", isIdentifier)
|| parser.probeIdentifier("derived", isIdentifier))
{
parser.seek(sectionIdentifierPosition);

View File

@ -57,8 +57,8 @@ ExpressionPointer parsePreconditionExpression(Context &context,
const auto expressionIdentifierPosition = parser.position();
if (parser.probeIdentifier("forall")
|| parser.probeIdentifier("preference"))
if (parser.probeIdentifier("forall", isIdentifier)
|| parser.probeIdentifier("preference", isIdentifier))
{
// TODO: refactor
parser.seek(expressionIdentifierPosition);
@ -102,19 +102,19 @@ ExpressionPointer parseExpression(Context &context, ExpressionContext &expressio
const auto expressionIdentifierPosition = parser.position();
if (parser.probeIdentifier("exists")
|| parser.probeIdentifier("forall")
|| parser.probeIdentifier("-")
|| parser.probeIdentifier("=")
|| parser.probeIdentifier("*")
|| parser.probeIdentifier("+")
|| parser.probeIdentifier("-")
|| parser.probeIdentifier("/")
|| parser.probeIdentifier(">")
|| parser.probeIdentifier("<")
|| parser.probeIdentifier("=")
|| parser.probeIdentifier(">=")
|| parser.probeIdentifier("<="))
if (parser.probeIdentifier("exists", isIdentifier)
|| parser.probeIdentifier("forall", isIdentifier)
|| parser.probeIdentifier("-", isIdentifier)
|| parser.probeIdentifier("=", isIdentifier)
|| parser.probeIdentifier("*", isIdentifier)
|| parser.probeIdentifier("+", isIdentifier)
|| parser.probeIdentifier("-", isIdentifier)
|| parser.probeIdentifier("/", isIdentifier)
|| parser.probeIdentifier(">", isIdentifier)
|| parser.probeIdentifier("<", isIdentifier)
|| parser.probeIdentifier("=", isIdentifier)
|| parser.probeIdentifier(">=", isIdentifier)
|| parser.probeIdentifier("<=", isIdentifier))
{
parser.seek(expressionIdentifierPosition);
const auto expressionIdentifier = parser.parseIdentifier(isIdentifier);
@ -152,8 +152,8 @@ ExpressionPointer parseEffectExpression(Context &context, ExpressionContext &exp
const auto expressionIdentifierPosition = parser.position();
if (parser.probeIdentifier("forall")
|| parser.probeIdentifier("when"))
if (parser.probeIdentifier("forall", isIdentifier)
|| parser.probeIdentifier("when", isIdentifier))
{
parser.seek(expressionIdentifierPosition);
const auto expressionIdentifier = parser.parseIdentifier(isIdentifier);
@ -191,12 +191,12 @@ ExpressionPointer parseEffectBodyExpression(Context &context, ExpressionContext
const auto expressionIdentifierPosition = parser.position();
if (parser.probeIdentifier("=")
|| parser.probeIdentifier("assign")
|| parser.probeIdentifier("scale-up")
|| parser.probeIdentifier("scale-down")
|| parser.probeIdentifier("increase")
|| parser.probeIdentifier("decrease"))
if (parser.probeIdentifier("=", isIdentifier)
|| parser.probeIdentifier("assign", isIdentifier)
|| parser.probeIdentifier("scale-up", isIdentifier)
|| parser.probeIdentifier("scale-down", isIdentifier)
|| parser.probeIdentifier("increase", isIdentifier)
|| parser.probeIdentifier("decrease", isIdentifier))
{
parser.seek(expressionIdentifierPosition);
const auto expressionIdentifier = parser.parseIdentifier(isIdentifier);

View File

@ -45,9 +45,9 @@ std::unique_ptr<InitialState> InitialState::parseDeclaration(Context &context, c
const auto expressionIdentifierPosition = parser.position();
if (parser.probeIdentifier("at")
|| parser.probeIdentifier("=")
|| parser.probeIdentifier("not"))
if (parser.probeIdentifier("at", isIdentifier)
|| parser.probeIdentifier("=", isIdentifier)
|| parser.probeIdentifier("not", isIdentifier))
{
parser.seek(expressionIdentifierPosition);
const auto expressionIdentifier = parser.parseIdentifier(isIdentifier);

View File

@ -71,18 +71,18 @@ void Problem::findSections()
const auto sectionIdentifierPosition = parser.position();
// TODO: check order of the sections
if (parser.probeIdentifier("domain"))
if (parser.probeIdentifier("domain", isIdentifier))
setSectionPosition("domain", m_domainPosition, position, true);
else if (parser.probeIdentifier("requirements"))
else if (parser.probeIdentifier("requirements", isIdentifier))
setSectionPosition("requirements", m_requirementsPosition, position, true);
else if (parser.probeIdentifier("objects"))
else if (parser.probeIdentifier("objects", isIdentifier))
setSectionPosition("objects", m_objectsPosition, position, true);
else if (parser.probeIdentifier("init"))
else if (parser.probeIdentifier("init", isIdentifier))
setSectionPosition("init", m_initialStatePosition, position, true);
else if (parser.probeIdentifier("goal")
|| parser.probeIdentifier("constraints")
|| parser.probeIdentifier("metric")
|| parser.probeIdentifier("length"))
else if (parser.probeIdentifier("goal", isIdentifier)
|| parser.probeIdentifier("constraints", isIdentifier)
|| parser.probeIdentifier("metric", isIdentifier)
|| parser.probeIdentifier("length", isIdentifier))
{
parser.seek(sectionIdentifierPosition);

View File

@ -284,13 +284,6 @@ bool Parser::probe<std::string>(const std::string &expectedValue)
////////////////////////////////////////////////////////////////////////////////////////////////////
bool Parser::probeIdentifier(const std::string &expectedValue)
{
return probe<std::string>(expectedValue) && std::iswspace(currentCharacter());
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<>
void Parser::expect<std::string>(const std::string &expectedValue)
{