diff --git a/CHANGELOG.md b/CHANGELOG.md index ff055f1..eb00966 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Bug Fixes: * fixes incorrect output format of conditional effects with SAS +* fixes parsing issue with unexpected whitespaces in SAS files ## 3.0.2 (2016-08-18) diff --git a/include/plasp/pddl/Parser.h b/include/plasp/pddl/Parser.h index c00cb50..acb0c87 100644 --- a/include/plasp/pddl/Parser.h +++ b/include/plasp/pddl/Parser.h @@ -27,6 +27,11 @@ class PDDLParserPolicy return std::iswspace(c); } + static bool isBlankCharacter(char c) + { + return std::isblank(c); + } + static bool isIdentifierCharacter(char c) { return c != '?' diff --git a/include/plasp/utils/Parser.h b/include/plasp/utils/Parser.h index 4e5b0b7..266a0ed 100644 --- a/include/plasp/utils/Parser.h +++ b/include/plasp/utils/Parser.h @@ -72,6 +72,7 @@ class Parser: public Stream, public ParserPolicy std::string parseLine(); void skipWhiteSpace(); + void skipBlankSpace(); void skipLine(); private: @@ -124,6 +125,17 @@ void Parser::skipWhiteSpace() //////////////////////////////////////////////////////////////////////////////////////////////////// +template +void Parser::skipBlankSpace() +{ + check(); + + while (!atEnd() && ParserPolicy::isBlankCharacter(currentCharacter())) + advance(); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + template void Parser::skipLine() { diff --git a/include/plasp/utils/ParserPolicy.h b/include/plasp/utils/ParserPolicy.h index 33c8baf..220516d 100644 --- a/include/plasp/utils/ParserPolicy.h +++ b/include/plasp/utils/ParserPolicy.h @@ -27,6 +27,11 @@ class CaseSensitiveParserPolicy return std::iswspace(c); } + static bool isBlankCharacter(char c) + { + return std::isblank(c); + } + static bool isIdentifierCharacter(char c) { return std::isgraph(c); @@ -48,6 +53,11 @@ class CaseInsensitiveParserPolicy return std::iswspace(c); } + static bool isBlankCharacter(char c) + { + return std::isblank(c); + } + static bool isIdentifierCharacter(char c) { return std::isgraph(c); diff --git a/src/plasp/sas/Predicate.cpp b/src/plasp/sas/Predicate.cpp index 8860ff5..d5dd91a 100644 --- a/src/plasp/sas/Predicate.cpp +++ b/src/plasp/sas/Predicate.cpp @@ -30,14 +30,10 @@ Predicate Predicate::fromSAS(utils::Parser<> &parser) while (true) { - // Parse arguments until reaching newline - // TODO: reimplement - /*parser.skipWhiteSpace( - [&](const auto character) - { - return character != '\n' && std::isspace(character); - });*/ + // Skip whitespace but not newlines + parser.skipBlankSpace(); + // TODO: check \r handling if (parser.currentCharacter() == '\n') break; diff --git a/tests/TestSASParser.cpp b/tests/TestSASParser.cpp index 4971b96..b91688c 100644 --- a/tests/TestSASParser.cpp +++ b/tests/TestSASParser.cpp @@ -111,6 +111,8 @@ TEST_F(SASParserTests, ParseValidSASFile) { FAIL() << e.what(); } + + // TODO: add whitespace test } ////////////////////////////////////////////////////////////////////////////////////////////////////