patrick
/
plasp
Archived
1
0
Fork 0

Fixed issue with invalid suffixes on section names.

This commit is contained in:
Patrick Lühne 2016-06-09 15:33:09 +02:00
parent d629f50661
commit 26d7e216a6
4 changed files with 31 additions and 22 deletions

View File

@ -67,6 +67,8 @@ class Parser
template<typename Type>
bool probe(const Type &expectedValue);
bool probeIdentifier(const std::string &identifier);
template<typename Type>
void expect(const Type &expectedValue);

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.probe<std::string>("requirements"))
if (parser.probeIdentifier("requirements"))
setSectionPosition("requirements", m_requirementsPosition, position, true);
else if (parser.probe<std::string>("types"))
else if (parser.probeIdentifier("types"))
setSectionPosition("types", m_typesPosition, position, true);
else if (parser.probe<std::string>("constants"))
else if (parser.probeIdentifier("constants"))
setSectionPosition("constants", m_constantsPosition, position, true);
else if (parser.probe<std::string>("predicates"))
else if (parser.probeIdentifier("predicates"))
setSectionPosition("predicates", m_predicatesPosition, position, true);
else if (parser.probe<std::string>("action"))
else if (parser.probeIdentifier("action"))
{
m_actionPositions.emplace_back(-1);
setSectionPosition("action", m_actionPositions.back(), position);
}
else if (parser.probe<std::string>("functions")
|| parser.probe<std::string>("constraints")
|| parser.probe<std::string>("durative-action")
|| parser.probe<std::string>("derived"))
else if (parser.probeIdentifier("functions")
|| parser.probeIdentifier("constraints")
|| parser.probeIdentifier("durative-action")
|| parser.probeIdentifier("derived"))
{
parser.seek(sectionIdentifierPosition);

View File

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

View File

@ -284,11 +284,18 @@ 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)
{
if (!probe<std::string>(expectedValue))
throw ParserException(*this, "Unexpected value, expected \"" + expectedValue + "\"");
throw ParserException(*this, "Expected \"" + expectedValue + "\"");
}
////////////////////////////////////////////////////////////////////////////////////////////////////
@ -322,7 +329,7 @@ template<>
void Parser::expect<char>(const char &expectedValue)
{
if (!probe<char>(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<int64_t>(const int64_t &expectedValue)
{
if (!probe<int64_t>(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<uint64_t>(const uint64_t &expectedValue)
{
if (!probe<uint64_t>(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<bool>(const bool &expectedValue)
const auto value = parse<bool>();
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) + "\"");
}
////////////////////////////////////////////////////////////////////////////////////////////////////