Throwing exceptions for unsupported features instead of silently accepting them.
This commit is contained in:
@@ -96,23 +96,6 @@ struct PrimitiveTypeDeclaration
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Unsupported
|
||||
{
|
||||
explicit Unsupported(std::string &&type)
|
||||
: type{std::move(type)}
|
||||
{
|
||||
}
|
||||
|
||||
Unsupported(const Unsupported &other) = delete;
|
||||
Unsupported &operator=(const Unsupported &&other) = delete;
|
||||
Unsupported(Unsupported &&other) = default;
|
||||
Unsupported &operator=(Unsupported &&other) = default;
|
||||
|
||||
std::string type;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Variable
|
||||
{
|
||||
explicit Variable(VariableDeclaration *declaration)
|
||||
|
@@ -36,8 +36,6 @@ using PrimitiveTypes = std::vector<PrimitiveTypePointer>;
|
||||
struct PrimitiveTypeDeclaration;
|
||||
using PrimitiveTypeDeclarationPointer = std::unique_ptr<PrimitiveTypeDeclaration>;
|
||||
using PrimitiveTypeDeclarations = std::vector<PrimitiveTypeDeclarationPointer>;
|
||||
struct Unsupported;
|
||||
using UnsupportedPointer = std::unique_ptr<Unsupported>;
|
||||
struct Variable;
|
||||
using VariablePointer = std::unique_ptr<Variable>;
|
||||
using Variables = std::vector<VariablePointer>;
|
||||
@@ -138,9 +136,9 @@ using Terms = std::vector<Term>;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
// TODO: add missing types
|
||||
using AtomicFormulaT = Variant<
|
||||
PredicatePointer,
|
||||
UnsupportedPointer>;
|
||||
PredicatePointer>;
|
||||
}
|
||||
|
||||
class AtomicFormula : public detail::AtomicFormulaT
|
||||
@@ -156,6 +154,7 @@ class Precondition;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
// TODO: add missing types
|
||||
using PreconditionT = Variant<
|
||||
AtomicFormula,
|
||||
AndPointer<Precondition>,
|
||||
@@ -163,8 +162,7 @@ using PreconditionT = Variant<
|
||||
ForAllPointer<Precondition>,
|
||||
ImplyPointer<Precondition>,
|
||||
NotPointer<Precondition>,
|
||||
OrPointer<Precondition>,
|
||||
UnsupportedPointer>;
|
||||
OrPointer<Precondition>>;
|
||||
}
|
||||
|
||||
class Precondition : public detail::PreconditionT
|
||||
@@ -182,11 +180,11 @@ class ConditionalEffect;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
// TODO: add missing types
|
||||
using ConditionalEffectT = Variant<
|
||||
AtomicFormula,
|
||||
AndPointer<ConditionalEffect>,
|
||||
NotPointer<ConditionalEffect>,
|
||||
UnsupportedPointer>;
|
||||
NotPointer<ConditionalEffect>>;
|
||||
}
|
||||
|
||||
class ConditionalEffect : public detail::ConditionalEffectT
|
||||
@@ -202,13 +200,13 @@ class Effect;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
// TODO: add missing types
|
||||
using EffectT = Variant<
|
||||
AtomicFormula,
|
||||
AndPointer<Effect>,
|
||||
ForAllPointer<Effect>,
|
||||
NotPointer<Effect>,
|
||||
WhenPointer<Precondition, ConditionalEffect>,
|
||||
UnsupportedPointer>;
|
||||
WhenPointer<Precondition, ConditionalEffect>>;
|
||||
}
|
||||
|
||||
class Effect : public detail::EffectT
|
||||
|
@@ -110,15 +110,6 @@ inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Primiti
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Unsupported &unsupported, pddl::detail::PrintContext &)
|
||||
{
|
||||
const auto unsupportedName = "<unsupported " + unsupported.type + ">";
|
||||
|
||||
return (stream << colorlog::Reserved(unsupportedName.c_str()));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Variable &variable, pddl::detail::PrintContext &)
|
||||
{
|
||||
const auto variableName = "?" + variable.declaration->name;
|
||||
|
@@ -115,13 +115,6 @@ void collectFreeVariables(const ast::OrPointer<Argument> &or_, std::vector<norma
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline void collectFreeVariables(const ast::UnsupportedPointer &unsupported, std::vector<normalizedAST::VariableDeclaration *> &, VariableStack &)
|
||||
{
|
||||
throw NormalizationException("cannot collect free variables of unsupported “" + unsupported->type + "” expression");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,8 +1,8 @@
|
||||
#ifndef __PDDL_PARSE__DETAIL__PARSING__UNSUPPORTED_H
|
||||
#define __PDDL_PARSE__DETAIL__PARSING__UNSUPPORTED_H
|
||||
|
||||
#include <pddlparse/ASTForward.h>
|
||||
#include <pddlparse/Context.h>
|
||||
#include <pddlparse/Exception.h>
|
||||
|
||||
namespace pddl
|
||||
{
|
||||
@@ -15,7 +15,8 @@ namespace detail
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ast::UnsupportedPointer parseUnsupported(Context &context);
|
||||
ParserException exceptUnsupportedExpression(tokenize::StreamPosition position, Context &context);
|
||||
ParserException exceptUnsupportedSection(tokenize::StreamPosition position, Context &context);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
Reference in New Issue
Block a user