From 26d7e216a6e41e523e9c4fef700732ef07db01aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Thu, 9 Jun 2016 15:33:09 +0200 Subject: [PATCH] Fixed issue with invalid suffixes on section names. --- include/plasp/utils/Parser.h | 2 ++ src/plasp/pddl/Domain.cpp | 18 +++++++++--------- src/plasp/pddl/Problem.cpp | 16 ++++++++-------- src/plasp/utils/Parser.cpp | 17 ++++++++++++----- 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/include/plasp/utils/Parser.h b/include/plasp/utils/Parser.h index 00ecfe5..89e7914 100644 --- a/include/plasp/utils/Parser.h +++ b/include/plasp/utils/Parser.h @@ -67,6 +67,8 @@ class Parser template bool probe(const Type &expectedValue); + bool probeIdentifier(const std::string &identifier); + template void expect(const Type &expectedValue); diff --git a/src/plasp/pddl/Domain.cpp b/src/plasp/pddl/Domain.cpp index 450f28c..9f19ea5 100644 --- a/src/plasp/pddl/Domain.cpp +++ b/src/plasp/pddl/Domain.cpp @@ -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.probe("requirements")) + if (parser.probeIdentifier("requirements")) setSectionPosition("requirements", m_requirementsPosition, position, true); - else if (parser.probe("types")) + else if (parser.probeIdentifier("types")) setSectionPosition("types", m_typesPosition, position, true); - else if (parser.probe("constants")) + else if (parser.probeIdentifier("constants")) setSectionPosition("constants", m_constantsPosition, position, true); - else if (parser.probe("predicates")) + else if (parser.probeIdentifier("predicates")) setSectionPosition("predicates", m_predicatesPosition, position, true); - else if (parser.probe("action")) + else if (parser.probeIdentifier("action")) { m_actionPositions.emplace_back(-1); setSectionPosition("action", m_actionPositions.back(), position); } - else if (parser.probe("functions") - || parser.probe("constraints") - || parser.probe("durative-action") - || parser.probe("derived")) + else if (parser.probeIdentifier("functions") + || parser.probeIdentifier("constraints") + || parser.probeIdentifier("durative-action") + || parser.probeIdentifier("derived")) { parser.seek(sectionIdentifierPosition); diff --git a/src/plasp/pddl/Problem.cpp b/src/plasp/pddl/Problem.cpp index 5b92488..96ac88e 100644 --- a/src/plasp/pddl/Problem.cpp +++ b/src/plasp/pddl/Problem.cpp @@ -71,18 +71,18 @@ void Problem::findSections() const auto sectionIdentifierPosition = parser.position(); // TODO: check order of the sections - if (parser.probe("domain")) + if (parser.probeIdentifier("domain")) setSectionPosition("domain", m_domainPosition, position, true); - else if (parser.probe("requirements")) + else if (parser.probeIdentifier("requirements")) setSectionPosition("requirements", m_requirementsPosition, position, true); - else if (parser.probe("objects")) + else if (parser.probeIdentifier("objects")) setSectionPosition("objects", m_objectsPosition, position, true); - else if (parser.probe("init")) + else if (parser.probeIdentifier("init")) setSectionPosition("init", m_initialStatePosition, position, true); - else if (parser.probe("goal") - || parser.probe("constraints") - || parser.probe("metric") - || parser.probe("length")) + else if (parser.probeIdentifier("goal") + || parser.probeIdentifier("constraints") + || parser.probeIdentifier("metric") + || parser.probeIdentifier("length")) { parser.seek(sectionIdentifierPosition); diff --git a/src/plasp/utils/Parser.cpp b/src/plasp/utils/Parser.cpp index 360a505..25f341a 100644 --- a/src/plasp/utils/Parser.cpp +++ b/src/plasp/utils/Parser.cpp @@ -284,11 +284,18 @@ bool Parser::probe(const std::string &expectedValue) //////////////////////////////////////////////////////////////////////////////////////////////////// +bool Parser::probeIdentifier(const std::string &expectedValue) +{ + return probe(expectedValue) && std::iswspace(currentCharacter()); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + template<> void Parser::expect(const std::string &expectedValue) { if (!probe(expectedValue)) - throw ParserException(*this, "Unexpected value, expected \"" + expectedValue + "\""); + throw ParserException(*this, "Expected \"" + expectedValue + "\""); } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -322,7 +329,7 @@ template<> void Parser::expect(const char &expectedValue) { if (!probe(expectedValue)) - throw ParserException(*this, std::string("Unexpected value, expected \"") + expectedValue + "\""); + throw ParserException(*this, std::string("Expected \"") + expectedValue + "\""); } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -417,7 +424,7 @@ template<> void Parser::expect(const int64_t &expectedValue) { if (!probe(expectedValue)) - throw ParserException(*this, "Unexpected value, expected \"" + std::to_string(expectedValue) + "\""); + throw ParserException(*this, "Expected \"" + std::to_string(expectedValue) + "\""); } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -426,7 +433,7 @@ template<> void Parser::expect(const uint64_t &expectedValue) { if (!probe(expectedValue)) - throw ParserException(*this, "Unexpected value, expected \"" + std::to_string(expectedValue) + "\""); + throw ParserException(*this, "Expected \"" + std::to_string(expectedValue) + "\""); } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -501,7 +508,7 @@ void Parser::expect(const bool &expectedValue) const auto value = parse(); if (value != expectedValue) - throw ParserException(*this, "Unexpected value " + std::to_string(value) + ", expected " + std::to_string(expectedValue)); + throw ParserException(*this, "Expected \"" + std::to_string(expectedValue) + "\""); } ////////////////////////////////////////////////////////////////////////////////////////////////////