diff --git a/include/plasp/utils/IO.h b/include/plasp/utils/IO.h index f16ddd5..d2d022e 100644 --- a/include/plasp/utils/IO.h +++ b/include/plasp/utils/IO.h @@ -40,18 +40,6 @@ inline std::string unescapeASP(const std::string &string) //////////////////////////////////////////////////////////////////////////////////////////////////// -inline std::string toLowerCase(const std::string &string) -{ - std::string result; - result.resize(string.size()); - - std::transform(string.begin(), string.end(), result.begin(), ::tolower); - - return result; -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// - } } diff --git a/include/plasp/utils/Parser.h b/include/plasp/utils/Parser.h index d41917c..5b1b118 100644 --- a/include/plasp/utils/Parser.h +++ b/include/plasp/utils/Parser.h @@ -24,6 +24,8 @@ class Parser size_t row() const; size_t column() const; + void setCaseSensitive(bool isCaseInsensitive = true); + char currentCharacter() const; void advance(); bool advanceIf(char expectedCharacter); @@ -63,6 +65,8 @@ class Parser size_t m_row; size_t m_column; + bool m_isCaseSensitive; + bool m_endOfFile; }; diff --git a/src/plasp/pddl/Action.cpp b/src/plasp/pddl/Action.cpp index 2c11502..1124901 100644 --- a/src/plasp/pddl/Action.cpp +++ b/src/plasp/pddl/Action.cpp @@ -51,7 +51,7 @@ Action &Action::parseDeclaration(Context &context) { context.parser.expect(":"); - const auto sectionIdentifier = utils::toLowerCase(context.parser.parseIdentifier(isIdentifier)); + const auto sectionIdentifier = context.parser.parseIdentifier(isIdentifier); if (sectionIdentifier == "precondition") action->m_precondition = parsePreconditionExpression(context, action->m_parameters); diff --git a/src/plasp/pddl/Description.cpp b/src/plasp/pddl/Description.cpp index 3eb8598..e7b34a4 100644 --- a/src/plasp/pddl/Description.cpp +++ b/src/plasp/pddl/Description.cpp @@ -22,6 +22,7 @@ Description::Description(std::istream &istream) : m_parser(istream), m_context(m_parser) { + m_parser.setCaseSensitive(false); } //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/plasp/pddl/Domain.cpp b/src/plasp/pddl/Domain.cpp index 5a5a527..334fc7c 100644 --- a/src/plasp/pddl/Domain.cpp +++ b/src/plasp/pddl/Domain.cpp @@ -105,7 +105,7 @@ void Domain::parseSection() m_context.parser.expect("("); m_context.parser.expect(":"); - const auto sectionIdentifier = utils::toLowerCase(m_context.parser.parseIdentifier(isIdentifier)); + const auto sectionIdentifier = m_context.parser.parseIdentifier(isIdentifier); const auto skipSection = [&]() diff --git a/src/plasp/pddl/Expression.cpp b/src/plasp/pddl/Expression.cpp index 09f6e43..04baf11 100644 --- a/src/plasp/pddl/Expression.cpp +++ b/src/plasp/pddl/Expression.cpp @@ -43,7 +43,7 @@ ExpressionPointer parsePreconditionExpression(Context &context, { context.parser.expect("("); - const auto expressionIdentifier = utils::toLowerCase(context.parser.parseIdentifier(isIdentifier)); + const auto expressionIdentifier = context.parser.parseIdentifier(isIdentifier); ExpressionPointer expression; @@ -71,7 +71,7 @@ ExpressionPointer parseExpression(Context &context, const expressions::Variables { context.parser.expect("("); - const auto expressionIdentifier = utils::toLowerCase(context.parser.parseIdentifier(isIdentifier)); + const auto expressionIdentifier = context.parser.parseIdentifier(isIdentifier); auto expression = parseExpressionContent(expressionIdentifier, context, parameters); @@ -136,7 +136,7 @@ ExpressionPointer parseEffectExpression(Context &context, const expressions::Var { context.parser.expect("("); - const auto expressionIdentifier = utils::toLowerCase(context.parser.parseIdentifier(isIdentifier)); + const auto expressionIdentifier = context.parser.parseIdentifier(isIdentifier); ExpressionPointer expression; diff --git a/src/plasp/pddl/Problem.cpp b/src/plasp/pddl/Problem.cpp index 60dd461..62dedf2 100644 --- a/src/plasp/pddl/Problem.cpp +++ b/src/plasp/pddl/Problem.cpp @@ -71,7 +71,7 @@ void Problem::parseSection() m_context.parser.expect("("); m_context.parser.expect(":"); - const auto sectionIdentifier = utils::toLowerCase(m_context.parser.parseIdentifier(isIdentifier)); + const auto sectionIdentifier = m_context.parser.parseIdentifier(isIdentifier); const auto skipSection = [&]() diff --git a/src/plasp/pddl/Requirement.cpp b/src/plasp/pddl/Requirement.cpp index 834fc86..451ee0f 100644 --- a/src/plasp/pddl/Requirement.cpp +++ b/src/plasp/pddl/Requirement.cpp @@ -82,7 +82,7 @@ Requirement::Requirement(Requirement::Type type) Requirement Requirement::parse(Context &context) { - const auto requirementName = utils::toLowerCase(context.parser.parseIdentifier(isIdentifier)); + const auto requirementName = context.parser.parseIdentifier(isIdentifier); const auto match = requirementTypesToPDDL.right.find(requirementName); diff --git a/src/plasp/utils/Parser.cpp b/src/plasp/utils/Parser.cpp index e350b74..dddaec4 100644 --- a/src/plasp/utils/Parser.cpp +++ b/src/plasp/utils/Parser.cpp @@ -26,6 +26,7 @@ Parser::Parser(std::istream &istream) m_position(m_istream), m_row{1}, m_column{1}, + m_isCaseSensitive{true}, m_endOfFile{false} { std::setlocale(LC_NUMERIC, "C"); @@ -52,11 +53,21 @@ size_t Parser::column() const //////////////////////////////////////////////////////////////////////////////////////////////////// +void Parser::setCaseSensitive(bool isCaseSensitive) +{ + m_isCaseSensitive = isCaseSensitive; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + char Parser::currentCharacter() const { checkStream(); - return *m_position; + if (m_isCaseSensitive) + return *m_position; + + return std::tolower(*m_position); } //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/tests/TestPDDLParser.cpp b/tests/TestPDDLParser.cpp index 78a75dd..0bbff48 100644 --- a/tests/TestPDDLParser.cpp +++ b/tests/TestPDDLParser.cpp @@ -58,7 +58,7 @@ TEST_F(PDDLParserTests, ParseBlocksWorldDomain) const auto &domain = description.domain(); // Name - ASSERT_EQ(domain.name(), "BLOCKS"); + ASSERT_EQ(domain.name(), "blocks"); // Requirements ASSERT_EQ(domain.requirements().size(), 2u); @@ -113,7 +113,7 @@ TEST_F(PDDLParserTests, ParseStorageDomain) const auto &domain = description.domain(); // Name - ASSERT_EQ(domain.name(), "Storage-Propositional"); + ASSERT_EQ(domain.name(), "storage-propositional"); // Requirements ASSERT_EQ(domain.requirements().size(), 1u);