Refactored PDDL parser to make all input case-insensitive.
This commit is contained in:
parent
d64c68f754
commit
e607ca4e8e
@ -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;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -51,7 +51,7 @@ Action &Action::parseDeclaration(Context &context)
|
||||
{
|
||||
context.parser.expect<std::string>(":");
|
||||
|
||||
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);
|
||||
|
@ -22,6 +22,7 @@ Description::Description(std::istream &istream)
|
||||
: m_parser(istream),
|
||||
m_context(m_parser)
|
||||
{
|
||||
m_parser.setCaseSensitive(false);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -105,7 +105,7 @@ void Domain::parseSection()
|
||||
m_context.parser.expect<std::string>("(");
|
||||
m_context.parser.expect<std::string>(":");
|
||||
|
||||
const auto sectionIdentifier = utils::toLowerCase(m_context.parser.parseIdentifier(isIdentifier));
|
||||
const auto sectionIdentifier = m_context.parser.parseIdentifier(isIdentifier);
|
||||
|
||||
const auto skipSection =
|
||||
[&]()
|
||||
|
@ -43,7 +43,7 @@ ExpressionPointer parsePreconditionExpression(Context &context,
|
||||
{
|
||||
context.parser.expect<std::string>("(");
|
||||
|
||||
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<std::string>("(");
|
||||
|
||||
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<std::string>("(");
|
||||
|
||||
const auto expressionIdentifier = utils::toLowerCase(context.parser.parseIdentifier(isIdentifier));
|
||||
const auto expressionIdentifier = context.parser.parseIdentifier(isIdentifier);
|
||||
|
||||
ExpressionPointer expression;
|
||||
|
||||
|
@ -71,7 +71,7 @@ void Problem::parseSection()
|
||||
m_context.parser.expect<std::string>("(");
|
||||
m_context.parser.expect<std::string>(":");
|
||||
|
||||
const auto sectionIdentifier = utils::toLowerCase(m_context.parser.parseIdentifier(isIdentifier));
|
||||
const auto sectionIdentifier = m_context.parser.parseIdentifier(isIdentifier);
|
||||
|
||||
const auto skipSection =
|
||||
[&]()
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user