Throwing exceptions for unsupported features instead of silently accepting them.
This commit is contained in:
@@ -17,19 +17,13 @@ namespace detail
|
||||
|
||||
normalizedAST::AtomicFormula normalize(ast::AtomicFormula &&atomicFormula)
|
||||
{
|
||||
const auto handleUnsupported =
|
||||
[&](ast::UnsupportedPointer &unsupported) -> normalizedAST::AtomicFormula
|
||||
{
|
||||
throw NormalizationException("“" + unsupported->type + "” expressions as literals can’t be normalized currently");
|
||||
};
|
||||
|
||||
const auto handlePredicate =
|
||||
[&](ast::PredicatePointer &predicate) -> normalizedAST::AtomicFormula
|
||||
{
|
||||
return std::move(predicate);
|
||||
};
|
||||
|
||||
return atomicFormula.match(handlePredicate, handleUnsupported);
|
||||
return atomicFormula.match(handlePredicate);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@@ -28,7 +28,6 @@ normalizedAST::Literal normalizeNestedImpl(ast::ForAllPointer<ast::Precondition>
|
||||
normalizedAST::Literal normalizeNestedImpl(ast::ImplyPointer<ast::Precondition> &, normalizedAST::DerivedPredicateDeclarations &);
|
||||
normalizedAST::Literal normalizeNestedImpl(ast::NotPointer<ast::Precondition> ¬_, normalizedAST::DerivedPredicateDeclarations &derivedPredicates);
|
||||
normalizedAST::Literal normalizeNestedImpl(ast::OrPointer<ast::Precondition> &or_, normalizedAST::DerivedPredicateDeclarations &derivedPredicates);
|
||||
normalizedAST::Literal normalizeNestedImpl(ast::UnsupportedPointer &unsupported, normalizedAST::DerivedPredicateDeclarations &);
|
||||
normalizedAST::Literal normalizeNestedImpl(ast::AtomicFormula &, normalizedAST::DerivedPredicateDeclarations &);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -175,13 +174,6 @@ normalizedAST::Literal normalizeNestedImpl(ast::OrPointer<ast::Precondition> &or
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
normalizedAST::Literal normalizeNestedImpl(ast::UnsupportedPointer &unsupported, normalizedAST::DerivedPredicateDeclarations &)
|
||||
{
|
||||
throw NormalizationException("“" + unsupported->type + "” expressions in preconditions can’t be normalized currently");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
normalizedAST::Literal normalizeNestedImpl(ast::AtomicFormula &atomicFormula, normalizedAST::DerivedPredicateDeclarations &)
|
||||
{
|
||||
return normalize(std::move(atomicFormula));
|
||||
@@ -189,13 +181,6 @@ normalizedAST::Literal normalizeNestedImpl(ast::AtomicFormula &atomicFormula, no
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
normalizedAST::PredicatePointer normalizeImpl(ast::UnsupportedPointer &&unsupported, normalizedAST::DerivedPredicateDeclarations &)
|
||||
{
|
||||
throw NormalizationException("“" + unsupported->type + "” expressions in preconditions can’t be normalized currently");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
normalizedAST::AtomicFormula normalizeImpl(ast::AtomicFormula &&atomicFormula, normalizedAST::DerivedPredicateDeclarations &)
|
||||
{
|
||||
return normalize(std::move(atomicFormula));
|
||||
@@ -252,15 +237,9 @@ normalizedAST::AndPointer<normalizedAST::Literal> normalizeImpl(ast::AndPointer<
|
||||
return normalizeNestedImpl(nested, derivedPredicates);
|
||||
};
|
||||
|
||||
const auto handleUnsupported =
|
||||
[&](ast::UnsupportedPointer &unsupported) -> normalizedAST::Literal
|
||||
{
|
||||
throw NormalizationException("“" + unsupported->type + "” expressions in preconditions can’t be normalized currently");
|
||||
};
|
||||
|
||||
for (auto &&argument : and_->arguments)
|
||||
{
|
||||
auto normalizedArgument = argument.match(handleAtomicFormula, handleNot, handleNested, handleUnsupported);
|
||||
auto normalizedArgument = argument.match(handleAtomicFormula, handleNot, handleNested);
|
||||
|
||||
arguments.emplace_back(std::move(normalizedArgument));
|
||||
}
|
||||
|
@@ -28,14 +28,6 @@ void eliminateDoubleNegations(ast::Precondition &precondition);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const auto handleUnsupported =
|
||||
[](ast::UnsupportedPointer &unsupported)
|
||||
{
|
||||
throw NormalizationException("“" + unsupported->type + "” expressions in preconditions can’t be normalized currently");
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void eliminateImply(ast::Precondition &precondition)
|
||||
{
|
||||
const auto handleAtomicFormula =
|
||||
@@ -89,7 +81,7 @@ void eliminateImply(ast::Precondition &precondition)
|
||||
eliminateImply(argument);
|
||||
};
|
||||
|
||||
precondition.match(handleAtomicFormula, handleAnd, handleExists, handleForAll, handleImply, handleNot, handleOr, handleUnsupported);
|
||||
precondition.match(handleAtomicFormula, handleAnd, handleExists, handleForAll, handleImply, handleNot, handleOr);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -167,7 +159,7 @@ void negationNormalizeNegated(ast::Precondition &precondition, ast::Precondition
|
||||
parent = std::make_unique<ast::And<ast::Precondition>>(std::move(arguments));
|
||||
};
|
||||
|
||||
precondition.match(handleAtomicFormula, handleAnd, handleExists, handleForAll, handleImply, handleNot, handleOr, handleUnsupported);
|
||||
precondition.match(handleAtomicFormula, handleAnd, handleExists, handleForAll, handleImply, handleNot, handleOr);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -217,7 +209,7 @@ void negationNormalize(ast::Precondition &precondition)
|
||||
negationNormalize(argument);
|
||||
};
|
||||
|
||||
precondition.match(handleAtomicFormula, handleAnd, handleExists, handleForAll, handleImply, handleNot, handleOr, handleUnsupported);
|
||||
precondition.match(handleAtomicFormula, handleAnd, handleExists, handleForAll, handleImply, handleNot, handleOr);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -271,7 +263,7 @@ void eliminateForAll(ast::Precondition &precondition)
|
||||
eliminateForAll(argument);
|
||||
};
|
||||
|
||||
precondition.match(handleAtomicFormula, handleAnd, handleExists, handleForAll, handleImply, handleNot, handleOr, handleUnsupported);
|
||||
precondition.match(handleAtomicFormula, handleAnd, handleExists, handleForAll, handleImply, handleNot, handleOr);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -330,7 +322,7 @@ void eliminateDoubleNegations(ast::Precondition &precondition)
|
||||
eliminateDoubleNegations(argument);
|
||||
};
|
||||
|
||||
precondition.match(handleAtomicFormula, handleAnd, handleExists, handleForAll, handleImply, handleNot, handleOr, handleUnsupported);
|
||||
precondition.match(handleAtomicFormula, handleAnd, handleExists, handleForAll, handleImply, handleNot, handleOr);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@@ -26,10 +26,7 @@ std::experimental::optional<ast::AtomicFormula> parseAtomicFormula(Context &cont
|
||||
tokenizer.skipWhiteSpace();
|
||||
|
||||
if (tokenizer.testIdentifierAndReturn("="))
|
||||
{
|
||||
tokenizer.seek(position);
|
||||
return parseUnsupported(context);
|
||||
}
|
||||
throw exceptUnsupportedExpression(position, context);
|
||||
|
||||
tokenizer.seek(position);
|
||||
|
||||
|
@@ -7,6 +7,7 @@
|
||||
#include <pddlparse/detail/parsing/PredicateDeclaration.h>
|
||||
#include <pddlparse/detail/parsing/PrimitiveTypeDeclaration.h>
|
||||
#include <pddlparse/detail/parsing/Requirement.h>
|
||||
#include <pddlparse/detail/parsing/Unsupported.h>
|
||||
#include <pddlparse/detail/parsing/Utils.h>
|
||||
|
||||
namespace pddl
|
||||
@@ -112,8 +113,6 @@ void DomainParser::findSections(ast::Domain &domain)
|
||||
tokenizer.expect<std::string>("(");
|
||||
tokenizer.expect<std::string>(":");
|
||||
|
||||
const auto sectionIdentifierPosition = tokenizer.position();
|
||||
|
||||
// Save the parser position of the individual sections for later parsing
|
||||
if (tokenizer.testIdentifierAndSkip("requirements"))
|
||||
setSectionPosition("requirements", m_requirementsPosition, position, true);
|
||||
@@ -133,13 +132,7 @@ void DomainParser::findSections(ast::Domain &domain)
|
||||
|| tokenizer.testIdentifierAndSkip("durative-action")
|
||||
|| tokenizer.testIdentifierAndSkip("derived"))
|
||||
{
|
||||
tokenizer.seek(sectionIdentifierPosition);
|
||||
|
||||
const auto sectionIdentifier = tokenizer.getIdentifier();
|
||||
|
||||
m_context.warningCallback(tokenizer.location(), "section type “" + sectionIdentifier + "” currently unsupported, ignoring section");
|
||||
|
||||
tokenizer.seek(sectionIdentifierPosition);
|
||||
throw exceptUnsupportedSection(position, m_context);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -64,8 +64,7 @@ std::experimental::optional<ast::Effect> parseEffectBody(Context &context, ASTCo
|
||||
|| tokenizer.testIdentifierAndReturn("increase")
|
||||
|| tokenizer.testIdentifierAndReturn("decrease"))
|
||||
{
|
||||
tokenizer.seek(position);
|
||||
return parseUnsupported(context);
|
||||
throw exceptUnsupportedExpression(position, context);
|
||||
}
|
||||
|
||||
tokenizer.seek(position);
|
||||
@@ -125,8 +124,7 @@ std::experimental::optional<ast::ConditionalEffect> parseConditionalEffectBody(C
|
||||
|| tokenizer.testIdentifierAndReturn("increase")
|
||||
|| tokenizer.testIdentifierAndReturn("decrease"))
|
||||
{
|
||||
tokenizer.seek(position);
|
||||
return parseUnsupported(context);
|
||||
throw exceptUnsupportedExpression(position, context);
|
||||
}
|
||||
|
||||
tokenizer.seek(position);
|
||||
|
@@ -27,10 +27,7 @@ std::experimental::optional<ast::Fact> parseFact(Context &context, ASTContext &a
|
||||
tokenizer.skipWhiteSpace();
|
||||
|
||||
if (tokenizer.testIdentifierAndReturn("="))
|
||||
{
|
||||
tokenizer.seek(position);
|
||||
return parseUnsupported(context);
|
||||
}
|
||||
throw exceptUnsupportedExpression(position, context);
|
||||
|
||||
tokenizer.seek(position);
|
||||
|
||||
@@ -46,10 +43,7 @@ std::experimental::optional<ast::Fact> parseFact(Context &context, ASTContext &a
|
||||
// Test for “at” expressions only now to allow “at” as a predicate name
|
||||
// TODO: allow this in compatibility mode only?
|
||||
if (tokenizer.testIdentifierAndReturn("at"))
|
||||
{
|
||||
tokenizer.seek(position);
|
||||
return parseUnsupported(context);
|
||||
}
|
||||
throw exceptUnsupportedExpression(position, context);
|
||||
|
||||
return std::experimental::nullopt;
|
||||
}
|
||||
|
@@ -29,10 +29,7 @@ std::experimental::optional<ast::Precondition> parsePrecondition(Context &contex
|
||||
tokenizer.expect<std::string>("(");
|
||||
|
||||
if (tokenizer.testIdentifierAndReturn("preference"))
|
||||
{
|
||||
tokenizer.seek(position);
|
||||
return parseUnsupported(context);
|
||||
}
|
||||
throw exceptUnsupportedExpression(position, context);
|
||||
|
||||
tokenizer.seek(position);
|
||||
|
||||
@@ -75,8 +72,7 @@ std::experimental::optional<ast::Precondition> parsePreconditionBody(Context &co
|
||||
|| tokenizer.testIdentifierAndReturn(">=")
|
||||
|| tokenizer.testIdentifierAndReturn("<="))
|
||||
{
|
||||
tokenizer.seek(position);
|
||||
return parseUnsupported(context);
|
||||
throw exceptUnsupportedExpression(position, context);
|
||||
}
|
||||
|
||||
tokenizer.seek(position);
|
||||
|
@@ -6,6 +6,7 @@
|
||||
#include <pddlparse/detail/parsing/InitialState.h>
|
||||
#include <pddlparse/detail/parsing/Precondition.h>
|
||||
#include <pddlparse/detail/parsing/Requirement.h>
|
||||
#include <pddlparse/detail/parsing/Unsupported.h>
|
||||
#include <pddlparse/detail/parsing/Utils.h>
|
||||
|
||||
namespace pddl
|
||||
@@ -109,8 +110,6 @@ void ProblemParser::findSections(ast::Problem &problem)
|
||||
tokenizer.expect<std::string>("(");
|
||||
tokenizer.expect<std::string>(":");
|
||||
|
||||
const auto sectionIdentifierPosition = tokenizer.position();
|
||||
|
||||
if (tokenizer.testIdentifierAndSkip("domain"))
|
||||
setSectionPosition("domain", m_domainPosition, position, true);
|
||||
else if (tokenizer.testIdentifierAndSkip("requirements"))
|
||||
@@ -125,13 +124,7 @@ void ProblemParser::findSections(ast::Problem &problem)
|
||||
|| tokenizer.testIdentifierAndSkip("metric")
|
||||
|| tokenizer.testIdentifierAndSkip("length"))
|
||||
{
|
||||
tokenizer.seek(sectionIdentifierPosition);
|
||||
|
||||
const auto sectionIdentifier = tokenizer.getIdentifier();
|
||||
|
||||
m_context.warningCallback(tokenizer.location(), "section type “" + sectionIdentifier + "” currently unsupported, ignoring section");
|
||||
|
||||
tokenizer.seek(sectionIdentifierPosition);
|
||||
throw exceptUnsupportedSection(position, m_context);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -14,19 +14,29 @@ namespace detail
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ast::UnsupportedPointer parseUnsupported(Context &context)
|
||||
ParserException exceptUnsupportedExpression(tokenize::StreamPosition position, Context &context)
|
||||
{
|
||||
auto &tokenizer = context.tokenizer;
|
||||
|
||||
tokenizer.seek(position);
|
||||
tokenizer.expect<std::string>("(");
|
||||
|
||||
auto expressionType = tokenizer.getIdentifier();
|
||||
|
||||
context.warningCallback(tokenizer.location(), "expression type “" + expressionType + "” currently unsupported in this context, substituting it with placeholder");
|
||||
return ParserException(tokenizer.location(position), "“" + expressionType + "” expressions currently unsupported");
|
||||
}
|
||||
|
||||
skipSection(tokenizer);
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
return std::make_unique<ast::Unsupported>(std::move(expressionType));
|
||||
ParserException exceptUnsupportedSection(tokenize::StreamPosition position, Context &context)
|
||||
{
|
||||
auto &tokenizer = context.tokenizer;
|
||||
|
||||
tokenizer.seek(position);
|
||||
tokenizer.expect<std::string>("(");
|
||||
tokenizer.expect<std::string>(":");
|
||||
auto sectionType = tokenizer.getIdentifier();
|
||||
|
||||
return ParserException(tokenizer.location(position), "“:" + sectionType + "” sections currently unsupported");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
Reference in New Issue
Block a user