#ifndef __PDDL_PARSE__AST_H #define __PDDL_PARSE__AST_H #include #include #include #include #include #include namespace pddl { namespace ast { //////////////////////////////////////////////////////////////////////////////////////////////////// // // AST // //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// // Primitives //////////////////////////////////////////////////////////////////////////////////////////////////// struct Constant { explicit Constant(ConstantDeclaration *declaration) : declaration{declaration} { } Constant(const Constant &other) = delete; Constant &operator=(const Constant &&other) = delete; Constant(Constant &&other) = default; Constant &operator=(Constant &&other) = default; ConstantDeclaration *declaration{nullptr}; }; //////////////////////////////////////////////////////////////////////////////////////////////////// struct ConstantDeclaration { explicit ConstantDeclaration(std::string &&name, std::experimental::optional &&type = std::experimental::nullopt, bool isDirty = true) : name{std::move(name)}, type{std::move(type)}, isDirty{isDirty} { } ConstantDeclaration(const ConstantDeclaration &other) = delete; ConstantDeclaration &operator=(const ConstantDeclaration &&other) = delete; ConstantDeclaration(ConstantDeclaration &&other) = default; ConstantDeclaration &operator=(ConstantDeclaration &&other) = default; std::string name; std::experimental::optional type; bool isDirty{true}; }; //////////////////////////////////////////////////////////////////////////////////////////////////// struct Dummy { explicit Dummy(std::string name) : name{name} { } Dummy(const Dummy &other) = delete; Dummy &operator=(const Dummy &&other) = delete; Dummy(Dummy &&other) = default; Dummy &operator=(Dummy &&other) = default; std::string name; }; //////////////////////////////////////////////////////////////////////////////////////////////////// struct PrimitiveType { explicit PrimitiveType(PrimitiveTypeDeclaration &declaration) : declaration{declaration} { } PrimitiveType(const PrimitiveType &other) = delete; PrimitiveType &operator=(const PrimitiveType &&other) = delete; PrimitiveType(PrimitiveType &&other) = default; PrimitiveType &operator=(PrimitiveType &&other) = default; PrimitiveTypeDeclaration &declaration; }; //////////////////////////////////////////////////////////////////////////////////////////////////// struct PrimitiveTypeDeclaration { explicit PrimitiveTypeDeclaration(std::string &&name) : name{std::move(name)} { } PrimitiveTypeDeclaration(const PrimitiveTypeDeclaration &other) = delete; PrimitiveTypeDeclaration &operator=(const PrimitiveTypeDeclaration &&other) = delete; PrimitiveTypeDeclaration(PrimitiveTypeDeclaration &&other) = default; PrimitiveTypeDeclaration &operator=(PrimitiveTypeDeclaration &&other) = default; std::string name; std::vector parentTypes; }; //////////////////////////////////////////////////////////////////////////////////////////////////// struct Unsupported { explicit Unsupported() = default; 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) : declaration{declaration} { } Variable(const Variable &other) = delete; Variable &operator=(const Variable &&other) = delete; Variable(Variable &&other) = default; Variable &operator=(Variable &&other) = default; VariableDeclaration &declaration; }; //////////////////////////////////////////////////////////////////////////////////////////////////// struct VariableDeclaration { explicit VariableDeclaration(std::string &&name, std::experimental::optional type = std::experimental::nullopt, bool isDirty = true) : name{std::move(name)}, type{std::move(type)}, isDirty{isDirty} { } VariableDeclaration(const VariableDeclaration &other) = delete; VariableDeclaration &operator=(const VariableDeclaration &&other) = delete; VariableDeclaration(VariableDeclaration &&other) = default; VariableDeclaration &operator=(VariableDeclaration &&other) = default; std::string name; std::experimental::optional type; bool isDirty{true}; }; //////////////////////////////////////////////////////////////////////////////////////////////////// // Compounds //////////////////////////////////////////////////////////////////////////////////////////////////// struct Predicate { explicit Predicate(PredicateDeclaration &declaration) : declaration{declaration} { } Predicate(const Predicate &other) = delete; Predicate &operator=(const Predicate &&other) = delete; Predicate(Predicate &&other) = default; Predicate &operator=(Predicate &&other) = default; std::string name; Terms arguments; PredicateDeclaration &declaration; }; //////////////////////////////////////////////////////////////////////////////////////////////////// struct PredicateDeclaration { explicit PredicateDeclaration(std::string &&name, VariableDeclarations &¶meters) : name{std::move(name)}, parameters{std::move(parameters)} { } PredicateDeclaration(const PredicateDeclaration &other) = delete; PredicateDeclaration &operator=(const PredicateDeclaration &&other) = delete; PredicateDeclaration(PredicateDeclaration &&other) = default; PredicateDeclaration &operator=(PredicateDeclaration &&other) = default; std::string name; VariableDeclarations parameters; }; //////////////////////////////////////////////////////////////////////////////////////////////////// // Expressions: Base Classes //////////////////////////////////////////////////////////////////////////////////////////////////// template struct Binary { explicit Binary(ArgumentLeft &&argumentLeft, ArgumentRight &&argumentRight) : argumentLeft{std::move(argumentLeft)}, argumentRight{std::move(argumentRight)} { } Binary(const Binary &other) = delete; Binary &operator=(const Binary &&other) = delete; Binary(Binary &&other) = default; Binary &operator=(Binary &&other) = default; ArgumentLeft argumentLeft; ArgumentRight argumentRight; }; //////////////////////////////////////////////////////////////////////////////////////////////////// template struct NAry { using Arguments = std::vector; explicit NAry(Arguments &&arguments) noexcept : arguments{std::move(arguments)} { } NAry(const NAry &other) = delete; NAry &operator=(const NAry &&other) = delete; NAry(NAry &&other) = default; NAry &operator=(NAry &&other) = default; Arguments arguments; protected: static Arguments copyArguments(const NAry &other) { Arguments arguments; arguments.reserve(other.arguments.size()); for (const auto &argument : other.arguments) arguments.emplace_back(std::move(deepCopyVariant(argument))); return arguments; } }; //////////////////////////////////////////////////////////////////////////////////////////////////// template struct Quantified { using Parameters = VariableDeclarations; explicit Quantified(Parameters &¶meters, Argument &&argument) : parameters{std::move(parameters)}, argument{std::move(argument)} { } Quantified(const Quantified &other) = delete; Quantified &operator=(const Quantified &&other) = delete; Quantified(Quantified &&other) = default; Quantified &operator=(Quantified &&other) = default; Parameters parameters; Argument argument; }; //////////////////////////////////////////////////////////////////////////////////////////////////// // Expressions //////////////////////////////////////////////////////////////////////////////////////////////////// template struct And: public NAry, Argument> { using typename NAry, Argument>::Arguments; static constexpr const auto Identifier = "and"; explicit And(Arguments &&arguments) noexcept : NAry, Argument>(std::move(arguments)) { } }; //////////////////////////////////////////////////////////////////////////////////////////////////// template struct At { static constexpr const auto TimePointStart = std::numeric_limits::max(); static constexpr const auto TimePointEnd = std::numeric_limits::max() - 1; At(std::size_t timePoint, Argument &&argument) : timePoint{timePoint}, argument{std::move(argument)} { } At(const At &other) = delete; At &operator=(const At &&other) = delete; At(At &&other) = default; At &operator=(At &&other) = default; std::size_t timePoint; Argument argument; }; //////////////////////////////////////////////////////////////////////////////////////////////////// template struct Either: public NAry, Argument> { using typename NAry, Argument>::Arguments; static constexpr const auto Identifier = "either"; explicit Either(Arguments &&arguments) noexcept : NAry, Argument>(std::move(arguments)) { } Either(const Either &other) : NAry, Argument>(this->copyArguments(other)) { } }; //////////////////////////////////////////////////////////////////////////////////////////////////// template struct Exists: public Quantified, Argument> { static constexpr const auto Identifier = "exists"; explicit Exists(VariableDeclarations &¶meters, Argument &&argument) : Quantified, Argument>(std::move(parameters), std::move(argument)) { } }; //////////////////////////////////////////////////////////////////////////////////////////////////// template struct ForAll: public Quantified, Argument> { static constexpr const auto Identifier = "forall"; explicit ForAll(VariableDeclarations &¶meters, Argument &&argument) : Quantified, Argument>(std::move(parameters), std::move(argument)) { } }; //////////////////////////////////////////////////////////////////////////////////////////////////// template struct Imply: public Binary, Argument> { static constexpr const auto Identifier = "imply"; // TODO: make noexcept consistent explicit Imply(Argument &&argumentLeft, Argument &&argumentRight) : Binary, Argument>(std::move(argumentLeft), std::move(argumentRight)) { } }; //////////////////////////////////////////////////////////////////////////////////////////////////// template struct Not { explicit Not(Argument &&argument) : argument{std::move(argument)} { } Not(const Not &other) = delete; Not &operator=(const Not &&other) = delete; Not(Not &&other) = default; Not &operator=(Not &&other) = default; Argument argument; }; //////////////////////////////////////////////////////////////////////////////////////////////////// template struct Or: public NAry, Argument> { using typename NAry, Argument>::Arguments; static constexpr const auto Identifier = "or"; explicit Or(Arguments &&arguments) noexcept : NAry, Argument>(std::move(arguments)) { } }; //////////////////////////////////////////////////////////////////////////////////////////////////// template struct When: public Binary, ArgumentLeft, ArgumentRight> { static constexpr const auto Identifier = "when"; explicit When(ArgumentLeft &&argumentLeft, ArgumentRight &&argumentRight) : Binary, ArgumentLeft, ArgumentRight>(std::move(argumentLeft), std::move(argumentRight)) { } }; //////////////////////////////////////////////////////////////////////////////////////////////////// // PDDL Structure //////////////////////////////////////////////////////////////////////////////////////////////////// struct Action { Action(const Action &other) = delete; Action &operator=(const Action &&other) = delete; Action(Action &&other) = default; Action &operator=(Action &&other) = default; std::string name; ast::VariableDeclarations parameters; std::experimental::optional precondition; std::experimental::optional effect; }; //////////////////////////////////////////////////////////////////////////////////////////////////// struct Domain { Domain(const Domain &other) = delete; Domain &operator=(const Domain &&other) = delete; Domain(Domain &&other) = default; Domain &operator=(Domain &&other) = default; std::string name; Requirements requirements; ast::PrimitiveTypeDeclarations types; ast::ConstantDeclarations constants; ast::PredicateDeclarations predicates; std::vector actions; }; //////////////////////////////////////////////////////////////////////////////////////////////////// struct InitialState { InitialState(const InitialState &other) = delete; InitialState &operator=(const InitialState &&other) = delete; InitialState(InitialState &&other) = default; InitialState &operator=(InitialState &&other) = default; ast::Facts facts; }; //////////////////////////////////////////////////////////////////////////////////////////////////// struct Problem { Problem(const Problem &other) = delete; Problem &operator=(const Problem &&other) = delete; Problem(Problem &&other) = default; Problem &operator=(Problem &&other) = default; Domain &domain; std::string name; Requirements requirements; ast::ConstantDeclarations objects; InitialState initialState; std::experimental::optional goal; }; //////////////////////////////////////////////////////////////////////////////////////////////////// enum class Requirement { STRIPS, Typing, NegativePreconditions, DisjunctivePreconditions, Equality, ExistentialPreconditions, UniversalPreconditions, QuantifiedPreconditions, ConditionalEffects, Fluents, NumericFluents, ObjectFluents, ADL, DurativeActions, DurationInequalities, ContinuousEffects, DerivedPredicates, TimedInitialLiterals, Preferences, Constraints, ActionCosts, GoalUtilities }; //////////////////////////////////////////////////////////////////////////////////////////////////// struct Description { Description(const Description &other) = delete; Description &operator=(const Description &&other) = delete; Description(Description &&other) = default; Description &operator=(Description &&other) = default; Domain domain; std::experimental::optional problem; }; //////////////////////////////////////////////////////////////////////////////////////////////////// } } #endif