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

View File

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

View File

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

View File

@ -67,7 +67,8 @@ class Parser
template<typename Type> template<typename Type>
bool probe(const Type &expectedValue); 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> template<typename Type>
void expect(const Type &expectedValue); 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> template<class WhiteSpacePredicate>
void Parser::skipWhiteSpace(WhiteSpacePredicate whiteSpacePredicate) void Parser::skipWhiteSpace(WhiteSpacePredicate whiteSpacePredicate)
{ {

View File

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

View File

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

View File

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

View File

@ -71,18 +71,18 @@ void Problem::findSections()
const auto sectionIdentifierPosition = parser.position(); const auto sectionIdentifierPosition = parser.position();
// TODO: check order of the sections // TODO: check order of the sections
if (parser.probeIdentifier("domain")) if (parser.probeIdentifier("domain", isIdentifier))
setSectionPosition("domain", m_domainPosition, position, true); setSectionPosition("domain", m_domainPosition, position, true);
else if (parser.probeIdentifier("requirements")) else if (parser.probeIdentifier("requirements", isIdentifier))
setSectionPosition("requirements", m_requirementsPosition, position, true); setSectionPosition("requirements", m_requirementsPosition, position, true);
else if (parser.probeIdentifier("objects")) else if (parser.probeIdentifier("objects", isIdentifier))
setSectionPosition("objects", m_objectsPosition, position, true); setSectionPosition("objects", m_objectsPosition, position, true);
else if (parser.probeIdentifier("init")) else if (parser.probeIdentifier("init", isIdentifier))
setSectionPosition("init", m_initialStatePosition, position, true); setSectionPosition("init", m_initialStatePosition, position, true);
else if (parser.probeIdentifier("goal") else if (parser.probeIdentifier("goal", isIdentifier)
|| parser.probeIdentifier("constraints") || parser.probeIdentifier("constraints", isIdentifier)
|| parser.probeIdentifier("metric") || parser.probeIdentifier("metric", isIdentifier)
|| parser.probeIdentifier("length")) || parser.probeIdentifier("length", isIdentifier))
{ {
parser.seek(sectionIdentifierPosition); 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<> template<>
void Parser::expect<std::string>(const std::string &expectedValue) void Parser::expect<std::string>(const std::string &expectedValue)
{ {