diff --git a/lib/pddlparse/include/pddlparse/detail/parsing/Requirement.h b/lib/pddlparse/include/pddlparse/detail/parsing/Requirement.h index 40bb71f..5f535f0 100644 --- a/lib/pddlparse/include/pddlparse/detail/parsing/Requirement.h +++ b/lib/pddlparse/include/pddlparse/detail/parsing/Requirement.h @@ -15,7 +15,7 @@ namespace detail // //////////////////////////////////////////////////////////////////////////////////////////////////// -ast::Requirement parseRequirement(Context &context); +std::experimental::optional parseRequirement(Context &context); const char *toString(const ast::Requirement &requirement); //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/lib/pddlparse/src/pddlparse/detail/parsing/Domain.cpp b/lib/pddlparse/src/pddlparse/detail/parsing/Domain.cpp index 5351c21..cc0e4d3 100644 --- a/lib/pddlparse/src/pddlparse/detail/parsing/Domain.cpp +++ b/lib/pddlparse/src/pddlparse/detail/parsing/Domain.cpp @@ -172,7 +172,10 @@ void DomainParser::parseRequirementSection(ast::Domain &domain) { tokenizer.expect(":"); - domain.requirements.emplace_back(parseRequirement(m_context)); + const auto requirement = parseRequirement(m_context); + + if (requirement) + domain.requirements.emplace_back(requirement.value()); tokenizer.skipWhiteSpace(); } diff --git a/lib/pddlparse/src/pddlparse/detail/parsing/Problem.cpp b/lib/pddlparse/src/pddlparse/detail/parsing/Problem.cpp index d577852..074c3d5 100644 --- a/lib/pddlparse/src/pddlparse/detail/parsing/Problem.cpp +++ b/lib/pddlparse/src/pddlparse/detail/parsing/Problem.cpp @@ -183,7 +183,10 @@ void ProblemParser::parseRequirementSection(ast::Problem &problem) { tokenizer.expect(":"); - problem.requirements.emplace_back(parseRequirement(m_context)); + const auto requirement = parseRequirement(m_context); + + if (requirement) + problem.requirements.emplace_back(requirement.value()); tokenizer.skipWhiteSpace(); } diff --git a/lib/pddlparse/src/pddlparse/detail/parsing/Requirement.cpp b/lib/pddlparse/src/pddlparse/detail/parsing/Requirement.cpp index fcc6375..777ba35 100644 --- a/lib/pddlparse/src/pddlparse/detail/parsing/Requirement.cpp +++ b/lib/pddlparse/src/pddlparse/detail/parsing/Requirement.cpp @@ -51,34 +51,25 @@ static const RequirementNameMap requirementNameMap = {"preferences", ast::Requirement::Preferences}, {"constraints", ast::Requirement::Constraints}, {"action-costs", ast::Requirement::ActionCosts}, - {"goal-utilities", ast::Requirement::GoalUtilities}, }; //////////////////////////////////////////////////////////////////////////////////////////////////// -ast::Requirement parseRequirement(Tokenizer &tokenizer) -{ - const auto requirementName = tokenizer.getIdentifier(); - const auto matchingRequirement = requirementNameMap.find(requirementName.c_str()); - - if (matchingRequirement == requirementNameMap.cend()) - throw ParserException(tokenizer.location(), "unknown PDDL requirement “" + requirementName + "”"); - - return matchingRequirement->second; -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// - -ast::Requirement parseRequirement(Context &context) +std::experimental::optional parseRequirement(Context &context) { auto &tokenizer = context.tokenizer; - auto requirement = parseRequirement(tokenizer); + const auto requirementName = tokenizer.getIdentifier(); - if (requirement == ast::Requirement::GoalUtilities) - context.warningCallback(tokenizer.location(), "requirement “goal-utilities” is not part of the PDDL 3.1 specification"); + const auto matchingRequirement = requirementNameMap.find(requirementName.c_str()); - return requirement; + if (matchingRequirement != requirementNameMap.cend()) + return matchingRequirement->second; + + if (requirementName == "goal-utilities" || requirementName == "domain-axioms") + context.warningCallback(tokenizer.location(), "ignoring requirement “" + requirementName + "”, which is not part of the PDDL 3.1 specification"); + + return std::experimental::nullopt; } ////////////////////////////////////////////////////////////////////////////////////////////////////