Started reimplementing problem parser.
This commit is contained in:
@@ -26,7 +26,7 @@ namespace ast
|
||||
|
||||
struct Constant
|
||||
{
|
||||
explicit Constant(ConstantDeclaration &declaration)
|
||||
explicit Constant(ConstantDeclaration *declaration)
|
||||
: declaration{declaration}
|
||||
{
|
||||
}
|
||||
@@ -36,7 +36,7 @@ struct Constant
|
||||
Constant(Constant &&other) = default;
|
||||
Constant &operator=(Constant &&other) = default;
|
||||
|
||||
ConstantDeclaration &declaration;
|
||||
ConstantDeclaration *declaration;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -51,8 +51,8 @@ struct ConstantDeclaration
|
||||
|
||||
ConstantDeclaration(const ConstantDeclaration &other) = delete;
|
||||
ConstantDeclaration &operator=(const ConstantDeclaration &&other) = delete;
|
||||
ConstantDeclaration(ConstantDeclaration &&other) = default;
|
||||
ConstantDeclaration &operator=(ConstantDeclaration &&other) = default;
|
||||
ConstantDeclaration(ConstantDeclaration &&other) = delete;
|
||||
ConstantDeclaration &operator=(ConstantDeclaration &&other) = delete;
|
||||
|
||||
std::string name;
|
||||
std::experimental::optional<Type> type;
|
||||
@@ -79,7 +79,7 @@ struct Dummy
|
||||
|
||||
struct PrimitiveType
|
||||
{
|
||||
explicit PrimitiveType(PrimitiveTypeDeclaration &declaration)
|
||||
explicit PrimitiveType(PrimitiveTypeDeclaration *declaration)
|
||||
: declaration{declaration}
|
||||
{
|
||||
}
|
||||
@@ -89,7 +89,7 @@ struct PrimitiveType
|
||||
PrimitiveType(PrimitiveType &&other) = default;
|
||||
PrimitiveType &operator=(PrimitiveType &&other) = default;
|
||||
|
||||
PrimitiveTypeDeclaration &declaration;
|
||||
PrimitiveTypeDeclaration *declaration;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -103,11 +103,11 @@ struct PrimitiveTypeDeclaration
|
||||
|
||||
PrimitiveTypeDeclaration(const PrimitiveTypeDeclaration &other) = delete;
|
||||
PrimitiveTypeDeclaration &operator=(const PrimitiveTypeDeclaration &&other) = delete;
|
||||
PrimitiveTypeDeclaration(PrimitiveTypeDeclaration &&other) = default;
|
||||
PrimitiveTypeDeclaration &operator=(PrimitiveTypeDeclaration &&other) = default;
|
||||
PrimitiveTypeDeclaration(PrimitiveTypeDeclaration &&other) = delete;
|
||||
PrimitiveTypeDeclaration &operator=(PrimitiveTypeDeclaration &&other) = delete;
|
||||
|
||||
std::string name;
|
||||
std::vector<PrimitiveType> parentTypes;
|
||||
std::vector<PrimitiveTypePointer> parentTypes;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -127,7 +127,7 @@ struct Unsupported
|
||||
|
||||
struct Variable
|
||||
{
|
||||
explicit Variable(VariableDeclaration &declaration)
|
||||
explicit Variable(VariableDeclaration *declaration)
|
||||
: declaration{declaration}
|
||||
{
|
||||
}
|
||||
@@ -137,7 +137,7 @@ struct Variable
|
||||
Variable(Variable &&other) = default;
|
||||
Variable &operator=(Variable &&other) = default;
|
||||
|
||||
VariableDeclaration &declaration;
|
||||
VariableDeclaration *declaration;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -152,8 +152,8 @@ struct VariableDeclaration
|
||||
|
||||
VariableDeclaration(const VariableDeclaration &other) = delete;
|
||||
VariableDeclaration &operator=(const VariableDeclaration &&other) = delete;
|
||||
VariableDeclaration(VariableDeclaration &&other) = default;
|
||||
VariableDeclaration &operator=(VariableDeclaration &&other) = default;
|
||||
VariableDeclaration(VariableDeclaration &&other) = delete;
|
||||
VariableDeclaration &operator=(VariableDeclaration &&other) = delete;
|
||||
|
||||
std::string name;
|
||||
std::experimental::optional<Type> type;
|
||||
@@ -165,7 +165,7 @@ struct VariableDeclaration
|
||||
|
||||
struct Predicate
|
||||
{
|
||||
explicit Predicate(PredicateDeclaration &declaration)
|
||||
explicit Predicate(PredicateDeclaration *declaration)
|
||||
: declaration{declaration}
|
||||
{
|
||||
}
|
||||
@@ -176,8 +176,7 @@ struct Predicate
|
||||
Predicate &operator=(Predicate &&other) = default;
|
||||
|
||||
Terms arguments;
|
||||
|
||||
PredicateDeclaration &declaration;
|
||||
PredicateDeclaration *declaration;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -416,9 +415,9 @@ struct Action
|
||||
|
||||
std::string name;
|
||||
|
||||
ast::VariableDeclarations parameters;
|
||||
std::experimental::optional<ast::Precondition> precondition;
|
||||
std::experimental::optional<ast::Effect> effect;
|
||||
VariableDeclarations parameters;
|
||||
std::experimental::optional<Precondition> precondition;
|
||||
std::experimental::optional<Effect> effect;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -429,15 +428,15 @@ struct Domain
|
||||
|
||||
Domain(const Domain &other) = delete;
|
||||
Domain &operator=(const Domain &&other) = delete;
|
||||
Domain(Domain &&other) = default;
|
||||
Domain &operator=(Domain &&other) = default;
|
||||
Domain(Domain &&other) = delete;
|
||||
Domain &operator=(Domain &&other) = delete;
|
||||
|
||||
std::string name;
|
||||
Requirements requirements;
|
||||
ast::PrimitiveTypeDeclarations types;
|
||||
ast::ConstantDeclarations constants;
|
||||
ast::PredicateDeclarations predicates;
|
||||
std::vector<Action> actions;
|
||||
PrimitiveTypeDeclarations types;
|
||||
ConstantDeclarations constants;
|
||||
PredicateDeclarations predicates;
|
||||
Actions actions;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -451,7 +450,7 @@ struct InitialState
|
||||
InitialState(InitialState &&other) = default;
|
||||
InitialState &operator=(InitialState &&other) = default;
|
||||
|
||||
ast::Facts facts;
|
||||
Facts facts;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -460,17 +459,22 @@ struct Problem
|
||||
{
|
||||
Problem() = default;
|
||||
|
||||
Problem(Domain *domain)
|
||||
: domain{domain}
|
||||
{
|
||||
}
|
||||
|
||||
Problem(const Problem &other) = delete;
|
||||
Problem &operator=(const Problem &&other) = delete;
|
||||
Problem(Problem &&other) = default;
|
||||
Problem &operator=(Problem &&other) = default;
|
||||
|
||||
Domain &domain;
|
||||
Domain *domain;
|
||||
std::string name;
|
||||
Requirements requirements;
|
||||
ast::ConstantDeclarations objects;
|
||||
ConstantDeclarations objects;
|
||||
InitialState initialState;
|
||||
std::experimental::optional<ast::Goal> goal;
|
||||
std::experimental::optional<Goal> goal;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -512,8 +516,8 @@ struct Description
|
||||
Description(Description &&other) = default;
|
||||
Description &operator=(Description &&other) = default;
|
||||
|
||||
Domain domain;
|
||||
std::experimental::optional<Problem> problem;
|
||||
DomainPointer domain;
|
||||
std::experimental::optional<ProblemPointer> problem;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@@ -26,27 +26,37 @@ namespace ast
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Constant;
|
||||
using ConstantPointer = std::unique_ptr<Constant>;
|
||||
struct ConstantDeclaration;
|
||||
using ConstantDeclarations = std::vector<ConstantDeclaration>;
|
||||
using ConstantDeclarationPointer = std::unique_ptr<ConstantDeclaration>;
|
||||
using ConstantDeclarations = std::vector<ConstantDeclarationPointer>;
|
||||
struct Dummy;
|
||||
using DummyPointer = std::unique_ptr<Dummy>;
|
||||
struct PrimitiveType;
|
||||
using PrimitiveTypes = std::vector<PrimitiveType>;
|
||||
using PrimitiveTypePointer = std::unique_ptr<PrimitiveType>;
|
||||
using PrimitiveTypes = std::vector<PrimitiveTypePointer>;
|
||||
struct PrimitiveTypeDeclaration;
|
||||
using PrimitiveTypeDeclarations = std::vector<PrimitiveTypeDeclaration>;
|
||||
using PrimitiveTypeDeclarationPointer = std::unique_ptr<PrimitiveTypeDeclaration>;
|
||||
using PrimitiveTypeDeclarations = std::vector<PrimitiveTypeDeclarationPointer>;
|
||||
struct Unsupported;
|
||||
using UnsupportedPointer = std::unique_ptr<Unsupported>;
|
||||
struct Variable;
|
||||
using Variables = std::vector<Variable>;
|
||||
using VariablePointer = std::unique_ptr<Variable>;
|
||||
using Variables = std::vector<VariablePointer>;
|
||||
struct VariableDeclaration;
|
||||
using VariableDeclarations = std::vector<VariableDeclaration>;
|
||||
using VariableDeclarationPointer = std::unique_ptr<VariableDeclaration>;
|
||||
using VariableDeclarations = std::vector<VariableDeclarationPointer>;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Compounds
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Predicate;
|
||||
using Predicates = std::vector<Predicate>;
|
||||
using PredicatePointer = std::unique_ptr<Predicate>;
|
||||
using Predicates = std::vector<PredicatePointer>;
|
||||
struct PredicateDeclaration;
|
||||
using PredicateDeclarations = std::vector<PredicateDeclaration>;
|
||||
using PredicateDeclarationPointer = std::unique_ptr<PredicateDeclaration>;
|
||||
using PredicateDeclarations = std::vector<PredicateDeclarationPointer>;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Expressions
|
||||
@@ -55,29 +65,53 @@ using PredicateDeclarations = std::vector<PredicateDeclaration>;
|
||||
template<class Argument>
|
||||
struct And;
|
||||
template<class Argument>
|
||||
using AndPointer = std::unique_ptr<And<Argument>>;
|
||||
template<class Argument>
|
||||
struct At;
|
||||
template<class Argument>
|
||||
using AtPointer = std::unique_ptr<At<Argument>>;
|
||||
template<class Argument>
|
||||
struct Either;
|
||||
template<class Argument>
|
||||
using EitherPointer = std::unique_ptr<Either<Argument>>;
|
||||
template<class Argument>
|
||||
struct Exists;
|
||||
template<class Argument>
|
||||
using ExistsPointer = std::unique_ptr<Exists<Argument>>;
|
||||
template<class Argument>
|
||||
struct ForAll;
|
||||
template<class Argument>
|
||||
using ForAllPointer = std::unique_ptr<ForAll<Argument>>;
|
||||
template<class Argument>
|
||||
struct Imply;
|
||||
template<class Argument>
|
||||
using ImplyPointer = std::unique_ptr<Imply<Argument>>;
|
||||
template<class Argument>
|
||||
struct Not;
|
||||
template<class Argument>
|
||||
using NotPointer = std::unique_ptr<Not<Argument>>;
|
||||
template<class Argument>
|
||||
struct Or;
|
||||
template<class Argument>
|
||||
using OrPointer = std::unique_ptr<Or<Argument>>;
|
||||
template<class ArgumentLeft, class ArgumentRight>
|
||||
struct When;
|
||||
template<class ArgumentLeft, class ArgumentRight>
|
||||
using WhenPointer = std::unique_ptr<When<ArgumentLeft, ArgumentRight>>;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PDDL Structure
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Action;
|
||||
using ActionPointer = std::unique_ptr<Action>;
|
||||
using Actions = std::vector<ActionPointer>;
|
||||
struct Description;
|
||||
using DescriptionPointer = std::unique_ptr<Description>;
|
||||
struct Domain;
|
||||
using DomainPointer = std::unique_ptr<Domain>;
|
||||
struct Problem;
|
||||
using ProblemPointer = std::unique_ptr<Problem>;
|
||||
enum class Requirement;
|
||||
using Requirements = std::vector<Requirement>;
|
||||
|
||||
@@ -88,8 +122,8 @@ using Requirements = std::vector<Requirement>;
|
||||
namespace detail
|
||||
{
|
||||
using TermT = Variant<
|
||||
Constant,
|
||||
Variable>;
|
||||
ConstantPointer,
|
||||
VariablePointer>;
|
||||
}
|
||||
|
||||
class Term : public detail::TermT
|
||||
@@ -104,8 +138,8 @@ using Terms = std::vector<Term>;
|
||||
namespace detail
|
||||
{
|
||||
using AtomicFormulaT = Variant<
|
||||
Predicate,
|
||||
Unsupported>;
|
||||
PredicatePointer,
|
||||
UnsupportedPointer>;
|
||||
}
|
||||
|
||||
class AtomicFormula : public detail::AtomicFormulaT
|
||||
@@ -121,13 +155,13 @@ namespace detail
|
||||
{
|
||||
using PreconditionT = Variant<
|
||||
AtomicFormula,
|
||||
And<Precondition>,
|
||||
Exists<Precondition>,
|
||||
ForAll<Precondition>,
|
||||
Imply<Precondition>,
|
||||
Not<Precondition>,
|
||||
Or<Precondition>,
|
||||
Unsupported>;
|
||||
AndPointer<Precondition>,
|
||||
ExistsPointer<Precondition>,
|
||||
ForAllPointer<Precondition>,
|
||||
ImplyPointer<Precondition>,
|
||||
NotPointer<Precondition>,
|
||||
OrPointer<Precondition>,
|
||||
UnsupportedPointer>;
|
||||
}
|
||||
|
||||
class Precondition : public detail::PreconditionT
|
||||
@@ -145,11 +179,11 @@ namespace detail
|
||||
{
|
||||
using EffectT = Variant<
|
||||
AtomicFormula,
|
||||
And<Effect>,
|
||||
ForAll<Effect>,
|
||||
Not<Effect>,
|
||||
When<Precondition, Effect>,
|
||||
Unsupported>;
|
||||
AndPointer<Effect>,
|
||||
ForAllPointer<Effect>,
|
||||
NotPointer<Effect>,
|
||||
WhenPointer<Precondition, Effect>,
|
||||
UnsupportedPointer>;
|
||||
}
|
||||
|
||||
class Effect : public detail::EffectT
|
||||
@@ -162,8 +196,8 @@ class Effect : public detail::EffectT
|
||||
namespace detail
|
||||
{
|
||||
using TypeT = Variant<
|
||||
Either<PrimitiveType>,
|
||||
PrimitiveType>;
|
||||
EitherPointer<PrimitiveTypePointer>,
|
||||
PrimitiveTypePointer>;
|
||||
}
|
||||
|
||||
class Type : public detail::TypeT
|
||||
@@ -177,7 +211,7 @@ namespace detail
|
||||
{
|
||||
using LiteralT = Variant<
|
||||
AtomicFormula,
|
||||
Not<AtomicFormula>>;
|
||||
NotPointer<AtomicFormula>>;
|
||||
}
|
||||
|
||||
class Literal : public detail::LiteralT
|
||||
@@ -193,7 +227,7 @@ namespace detail
|
||||
{
|
||||
using FactT = Variant<
|
||||
AtomicFormula,
|
||||
At<Literal>>;
|
||||
AtPointer<Literal>>;
|
||||
}
|
||||
|
||||
class Fact : public detail::FactT
|
||||
|
49
lib/pddlparse/include/pddlparse/Context.h
Normal file
49
lib/pddlparse/include/pddlparse/Context.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef __PDDL_PARSE__CONTEXT_H
|
||||
#define __PDDL_PARSE__CONTEXT_H
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <pddlparse/Tokenizer.h>
|
||||
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Context
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Context
|
||||
{
|
||||
constexpr static const char *auxiliaryPrefix()
|
||||
{
|
||||
return "__plasp_";
|
||||
}
|
||||
|
||||
// TODO: replace std::string with char *
|
||||
using WarningCallback = std::function<void (tokenize::Location, const std::string &)>;
|
||||
|
||||
Context() = default;
|
||||
~Context() = default;
|
||||
|
||||
explicit Context(Tokenizer &&tokenizer, WarningCallback warningCallback)
|
||||
: tokenizer{std::move(tokenizer)},
|
||||
warningCallback{warningCallback}
|
||||
{
|
||||
}
|
||||
|
||||
Context(const Context &other) = delete;
|
||||
Context &operator=(const Context &other) = delete;
|
||||
Context(Context &&other) = default;
|
||||
Context &operator=(Context &&other) = default;
|
||||
|
||||
Tokenizer tokenizer;
|
||||
WarningCallback warningCallback;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
|
||||
#endif
|
24
lib/pddlparse/include/pddlparse/Parse.h
Normal file
24
lib/pddlparse/include/pddlparse/Parse.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef __PDDL_PARSE__PARSE_H
|
||||
#define __PDDL_PARSE__PARSE_H
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
#include <pddlparse/ASTForward.h>
|
||||
#include <pddlparse/Context.h>
|
||||
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Parse
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ast::Description parseDescription(Context &context);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,233 +1,20 @@
|
||||
#ifndef __PDDL_PARSE__VARIANT_H
|
||||
#define __PDDL_PARSE__VARIANT_H
|
||||
|
||||
#include <cassert>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <type_traits>
|
||||
#include <mapbox/variant.hpp>
|
||||
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Variant (from clingo, written by Roland Kaminski)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <class T, class... U>
|
||||
struct TypeInList : std::false_type { };
|
||||
|
||||
template <class T, class... U>
|
||||
struct TypeInList<T, T, U...> : std::true_type { };
|
||||
|
||||
template <class T, class V, class... U>
|
||||
struct TypeInList<T, V, U...> : TypeInList<T, U...> { };
|
||||
|
||||
template <unsigned, class... U>
|
||||
struct VariantHolder;
|
||||
|
||||
template <unsigned n>
|
||||
struct VariantHolder<n> {
|
||||
bool check_type() const { return type_ == 0; }
|
||||
void emplace() { }
|
||||
void emplace2() { }
|
||||
void copy(VariantHolder const &) { }
|
||||
void destroy() {
|
||||
type_ = 0;
|
||||
data_ = nullptr;
|
||||
}
|
||||
void print(std::ostream &) const { }
|
||||
void swap(VariantHolder &other) {
|
||||
std::swap(type_, other.type_);
|
||||
std::swap(data_, other.data_);
|
||||
}
|
||||
unsigned type_ = 0;
|
||||
void *data_ = nullptr;
|
||||
};
|
||||
|
||||
template <unsigned n, class T, class... U>
|
||||
struct VariantHolder<n, T, U...> : VariantHolder<n+1, U...>{
|
||||
using Helper = VariantHolder<n+1, U...>;
|
||||
using Helper::check_type;
|
||||
using Helper::emplace;
|
||||
using Helper::emplace2;
|
||||
using Helper::data_;
|
||||
using Helper::type_;
|
||||
bool check_type(T *) const { return type_ == n; }
|
||||
template <class... Args>
|
||||
void emplace(T *, Args&& ...x) {
|
||||
data_ = new T{std::forward<Args>(x)...};
|
||||
type_ = n;
|
||||
}
|
||||
// NOTE: http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1467
|
||||
template <class... Args>
|
||||
void emplace2(T *, Args&& ...x) {
|
||||
data_ = new T(std::forward<Args>(x)...);
|
||||
type_ = n;
|
||||
}
|
||||
void copy(VariantHolder const &src) {
|
||||
if (src.type_ == n) {
|
||||
data_ = new T(*static_cast<T const*>(src.data_));
|
||||
type_ = src.type_;
|
||||
}
|
||||
Helper::copy(src);
|
||||
}
|
||||
// NOTE: workaround for visual studio (C++14 can also simply use auto)
|
||||
# define CLINGO_VARIANT_RETURN(Type) decltype(std::declval<V>().visit(std::declval<Type&>(), std::declval<Args>()...))
|
||||
template <class V, class... Args>
|
||||
using Ret_ = CLINGO_VARIANT_RETURN(T);
|
||||
template <class V, class... Args>
|
||||
using ConstRet_ = CLINGO_VARIANT_RETURN(T const);
|
||||
// non-const
|
||||
template <class V, class U1, class... U2, class... Args>
|
||||
auto accept_(V &&visitor, Args &&... args) -> CLINGO_VARIANT_RETURN(T) {
|
||||
static_assert(std::is_same<Ret_<V, Args...>, typename Helper::template Ret_<V, Args...>>::value, "");
|
||||
return n == type_
|
||||
? visitor.visit(*static_cast<T*>(data_), std::forward<Args>(args)...)
|
||||
: Helper::template accept<V>(std::forward<V>(visitor), std::forward<Args>(args)...);
|
||||
}
|
||||
template <class V, class... Args>
|
||||
auto accept_(V &&visitor, Args &&... args) -> CLINGO_VARIANT_RETURN(T) {
|
||||
assert(n == type_);
|
||||
return visitor.visit(*static_cast<T*>(data_), std::forward<Args>(args)...);
|
||||
}
|
||||
template <class V, class... Args>
|
||||
auto accept(V &&visitor, Args &&... args) -> CLINGO_VARIANT_RETURN(T) {
|
||||
return accept_<V, U...>(std::forward<V>(visitor), std::forward<Args>(args)...);
|
||||
}
|
||||
// const
|
||||
template <class V, class U1, class... U2, class... Args>
|
||||
auto accept_(V &&visitor, Args &&... args) const -> CLINGO_VARIANT_RETURN(T const) {
|
||||
static_assert(std::is_same<ConstRet_<V, Args...>, typename Helper::template ConstRet_<V, Args...>>::value, "");
|
||||
return n == type_
|
||||
? visitor.visit(*static_cast<T const *>(data_), std::forward<Args>(args)...)
|
||||
: Helper::template accept<V>(std::forward<V>(visitor), std::forward<Args>(args)...);
|
||||
}
|
||||
template <class V, class... Args>
|
||||
auto accept_(V &&visitor, Args &&... args) const -> CLINGO_VARIANT_RETURN(T const) {
|
||||
assert(n == type_);
|
||||
return visitor.visit(*static_cast<T const *>(data_), std::forward<Args>(args)...);
|
||||
}
|
||||
template <class V, class... Args>
|
||||
auto accept(V &&visitor, Args &&... args) const -> CLINGO_VARIANT_RETURN(T const) {
|
||||
return accept_<V, U...>(std::forward<V>(visitor), std::forward<Args>(args)...);
|
||||
}
|
||||
# undef CLINGO_VARIANT_RETURN
|
||||
void destroy() {
|
||||
if (n == type_) { delete static_cast<T*>(data_); }
|
||||
Helper::destroy();
|
||||
}
|
||||
void print(std::ostream &out) const {
|
||||
if (n == type_) { out << *static_cast<T const*>(data_); }
|
||||
Helper::print(out);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
template <class... T>
|
||||
class Variant {
|
||||
using Holder = detail::VariantHolder<1, T...>;
|
||||
public:
|
||||
Variant(Variant const &other) : Variant(other.data_) { }
|
||||
Variant(Variant &&other) noexcept { data_.swap(other.data_); }
|
||||
template <class U>
|
||||
Variant(U &&u, typename std::enable_if<detail::TypeInList<U, T...>::value>::type * = nullptr) { emplace2<U>(std::forward<U>(u)); }
|
||||
template <class U>
|
||||
Variant(U &u, typename std::enable_if<detail::TypeInList<U, T...>::value>::type * = nullptr) { emplace2<U>(u); }
|
||||
template <class U>
|
||||
Variant(U const &u, typename std::enable_if<detail::TypeInList<U, T...>::value>::type * = nullptr) { emplace2<U>(u); }
|
||||
template <class U, class... Args>
|
||||
static Variant make(Args&& ...args) {
|
||||
Variant<T...> x;
|
||||
x.data_.emplace(static_cast<U*>(nullptr), std::forward<Args>(args)...);
|
||||
return std::move(x);
|
||||
}
|
||||
~Variant() { data_.destroy(); }
|
||||
Variant &operator=(Variant const &other) { return *this = other.data_; }
|
||||
Variant &operator=(Variant &&other) noexcept { return *this = std::move(other.data_); }
|
||||
template <class U>
|
||||
typename std::enable_if<detail::TypeInList<U, T...>::value, Variant>::type &operator=(U &&u) {
|
||||
emplace2<U>(std::forward<U>(u));
|
||||
return *this;
|
||||
}
|
||||
template <class U>
|
||||
typename std::enable_if<detail::TypeInList<U, T...>::value, Variant>::type &operator=(U &u) {
|
||||
emplace2<U>(u);
|
||||
return *this;
|
||||
}
|
||||
template <class U>
|
||||
typename std::enable_if<detail::TypeInList<U, T...>::value, Variant>::type &operator=(U const &u) {
|
||||
emplace2<U>(u);
|
||||
return *this;
|
||||
}
|
||||
template <class U>
|
||||
U &get() {
|
||||
if (!data_.check_type(static_cast<U*>(nullptr))) { throw std::bad_cast(); }
|
||||
return *static_cast<U*>(data_.data_);
|
||||
}
|
||||
template <class U>
|
||||
U const &get() const {
|
||||
if (!data_.check_type(static_cast<U*>(nullptr))) { throw std::bad_cast(); }
|
||||
return *static_cast<U*>(data_.data_);
|
||||
}
|
||||
template <class U, class... Args>
|
||||
void emplace(Args&& ...args) {
|
||||
Variant<T...> x;
|
||||
x.data_.emplace(static_cast<U*>(nullptr), std::forward<Args>(args)...);
|
||||
data_.swap(x.data_);
|
||||
}
|
||||
template <class U>
|
||||
bool is() const { return data_.check_type(static_cast<U*>(nullptr)); }
|
||||
void swap(Variant &other) { data_.swap(other.data_); }
|
||||
template <class V, class... Args>
|
||||
typename Holder::template Ret_<V, Args...> accept(V &&visitor, Args &&... args) {
|
||||
return data_.accept(std::forward<V>(visitor), std::forward<Args>(args)...);
|
||||
}
|
||||
template <class V, class... Args>
|
||||
typename Holder::template ConstRet_<V, Args...> accept(V &&visitor, Args &&... args) const {
|
||||
return data_.accept(std::forward<V>(visitor), std::forward<Args>(args)...);
|
||||
}
|
||||
friend std::ostream &operator<<(std::ostream &out, Variant const &x) {
|
||||
x.data_.print(out);
|
||||
return out;
|
||||
}
|
||||
|
||||
private:
|
||||
Variant() { }
|
||||
Variant(Holder const &data) {
|
||||
data_.copy(data);
|
||||
}
|
||||
Variant &operator=(Holder const &data) {
|
||||
Variant x(data);
|
||||
data_.swap(x.data_);
|
||||
return *this;
|
||||
}
|
||||
Variant &operator=(Holder &&data) noexcept {
|
||||
Holder x;
|
||||
x.swap(data);
|
||||
// Destroy the old data_ only after securing the new data
|
||||
// Otherwise, data would be destroyed together with data_ if it was a descendant of data_
|
||||
data_.destroy();
|
||||
x.swap(data_);
|
||||
return *this;
|
||||
}
|
||||
template <class U, class... Args>
|
||||
void emplace2(Args&& ...args) {
|
||||
Variant<T...> x;
|
||||
x.data_.emplace2(static_cast<U*>(nullptr), std::forward<Args>(args)...);
|
||||
data_.swap(x.data_);
|
||||
}
|
||||
|
||||
private:
|
||||
Holder data_;
|
||||
};
|
||||
template<class... Types>
|
||||
using Variant = mapbox::util::variant<Types...>;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif
|
||||
|
48
lib/pddlparse/include/pddlparse/detail/ASTContext.h
Normal file
48
lib/pddlparse/include/pddlparse/detail/ASTContext.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#ifndef __PDDL_PARSE__DETAIL__AST_CONTEXT_H
|
||||
#define __PDDL_PARSE__DETAIL__AST_CONTEXT_H
|
||||
|
||||
#include <pddlparse/AST.h>
|
||||
#include <pddlparse/detail/VariableStack.h>
|
||||
|
||||
namespace pddl
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// ASTContext
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct ASTContext
|
||||
{
|
||||
ASTContext(ast::Description &description)
|
||||
: domain{description.domain.get()},
|
||||
problem{description.problem.value() ? std::experimental::optional<ast::Problem *>(description.problem.value().get()) : std::experimental::nullopt}
|
||||
{
|
||||
}
|
||||
|
||||
ASTContext(ast::Domain &domain)
|
||||
: domain{&domain}
|
||||
{
|
||||
}
|
||||
|
||||
ASTContext(ast::Problem &problem)
|
||||
: domain{problem.domain},
|
||||
problem{&problem}
|
||||
{
|
||||
}
|
||||
|
||||
ast::Domain *domain;
|
||||
std::experimental::optional<ast::Problem *> problem;
|
||||
|
||||
VariableStack variables;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
161
lib/pddlparse/include/pddlparse/detail/ASTCopy.h
Normal file
161
lib/pddlparse/include/pddlparse/detail/ASTCopy.h
Normal file
@@ -0,0 +1,161 @@
|
||||
#ifndef __PDDL_PARSE__DETAIL__AST_COPY_H
|
||||
#define __PDDL_PARSE__DETAIL__AST_COPY_H
|
||||
|
||||
#include <pddlparse/AST.h>
|
||||
|
||||
namespace pddl
|
||||
{
|
||||
namespace ast
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// ASTCopy
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Primitives
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline Constant deepCopy(Constant &other);
|
||||
inline PrimitiveType deepCopy(PrimitiveType &other);
|
||||
inline Variable deepCopy(Variable &other);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Expressions: Base Classes
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived, class ArgumentLeft, class ArgumentRight = ArgumentLeft>
|
||||
inline Binary<Derived, ArgumentLeft, ArgumentRight> deepCopy(Binary<Derived, ArgumentLeft, ArgumentRight> &other);
|
||||
template<class Derived, class Argument>
|
||||
inline NAry<Derived, Argument> deepCopy(NAry<Derived, Argument> &other);
|
||||
template<class Derived, class Argument>
|
||||
inline Quantified<Derived, Argument> deepCopy(Quantified<Derived, Argument> &other);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Expressions
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Argument>
|
||||
inline At<Argument> deepCopy(At<Argument> &other);
|
||||
template<class Argument>
|
||||
inline Not<Argument> deepCopy(Not<Argument> &other);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Variants
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline ast::Term deepCopy(ast::Term &other);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Primitives
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Constant deepCopy(Constant &other)
|
||||
{
|
||||
return Constant(other.declaration);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PrimitiveType deepCopy(PrimitiveType &other)
|
||||
{
|
||||
return PrimitiveType(other.declaration);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Variable deepCopy(Variable &other)
|
||||
{
|
||||
return Variable(other.declaration);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Expressions: Base Classes
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived, class ArgumentLeft, class ArgumentRight>
|
||||
Binary<Derived, ArgumentLeft, ArgumentRight> deepCopy(Binary<Derived, ArgumentLeft, ArgumentRight> &other)
|
||||
{
|
||||
auto argumentLeft = deepCopy(other.argumentLeft);
|
||||
auto argumentRight = deepCopy(other.argumentRight);
|
||||
|
||||
return Binary<Derived, ArgumentLeft, ArgumentRight>(std::move(argumentLeft), std::move(argumentRight));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived, class Argument>
|
||||
NAry<Derived, Argument> deepCopy(NAry<Derived, Argument> &other)
|
||||
{
|
||||
typename NAry<Derived, Argument>::Arguments arguments;
|
||||
arguments.reserve(other.arguments.size());
|
||||
|
||||
for (auto &argument : other.arguments)
|
||||
arguments.emplace_back(deepCopy(argument));
|
||||
|
||||
return NAry<Derived, Argument>(std::move(arguments));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived, class Argument>
|
||||
Quantified<Derived, Argument> deepCopy(Quantified<Derived, Argument> &other)
|
||||
{
|
||||
auto argument = deepCopy(other.argument);
|
||||
|
||||
return Quantified<Derived, Argument>(std::move(argument));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Expressions
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Argument>
|
||||
At<Argument> deepCopy(At<Argument> &other)
|
||||
{
|
||||
auto argument = deepCopy(other.argument);
|
||||
|
||||
return At<Argument>(other.timePoint, std::move(argument));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Argument>
|
||||
Not<Argument> deepCopy(Not<Argument> &other)
|
||||
{
|
||||
auto argument = deepCopy(other.argument);
|
||||
|
||||
return Not<Argument>(std::move(argument));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Variants
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct DeepCopyVisitor
|
||||
{
|
||||
template<class Argument>
|
||||
Argument visit(Argument &other)
|
||||
{
|
||||
return deepCopy(other);
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Unique Pointers
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class T>
|
||||
std::unique_ptr<T> deepCopy(std::unique_ptr<T> &other)
|
||||
{
|
||||
return std::make_unique<T>(deepCopy(*other));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
33
lib/pddlparse/include/pddlparse/detail/Requirements.h
Normal file
33
lib/pddlparse/include/pddlparse/detail/Requirements.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef __PDDL_PARSE__DETAIL__REQUIREMENTS_H
|
||||
#define __PDDL_PARSE__DETAIL__REQUIREMENTS_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <pddlparse/Context.h>
|
||||
#include <pddlparse/detail/ASTContext.h>
|
||||
|
||||
namespace pddl
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Requirements
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool hasRequirement(const ast::Domain &domain, ast::Requirement requirement);
|
||||
bool hasRequirement(const ast::Problem &problem, ast::Requirement requirement);
|
||||
bool hasRequirement(const ASTContext &astContext, ast::Requirement requirement);
|
||||
|
||||
void checkRequirement(ast::Domain &domain, ast::Requirement requirement, Context &context);
|
||||
void checkRequirement(ast::Problem &problem, ast::Requirement requirement, Context &context);
|
||||
void checkRequirement(ASTContext &astContext, ast::Requirement requirement, Context &context);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
127
lib/pddlparse/include/pddlparse/detail/parsing/AST.h
Normal file
127
lib/pddlparse/include/pddlparse/detail/parsing/AST.h
Normal file
@@ -0,0 +1,127 @@
|
||||
#ifndef __PDDL_PARSE__DETAIL__PARSING__AST_H
|
||||
#define __PDDL_PARSE__DETAIL__PARSING__AST_H
|
||||
|
||||
#include <pddlparse/AST.h>
|
||||
#include <pddlparse/detail/parsing/Parser.h>
|
||||
#include <pddlparse/detail/parsing/Utils.h>
|
||||
|
||||
namespace pddl
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
/*
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// ParseAST
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Primitives
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<>
|
||||
struct Parser<ast::Constant>
|
||||
{
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<>
|
||||
struct Parser<ast::ConstantDeclaration>
|
||||
{
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<>
|
||||
struct Parser<ast::PrimitiveType>
|
||||
{
|
||||
std::experimental::optional<ast::PrimitiveType> parse(Context &context, ASTContext &astContext)
|
||||
{
|
||||
auto &tokenizer = context.tokenizer;
|
||||
auto &types = astContext.description.domain.types;
|
||||
|
||||
tokenizer.skipWhiteSpace();
|
||||
|
||||
auto typeName = tokenizer.getIdentifier();
|
||||
|
||||
if (typeName.empty())
|
||||
throw tokenize::TokenizerException(tokenizer.location(), "no type supplied");
|
||||
|
||||
auto matchingType = std::find_if(types.begin(), types.end(),
|
||||
[&](auto &primitiveTypeDeclaration)
|
||||
{
|
||||
return primitiveTypeDeclaration->name == typeName;
|
||||
});
|
||||
|
||||
if (matchingType == types.end())
|
||||
{
|
||||
// Only “object” is allowed as an implicit type
|
||||
if (typeName == "object" || typeName == "objects")
|
||||
{
|
||||
context.warningCallback(tokenizer.location(), "primitive type “" + typeName + "” should be declared");
|
||||
types.emplace_back(std::make_unique<ast::PrimitiveTypeDeclaration>(std::move(typeName)));
|
||||
|
||||
return ast::PrimitiveType(types.back());
|
||||
}
|
||||
else
|
||||
throw tokenize::TokenizerException(tokenizer.location(), "type “" + typeName + "” used but never declared");
|
||||
}
|
||||
|
||||
auto &type = *matchingType;
|
||||
|
||||
return ast::PrimitiveType(type);
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<>
|
||||
struct Parser<ast::PrimitiveTypeDeclaration>
|
||||
{
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<>
|
||||
struct Parser<ast::Unsupported>
|
||||
{
|
||||
std::experimental::optional<ast::Unsupported> parse(Context &context, ASTContext &)
|
||||
{
|
||||
auto &tokenizer = context.tokenizer;
|
||||
|
||||
ast::Unsupported unsupported;
|
||||
|
||||
tokenizer.expect<std::string>("(");
|
||||
|
||||
unsupported.type = tokenizer.getIdentifier();
|
||||
|
||||
context.warningCallback(tokenizer.location(), "expression type “" + unsupported.type + "” currently unsupported in this context");
|
||||
|
||||
skipSection(tokenizer);
|
||||
|
||||
return unsupported;
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Expressions
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Argument>
|
||||
struct Parser<ast::And<Argument>>
|
||||
{
|
||||
template<typename ArgumentParser>
|
||||
std::experimental::optional<ast::And<Argument>> parse(Context &context, ASTContext &astContext, ArgumentParser parseArgument)
|
||||
{
|
||||
return Parser<ast::NAry<ast::And<Argument>, Argument>>::parse(context, astContext, parseArgument);
|
||||
}
|
||||
};
|
||||
*/
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
25
lib/pddlparse/include/pddlparse/detail/parsing/Action.h
Normal file
25
lib/pddlparse/include/pddlparse/detail/parsing/Action.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef __PDDL_PARSE__DETAIL__PARSING__ACTION_H
|
||||
#define __PDDL_PARSE__DETAIL__PARSING__ACTION_H
|
||||
|
||||
#include <pddlparse/ASTForward.h>
|
||||
#include <pddlparse/Context.h>
|
||||
|
||||
namespace pddl
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Action
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void parseAndAddAction(Context &context, ast::Domain &domain);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
26
lib/pddlparse/include/pddlparse/detail/parsing/Constant.h
Normal file
26
lib/pddlparse/include/pddlparse/detail/parsing/Constant.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef __PDDL_PARSE__DETAIL__PARSING__CONSTANT_H
|
||||
#define __PDDL_PARSE__DETAIL__PARSING__CONSTANT_H
|
||||
|
||||
#include <pddlparse/ASTForward.h>
|
||||
#include <pddlparse/Context.h>
|
||||
|
||||
namespace pddl
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Constant
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ast::ConstantPointer parseConstant(Context &context, ast::Domain &domain);
|
||||
ast::ConstantPointer parseConstant(Context &context, ast::Problem &problem);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -0,0 +1,26 @@
|
||||
#ifndef __PDDL_PARSE__DETAIL__PARSING__CONSTANT_DECLARATION_H
|
||||
#define __PDDL_PARSE__DETAIL__PARSING__CONSTANT_DECLARATION_H
|
||||
|
||||
#include <pddlparse/ASTForward.h>
|
||||
#include <pddlparse/Context.h>
|
||||
|
||||
namespace pddl
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// ConstantDeclaration
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void parseAndAddConstantDeclarations(Context &context, ast::Domain &domain);
|
||||
void parseAndAddConstantDeclarations(Context &context, ast::Problem &problem);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
39
lib/pddlparse/include/pddlparse/detail/parsing/Description.h
Normal file
39
lib/pddlparse/include/pddlparse/detail/parsing/Description.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef __PDDL_PARSE__DETAIL__PARSING__DESCRIPTION_H
|
||||
#define __PDDL_PARSE__DETAIL__PARSING__DESCRIPTION_H
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
#include <pddlparse/ASTForward.h>
|
||||
#include <pddlparse/Context.h>
|
||||
|
||||
namespace pddl
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Description
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class DescriptionParser
|
||||
{
|
||||
public:
|
||||
DescriptionParser(Context &context);
|
||||
ast::Description parse();
|
||||
|
||||
private:
|
||||
void findSections();
|
||||
|
||||
Context &m_context;
|
||||
tokenize::Stream::Position m_domainPosition;
|
||||
tokenize::Stream::Position m_problemPosition;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
50
lib/pddlparse/include/pddlparse/detail/parsing/Domain.h
Normal file
50
lib/pddlparse/include/pddlparse/detail/parsing/Domain.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#ifndef __PDDL_PARSE__DETAIL__PARSING__DOMAIN_H
|
||||
#define __PDDL_PARSE__DETAIL__PARSING__DOMAIN_H
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
#include <pddlparse/AST.h>
|
||||
#include <pddlparse/Context.h>
|
||||
|
||||
namespace pddl
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Domain
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class DomainParser
|
||||
{
|
||||
public:
|
||||
DomainParser(Context &context);
|
||||
ast::DomainPointer parse();
|
||||
|
||||
private:
|
||||
void findSections(ast::Domain &domain);
|
||||
|
||||
void parseRequirementSection(ast::Domain &domain);
|
||||
void computeDerivedRequirements(ast::Domain &domain);
|
||||
void parseTypeSection(ast::Domain &domain);
|
||||
void parseConstantSection(ast::Domain &domain);
|
||||
void parsePredicateSection(ast::Domain &domain);
|
||||
void parseActionSection(ast::Domain &domain);
|
||||
|
||||
Context &m_context;
|
||||
|
||||
tokenize::Stream::Position m_requirementsPosition;
|
||||
tokenize::Stream::Position m_typesPosition;
|
||||
tokenize::Stream::Position m_constantsPosition;
|
||||
tokenize::Stream::Position m_predicatesPosition;
|
||||
std::vector<tokenize::Stream::Position> m_actionPositions;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -0,0 +1,25 @@
|
||||
#ifndef __PDDL_PARSE__DETAIL__PARSING__INITIAL_STATE_H
|
||||
#define __PDDL_PARSE__DETAIL__PARSING__INITIAL_STATE_H
|
||||
|
||||
#include <pddlparse/Context.h>
|
||||
#include <pddlparse/detail/ASTContext.h>
|
||||
|
||||
namespace pddl
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// InitialState
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ast::InitialState parseInitialState(Context &context, ASTContext &expressionContext);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
43
lib/pddlparse/include/pddlparse/detail/parsing/Parser.h
Normal file
43
lib/pddlparse/include/pddlparse/detail/parsing/Parser.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#ifndef __PDDL_PARSE__DETAIL__PARSER_H
|
||||
#define __PDDL_PARSE__DETAIL__PARSER_H
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
#include <pddlparse/ASTForward.h>
|
||||
#include <pddlparse/Context.h>
|
||||
#include <pddlparse/detail/ASTContext.h>
|
||||
|
||||
namespace pddl
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Parser
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class T>
|
||||
struct Parser
|
||||
{
|
||||
};
|
||||
|
||||
template<class T, typename... ArgumentParser>
|
||||
std::experimental::optional<T> parse(Context &context, ASTContext &astContext, ArgumentParser... argumentParsers)
|
||||
{
|
||||
return detail::Parser<T>().parse(context, astContext, argumentParsers...);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
std::experimental::optional<T> parse(Context &context, ASTContext &astContext)
|
||||
{
|
||||
return detail::Parser<T>().parse(context, astContext);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -0,0 +1,25 @@
|
||||
#ifndef __PDDL_PARSE__DETAIL__PARSING__PREDICATE_DECLARATION_H
|
||||
#define __PDDL_PARSE__DETAIL__PARSING__PREDICATE_DECLARATION_H
|
||||
|
||||
#include <pddlparse/ASTForward.h>
|
||||
#include <pddlparse/Context.h>
|
||||
|
||||
namespace pddl
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PredicateDeclaration
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void parseAndAddPredicateDeclarations(Context &context, ast::Domain &domain);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -0,0 +1,25 @@
|
||||
#ifndef __PDDL_PARSE__DETAIL__PARSING__PRIMITIVE_TYPE_H
|
||||
#define __PDDL_PARSE__DETAIL__PARSING__PRIMITIVE_TYPE_H
|
||||
|
||||
#include <pddlparse/ASTForward.h>
|
||||
#include <pddlparse/Context.h>
|
||||
|
||||
namespace pddl
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PrimitiveType
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ast::PrimitiveTypePointer parsePrimitiveType(Context &context, ast::Domain &domain);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -0,0 +1,25 @@
|
||||
#ifndef __PDDL_PARSE__DETAIL__PARSING__PRIMITIVE_TYPE_DECLARATION_H
|
||||
#define __PDDL_PARSE__DETAIL__PARSING__PRIMITIVE_TYPE_DECLARATION_H
|
||||
|
||||
#include <pddlparse/ASTForward.h>
|
||||
#include <pddlparse/Context.h>
|
||||
|
||||
namespace pddl
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PrimitiveTypeDeclaration
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void parseAndAddPrimitiveTypeDeclarations(Context &context, ast::Domain &domain);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
51
lib/pddlparse/include/pddlparse/detail/parsing/Problem.h
Normal file
51
lib/pddlparse/include/pddlparse/detail/parsing/Problem.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef __PDDL_PARSE__DETAIL__PARSING__PROBLEM_H
|
||||
#define __PDDL_PARSE__DETAIL__PARSING__PROBLEM_H
|
||||
|
||||
#include <experimental/optional>
|
||||
|
||||
#include <pddlparse/AST.h>
|
||||
#include <pddlparse/Context.h>
|
||||
|
||||
namespace pddl
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Problem
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ProblemParser
|
||||
{
|
||||
public:
|
||||
ProblemParser(Context &context, ast::Domain &domain);
|
||||
ast::ProblemPointer parse();
|
||||
|
||||
private:
|
||||
void findSections(ast::Problem &problem);
|
||||
|
||||
void parseDomainSection(ast::Problem &problem);
|
||||
void parseRequirementSection(ast::Problem &problem);
|
||||
void computeDerivedRequirements(ast::Problem &problem);
|
||||
void parseObjectSection(ast::Problem &problem);
|
||||
void parseInitialStateSection(ast::Problem &problem);
|
||||
void parseGoalSection(ast::Problem &problem);
|
||||
|
||||
Context &m_context;
|
||||
ast::Domain &m_domain;
|
||||
|
||||
tokenize::Stream::Position m_domainPosition;
|
||||
tokenize::Stream::Position m_requirementsPosition;
|
||||
tokenize::Stream::Position m_objectsPosition;
|
||||
tokenize::Stream::Position m_initialStatePosition;
|
||||
tokenize::Stream::Position m_goalPosition;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
26
lib/pddlparse/include/pddlparse/detail/parsing/Requirement.h
Normal file
26
lib/pddlparse/include/pddlparse/detail/parsing/Requirement.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef __PDDL_PARSE__DETAIL__PARSING__REQUIREMENT_H
|
||||
#define __PDDL_PARSE__DETAIL__PARSING__REQUIREMENT_H
|
||||
|
||||
#include <pddlparse/ASTForward.h>
|
||||
#include <pddlparse/Context.h>
|
||||
|
||||
namespace pddl
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Requirement
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ast::Requirement parseRequirement(Context &context);
|
||||
const char *toString(const ast::Requirement &requirement);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
25
lib/pddlparse/include/pddlparse/detail/parsing/Variable.h
Normal file
25
lib/pddlparse/include/pddlparse/detail/parsing/Variable.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef __PDDL_PARSE__DETAIL__PARSING__VARIABLE_H
|
||||
#define __PDDL_PARSE__DETAIL__PARSING__VARIABLE_H
|
||||
|
||||
#include <pddlparse/ASTForward.h>
|
||||
#include <pddlparse/Context.h>
|
||||
|
||||
namespace pddl
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Variable
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ast::Variable parseVariable(Context &context, ast::Domain &domain);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -0,0 +1,25 @@
|
||||
#ifndef __PDDL_PARSE__DETAIL__PARSING__VARIABLE_DECLARATION_H
|
||||
#define __PDDL_PARSE__DETAIL__PARSING__VARIABLE_DECLARATION_H
|
||||
|
||||
#include <pddlparse/ASTForward.h>
|
||||
#include <pddlparse/Context.h>
|
||||
|
||||
namespace pddl
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// VariableDeclaration
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ast::VariableDeclarations parseVariableDeclarations(Context &context, ast::Domain &domain);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user