diff --git a/src/core/parser_old/expression_factory.cpp b/src/core/parser_old/expression_factory.cpp deleted file mode 100644 index 312e76ed..00000000 --- a/src/core/parser_old/expression_factory.cpp +++ /dev/null @@ -1,115 +0,0 @@ -#include "expression_factory.h" - -#include "expressions/booleans/empty.h" -#include "expressions/booleans/inclusion.h" -#include "expressions/booleans/nullary.h" -#include "expressions/concepts/all.h" -#include "expressions/concepts/and.h" -#include "expressions/concepts/bot.h" -#include "expressions/concepts/diff.h" -#include "expressions/concepts/equal.h" -#include "expressions/concepts/not.h" -#include "expressions/concepts/one_of.h" -#include "expressions/concepts/or.h" -#include "expressions/concepts/projection.h" -#include "expressions/concepts/primitive.h" -#include "expressions/concepts/some.h" -#include "expressions/concepts/subset.h" -#include "expressions/concepts/top.h" -#include "expressions/numericals/concept_distance.h" -#include "expressions/numericals/count.h" -#include "expressions/numericals/role_distance.h" -#include "expressions/numericals/sum_concept_distance.h" -#include "expressions/numericals/sum_role_distance.h" -#include "expressions/roles/and.h" -#include "expressions/roles/compose.h" -#include "expressions/roles/diff.h" -#include "expressions/roles/identity.h" -#include "expressions/roles/inverse.h" -#include "expressions/roles/not.h" -#include "expressions/roles/or.h" -#include "expressions/roles/primitive.h" -#include "expressions/roles/restrict.h" -#include "expressions/roles/top.h" -#include "expressions/roles/transitive_closure.h" -#include "expressions/roles/transitive_reflexive_closure.h" - -#include -#include - - -namespace dlplan::core::parser { - -std::unique_ptr ExpressionFactory::make_expression(const std::string& name, std::vector> &&children) { - if (name == EmptyBoolean::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == InclusionBoolean::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == NullaryBoolean::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == AllConcept::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == AndConcept::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == BotConcept::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == DiffConcept::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == EqualConcept::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == NotConcept::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == OneOfConcept::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == OrConcept::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == PrimitiveConcept::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == ProjectionConcept::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == SomeConcept::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == SubsetConcept::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == TopConcept::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == ConceptDistanceNumerical::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == CountNumerical::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == RoleDistanceNumerical::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == SumConceptDistanceNumerical::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == SumRoleDistanceNumerical::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == AndRole::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == ComposeRole::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == DiffRole::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == IdentityRole::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == InverseRole::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == NotRole::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == OrRole::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == PrimitiveRole::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == RestrictRole::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == TopRole::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == TransitiveClosureRole::get_name()) { - return std::make_unique(name, std::move(children)); - } else if (name == TransitiveReflexiveClosureRole::get_name()) { - return std::make_unique(name, std::move(children)); - } - return std::make_unique(name, std::move(children)); -} - - -} diff --git a/src/core/parser_old/expression_factory.h b/src/core/parser_old/expression_factory.h deleted file mode 100644 index 0eab468b..00000000 --- a/src/core/parser_old/expression_factory.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_FACTORY_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_FACTORY_H_ - -#include -#include - - -namespace dlplan::core { -class VocabularyInfo; -namespace parser { -class Expression; - -class ExpressionFactory { -public: - std::unique_ptr make_expression( - const std::string& name, - std::vector> &&children); -}; - -} -} - -#endif diff --git a/src/core/parser_old/expressions/boolean.h b/src/core/parser_old/expressions/boolean.h deleted file mode 100644 index c54201cf..00000000 --- a/src/core/parser_old/expressions/boolean.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_BOOLEAN_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_BOOLEAN_H_ - -#include "expression.h" -#include "../../cache.h" - - -namespace dlplan::core { -class Boolean; -} - -namespace dlplan::core::parser { - -class Boolean : public Expression { -public: - Boolean(const std::string &name, std::vector> &&children) - : Expression(name, std::move(children)) { } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/booleans/empty.h b/src/core/parser_old/expressions/booleans/empty.h deleted file mode 100644 index e42f185a..00000000 --- a/src/core/parser_old/expressions/booleans/empty.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_BOOLEAN_EMPTY_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_BOOLEAN_EMPTY_H_ - -#include "../boolean.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class EmptyBoolean : public Boolean { -private: - static inline const std::string m_name = "b_empty"; - -public: - EmptyBoolean(const std::string &name, std::vector> &&children) - : Boolean(name, std::move(children)) { } - - std::shared_ptr parse_boolean(SyntacticElementFactory& factory) const override { - if (m_children.size() != 1) { - throw std::runtime_error("EmptyBoolean::parse_boolean - number of children ("s + std::to_string(m_children.size()) + " != 1)."); - } - // 1. Parse and construct children - auto concept_element = m_children[0]->parse_concept(factory); - if (concept_element) { - return factory.make_empty_boolean(concept_element); - } - auto role_element = m_children[0]->parse_role(factory); - if (role_element) { - return factory.make_empty_boolean(role_element); - } - // 2. If unsuccessful then throw a runtime error. - throw std::runtime_error("EmptyBoolean::parse_boolean - unable to construct children elements."); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/booleans/inclusion.h b/src/core/parser_old/expressions/booleans/inclusion.h deleted file mode 100644 index 7c4cbf53..00000000 --- a/src/core/parser_old/expressions/booleans/inclusion.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_BOOLEAN_INCLUSION_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_BOOLEAN_INCLUSION_H_ - -#include "../boolean.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class InclusionBoolean : public Boolean { -private: - static inline const std::string m_name = "b_inclusion"; - -public: - InclusionBoolean(const std::string &name, std::vector> &&children) - : Boolean(name, std::move(children)) { } - - std::shared_ptr parse_boolean(SyntacticElementFactory& factory) const override { - if (m_children.size() != 2) { - throw std::runtime_error("InclusionBoolean::parse_boolean - number of children ("s + std::to_string(m_children.size()) + " != 2)."); - } - // 1. Parse and construct children - auto concept_left = m_children[0]->parse_concept(factory); - auto concept_right = m_children[1]->parse_concept(factory); - if (concept_left && concept_right) { - return factory.make_inclusion_boolean(concept_left, concept_right); - } - auto role_left = m_children[0]->parse_role(factory); - auto role_right = m_children[1]->parse_role(factory); - if (role_left && role_right) { - return factory.make_inclusion_boolean(role_left, role_right); - } - // 2. If unsuccessful then throw a runtime error. - throw std::runtime_error("EmptyBoolean::parse_boolean - unable to construct children elements."); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/booleans/nullary.h b/src/core/parser_old/expressions/booleans/nullary.h deleted file mode 100644 index 9e3fe9d0..00000000 --- a/src/core/parser_old/expressions/booleans/nullary.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_BOOLEANS_NULLARY_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_BOOLEANS_NULLARY_H_ - -#include "../boolean.h" - - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class NullaryBoolean : public Boolean { -private: - static inline const std::string m_name = "b_nullary"; - -public: - NullaryBoolean(const std::string &name, std::vector> &&children) - : Boolean(name, std::move(children)) { } - - std::shared_ptr parse_boolean(SyntacticElementFactory& factory) const override { - if (m_children.size() != 1) { - throw std::runtime_error("NullaryBoolean::parse_boolean - number of children ("s + std::to_string(m_children.size()) + " != 1)."); - } - // 1. Parse children - const auto& predicate_name = m_children[0]->get_name(); - // 2. Construct element - return factory.make_nullary_boolean(factory.get_vocabulary_info()->get_predicate(predicate_name)); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/concept.h b/src/core/parser_old/expressions/concept.h deleted file mode 100644 index 663069d8..00000000 --- a/src/core/parser_old/expressions/concept.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_CONCEPT_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_CONCEPT_H_ - -#include "expression.h" -#include "../../cache.h" - - -namespace dlplan::core { -class Concept; -} - -namespace dlplan::core::parser { - -class Concept : public Expression { -public: - Concept(const std::string &name, std::vector> &&children) - : Expression(name, std::move(children)) { } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/concepts/all.h b/src/core/parser_old/expressions/concepts/all.h deleted file mode 100644 index 8ecc00fe..00000000 --- a/src/core/parser_old/expressions/concepts/all.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_CONCEPTS_ALL_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_CONCEPTS_ALL_H_ - -#include "../concept.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class AllConcept : public Concept { -private: - static inline const std::string m_name = "c_all"; - -public: - AllConcept(const std::string &name, std::vector> &&children) - : Concept(name, std::move(children)) { } - - std::shared_ptr parse_concept(SyntacticElementFactory& factory) const override { - if (m_children.size() != 2) { - throw std::runtime_error("AllConcept::parse_concept - number of children ("s + std::to_string(m_children.size()) + " != 2)."); - } - // 1. Parse children - auto role = m_children[0]->parse_role(factory); - auto concept = m_children[1]->parse_concept(factory); - if (!(role && concept)) { - throw std::runtime_error("AllConcept::parse_concept - at least one child is a nullptr"); - } - // 2. Construct element - return factory.make_all_concept(role, concept); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/concepts/and.h b/src/core/parser_old/expressions/concepts/and.h deleted file mode 100644 index bcf18476..00000000 --- a/src/core/parser_old/expressions/concepts/and.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_CONCEPTS_AND_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_CONCEPTS_AND_H_ - -#include "../concept.h" -#include "../../utils.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class AndConcept : public Concept { -private: - static inline const std::string m_name = "c_and"; - -public: - AndConcept(const std::string &name, std::vector> &&children) - : Concept(name, sort_children_lexicographically(std::move(children))) { } - - std::shared_ptr parse_concept(SyntacticElementFactory& factory) const override { - if (m_children.size() != 2) { - throw std::runtime_error("AndConcept::parse_concept - number of children ("s + std::to_string(m_children.size()) + " != 2)."); - } - // 1. Parse children - auto concept_left = m_children[0]->parse_concept(factory); - auto concept_right = m_children[1]->parse_concept(factory); - if (!(concept_left && concept_right)) { - throw std::runtime_error("AndConcept::parse_concept - children are not of type Concept."); - } - // 2. Construct element - return factory.make_and_concept(concept_left, concept_right); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/concepts/bot.h b/src/core/parser_old/expressions/concepts/bot.h deleted file mode 100644 index 2453c1ce..00000000 --- a/src/core/parser_old/expressions/concepts/bot.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_CONCEPTS_BOT_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_CONCEPTS_BOT_H_ - -#include "../concept.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class BotConcept : public Concept { -private: - static inline const std::string m_name = "c_bot"; - -public: - BotConcept(const std::string &name, std::vector> &&children) - : Concept(name, std::move(children)) { } - - std::shared_ptr parse_concept(SyntacticElementFactory& factory) const override { - if (m_children.size() != 0) { - throw std::runtime_error("BotConcept::parse_concept - number of children ("s + std::to_string(m_children.size()) + " != 0)."); - } - // 2. Construct element - return factory.make_bot_concept(); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/concepts/diff.h b/src/core/parser_old/expressions/concepts/diff.h deleted file mode 100644 index f0812c30..00000000 --- a/src/core/parser_old/expressions/concepts/diff.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_CONCEPTS_DIFF_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_CONCEPTS_DIFF_H_ - -#include "../concept.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class DiffConcept : public Concept { -private: - static inline const std::string m_name = "c_diff"; - -public: - DiffConcept(const std::string &name, std::vector> &&children) - : Concept(name, std::move(children)) { } - - std::shared_ptr parse_concept(SyntacticElementFactory& factory) const override { - if (m_children.size() != 2) { - throw std::runtime_error("DiffConcept::parse_concept - number of children ("s + std::to_string(m_children.size()) + " != 2)."); - } - // 1. Parse children - auto concept_left = m_children[0]->parse_concept(factory); - auto concept_right = m_children[1]->parse_concept(factory); - if (!(concept_left && concept_right)) { - throw std::runtime_error("DiffConcept::parse_concept - children are not of type Concept."); - } - // 2. Construct element - return factory.make_diff_concept(concept_left, concept_right); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/concepts/equal.h b/src/core/parser_old/expressions/concepts/equal.h deleted file mode 100644 index e65712aa..00000000 --- a/src/core/parser_old/expressions/concepts/equal.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_CONCEPTS_EQUAL_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_CONCEPTS_EQUAL_H_ - -#include "../concept.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class EqualConcept : public Concept { -private: - static inline const std::string m_name = "c_equal"; - -public: - EqualConcept(const std::string &name, std::vector> &&children) - : Concept(name, std::move(children)) { } - - std::shared_ptr parse_concept(SyntacticElementFactory& factory) const override { - if (m_children.size() != 2) { - throw std::runtime_error("EqualConcept::parse_concept - number of children ("s + std::to_string(m_children.size()) + " != 2)."); - } - // 1. Parse children - auto role_left = m_children[0]->parse_role(factory); - auto role_right = m_children[1]->parse_role(factory); - if (!(role_left && role_right)) { - throw std::runtime_error("EqualConcept::parse_concept - at least one children is a nullptr"); - } - // 2. Construct element - return factory.make_equal_concept(role_left, role_right); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/concepts/not.h b/src/core/parser_old/expressions/concepts/not.h deleted file mode 100644 index 343ec0d5..00000000 --- a/src/core/parser_old/expressions/concepts/not.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_CONCEPTS_NOT_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_CONCEPTS_NOT_H_ - -#include "../concept.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class NotConcept : public Concept { -private: - static inline const std::string m_name = "c_not"; - -public: - NotConcept(const std::string &name, std::vector> &&children) - : Concept(name, std::move(children)) { } - - std::shared_ptr parse_concept(SyntacticElementFactory& factory) const override { - if (m_children.size() != 1) { - throw std::runtime_error("NotConcept::parse_concept - number of children ("s + std::to_string(m_children.size()) + " != 1)."); - } - // 1. Parse children - auto concept = m_children[0]->parse_concept(factory); - if (!concept) { - throw std::runtime_error("NotConcept::parse_concept - child is not of type Concept."); - } - // 2. Construct element - return factory.make_not_concept(concept); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/concepts/one_of.h b/src/core/parser_old/expressions/concepts/one_of.h deleted file mode 100644 index 20bd12c7..00000000 --- a/src/core/parser_old/expressions/concepts/one_of.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_CONCEPTS_ONE_OF_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_CONCEPTS_ONE_OF_H_ - -#include "../concept.h" -#include "../../utils.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class OneOfConcept : public Concept { -private: - static inline const std::string m_name = "c_one_of"; - -public: - OneOfConcept(const std::string &name, std::vector> &&children) - : Concept(name, std::move(children)) { } - - std::shared_ptr parse_concept(SyntacticElementFactory& factory) const override { - if (m_children.size() != 1) { - throw std::runtime_error("OneOfConcept::parse_concept - number of children ("s + std::to_string(m_children.size()) + " != 1)."); - } - const auto& constant_name = m_children[0]->get_name(); - return factory.make_one_of_concept(factory.get_vocabulary_info()->get_constant(constant_name)); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/concepts/or.h b/src/core/parser_old/expressions/concepts/or.h deleted file mode 100644 index a5242506..00000000 --- a/src/core/parser_old/expressions/concepts/or.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_CONCEPTS_OR_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_CONCEPTS_OR_H_ - -#include "../concept.h" -#include "../../utils.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class OrConcept : public Concept { -private: - static inline const std::string m_name = "c_or"; - -public: - OrConcept(const std::string &name, std::vector> &&children) - : Concept(name, sort_children_lexicographically(std::move(children))) { } - - std::shared_ptr parse_concept(SyntacticElementFactory& factory) const override { - if (m_children.size() != 2) { - throw std::runtime_error("OrConcept::parse_concept - number of children ("s + std::to_string(m_children.size()) + " != 2)."); - } - // 1. Parse children - auto concept_left = m_children[0]->parse_concept(factory); - auto concept_right = m_children[1]->parse_concept(factory); - if (!(concept_left && concept_right)) { - throw std::runtime_error("OrConcept::parse_concept - children are not of type Concept."); - } - // 2. Construct element - return factory.make_or_concept(concept_left, concept_right); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/concepts/primitive.h b/src/core/parser_old/expressions/concepts/primitive.h deleted file mode 100644 index 65992b69..00000000 --- a/src/core/parser_old/expressions/concepts/primitive.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_CONCEPTS_PRIMITIVE_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_CONCEPTS_PRIMITIVE_H_ - -#include "../concept.h" -#include "../../utils.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class PrimitiveConcept : public Concept { -private: - static inline const std::string m_name = "c_primitive"; - -public: - PrimitiveConcept(const std::string &name, std::vector> &&children) - : Concept(name, std::move(children)) { } - - std::shared_ptr parse_concept(SyntacticElementFactory& factory) const override { - if (m_children.size() != 2) { - throw std::runtime_error("PrimitiveConcept::parse_concept - number of children ("s + std::to_string(m_children.size()) + " != 2)."); - } - // 1. Parse children - const auto& predicate_name = m_children[0]->get_name(); - int pos = try_parse_number(m_children[1]->get_name()); - // 2. Construct element - return factory.make_primitive_concept(factory.get_vocabulary_info()->get_predicate(predicate_name), pos); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/concepts/projection.h b/src/core/parser_old/expressions/concepts/projection.h deleted file mode 100644 index 1efa86ce..00000000 --- a/src/core/parser_old/expressions/concepts/projection.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_CONCEPTS_PROJECTION_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_CONCEPTS_PROJECTION_H_ - -#include "../concept.h" -#include "../../utils.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class ProjectionConcept : public Concept { -private: - static inline const std::string m_name = "c_projection"; - -public: - ProjectionConcept(const std::string &name, std::vector> &&children) - : Concept(name, std::move(children)) { } - - std::shared_ptr parse_concept(SyntacticElementFactory& factory) const override { - if (m_children.size() != 2) { - throw std::runtime_error("ProjectionConcept::parse_concept - number of children ("s + std::to_string(m_children.size()) + " != 1)."); - } - auto role = m_children[0]->parse_role(factory); - if (!role) { - throw std::runtime_error("ProjectionConcept::parse_concept - child is a nullptr."); - } - int pos = try_parse_number(m_children[1]->get_name()); - if (pos < 0 || pos > 1) { - throw std::runtime_error("ProjectionConcept::parse_concept - projection index out of range, should be 0 or 1 ("s + std::to_string(pos) + ")"); - } - return factory.make_projection_concept(role, pos); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/concepts/some.h b/src/core/parser_old/expressions/concepts/some.h deleted file mode 100644 index 1dea2b41..00000000 --- a/src/core/parser_old/expressions/concepts/some.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_CONCEPTS_SOME_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_CONCEPTS_SOME_H_ - -#include "../concept.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class SomeConcept : public Concept { -private: - static inline const std::string m_name = "c_some"; - -public: - SomeConcept(const std::string &name, std::vector> &&children) - : Concept(name, std::move(children)) { } - - std::shared_ptr parse_concept(SyntacticElementFactory& factory) const override { - if (m_children.size() != 2) { - throw std::runtime_error("SomeConcept::parse_concept - number of children ("s + std::to_string(m_children.size()) + " != 2)."); - } - // 1. Parse children - auto role = m_children[0]->parse_role(factory); - auto concept = m_children[1]->parse_concept(factory); - if (!(role && concept)) { - throw std::runtime_error("SomeConcept::parse_concept - at least one children is a nullptr"); - } - // 2. Construct element - return factory.make_some_concept(role, concept); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/concepts/subset.h b/src/core/parser_old/expressions/concepts/subset.h deleted file mode 100644 index 8c599e7c..00000000 --- a/src/core/parser_old/expressions/concepts/subset.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_CONCEPTS_SUBSET_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_CONCEPTS_SUBSET_H_ - -#include "../concept.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class SubsetConcept : public Concept { -private: - static inline const std::string m_name = "c_subset"; - -public: - SubsetConcept(const std::string &name, std::vector> &&children) - : Concept(name, std::move(children)) { } - - std::shared_ptr parse_concept(SyntacticElementFactory& factory) const override { - if (m_children.size() != 2) { - throw std::runtime_error("SubsetConcept::parse_concept - number of children ("s + std::to_string(m_children.size()) + " != 2)."); - } - // 1. Parse children - auto role_left = m_children[0]->parse_role(factory); - auto role_right = m_children[1]->parse_role(factory); - if (!(role_left && role_right)) { - throw std::runtime_error("SubsetConcept::parse_concept - at least one children is a nullptr"); - } - // 2. Construct element - return factory.make_subset_concept(role_left, role_right); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/concepts/top.h b/src/core/parser_old/expressions/concepts/top.h deleted file mode 100644 index be437e9e..00000000 --- a/src/core/parser_old/expressions/concepts/top.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_CONCEPTS_TOP_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_CONCEPTS_TOP_H_ - -#include "../concept.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class TopConcept : public Concept { -private: - static inline const std::string m_name = "c_top"; - -public: - TopConcept(const std::string &name, std::vector> &&children) - : Concept(name, std::move(children)) { } - - std::shared_ptr parse_concept(SyntacticElementFactory& factory) const override { - if (m_children.size() != 0) { - throw std::runtime_error("TopConcept::parse_concept - number of children ("s + std::to_string(m_children.size()) + " != 0)."); - } - // 2. Construct element - return factory.make_top_concept(); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/expression.h b/src/core/parser_old/expressions/expression.h deleted file mode 100644 index 4f11da90..00000000 --- a/src/core/parser_old/expressions/expression.h +++ /dev/null @@ -1,97 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_EXPRESSION_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_EXPRESSION_H_ - -#include -#include -#include -#include - - -namespace dlplan::core { -class VocabularyInfo; -struct Caches; -class Concept; -class Role; -class Boolean; -class Numerical; -class SyntacticElementFactory; -} - -namespace dlplan::core::parser { - -/** - * An Expression represents a node in an abstract syntax tree. - */ -class Expression { -protected: - std::string m_name; - std::vector> m_children; - -public: - Expression(const std::string &name, - std::vector> &&children) - : m_name(name), m_children(std::move(children)) { - } - virtual ~Expression() = default; - - /** - * Returns true if the expression is a leaf, i.e., - * an expression that represents a position in a predicate for projection. - */ - bool is_leaf() const { - return m_children.empty(); - } - - /** - * Getters. - */ - const std::string& get_name() const { - return m_name; - } - - // Note: since children are stored as std::vector - // we do not know what type the children will be - // and each concrete type must decide what method to call - // in order to parse into the desired type. - // As a result we cannot change this into a template. - - /** - * Tries to parse the Expression into a Concept. - * If unsuccessful print human readable error messages and throw and exception. - */ - virtual std::shared_ptr - parse_concept(dlplan::core::SyntacticElementFactory& /* factory */ ) const { - return nullptr; - } - - /** - * Tries to parse the Expression into a Role. - * If unsuccessful print human readable error messages and throw and exception. - */ - virtual std::shared_ptr - parse_role(dlplan::core::SyntacticElementFactory& /* factory */ ) const { - return nullptr; - } - - /** - * Tries to parse the Expression into a Numerical. - * If unsuccessful print human readable error messages and throw and exception. - */ - virtual std::shared_ptr - parse_numerical(dlplan::core::SyntacticElementFactory& /* factory */ ) const { - return nullptr; - } - - /** - * Tries to parse the Expression into a Boolean. - * If unsuccessful print human readable error messages and throw and exception. - */ - virtual std::shared_ptr - parse_boolean(dlplan::core::SyntacticElementFactory& /* factory */ ) const { - return nullptr; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/numerical.h b/src/core/parser_old/expressions/numerical.h deleted file mode 100644 index 6ca340ee..00000000 --- a/src/core/parser_old/expressions/numerical.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_NUMERICAL_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_NUMERICAL_H_ - -#include "expression.h" -#include "../../cache.h" - - -namespace dlplan::core { -class Numerical; -} - - -namespace dlplan::core::parser { - -class Numerical : public Expression { -public: - Numerical(const std::string &name, std::vector> &&children) - : Expression(name, std::move(children)) { } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/numericals/concept_distance.h b/src/core/parser_old/expressions/numericals/concept_distance.h deleted file mode 100644 index f519bdb8..00000000 --- a/src/core/parser_old/expressions/numericals/concept_distance.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_NUMERICAL_CONCEPT_DISTANCE_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_NUMERICAL_CONCEPT_DISTANCE_H_ - -#include "../numerical.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class ConceptDistanceNumerical : public Numerical { -private: - static inline const std::string m_name = "n_concept_distance"; - -public: - ConceptDistanceNumerical(const std::string &name, std::vector> &&children) - : Numerical(name, std::move(children)) { } - - std::shared_ptr parse_numerical(SyntacticElementFactory& factory) const override { - if (m_children.size() != 3) { - throw std::runtime_error("ConceptDistanceNumerical::parse_numerical - number of children ("s + std::to_string(m_children.size()) + " != 3)."); - } - // 1. Parse children - auto concept_from = m_children[0]->parse_concept(factory); - auto role = m_children[1]->parse_role(factory); - auto concept_to = m_children[2]->parse_concept(factory); - if (!(concept_from && role && concept_to)) { - throw std::runtime_error("ConceptDistanceNumerical::parse_numerical - child is not of type Concept, Role, Concept."); - } - return factory.make_concept_distance_numerical(concept_from, role, concept_to); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/numericals/count.h b/src/core/parser_old/expressions/numericals/count.h deleted file mode 100644 index d9a7e5fb..00000000 --- a/src/core/parser_old/expressions/numericals/count.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_NUMERICAL_COUNT_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_NUMERICAL_COUNT_H_ - -#include "../numerical.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class CountNumerical : public Numerical { -private: - static inline const std::string m_name = "n_count"; - -public: - CountNumerical(const std::string &name, std::vector> &&children) - : Numerical(name, std::move(children)) { } - - std::shared_ptr parse_numerical(SyntacticElementFactory& factory) const override { - if (m_children.size() != 1) { - throw std::runtime_error("CountNumerical::parse_numerical - number of children ("s + std::to_string(m_children.size()) + " != 1)."); - } - // 1. Parse children - auto concept = m_children[0]->parse_concept(factory); - if (concept) { - return factory.make_count_numerical(concept); - } - auto role = m_children[0]->parse_role(factory); - if (role) { - return factory.make_count_numerical(role); - } - // 2. Construct element - throw std::runtime_error("CountNumerical::parse_numerical - unable to construct children elements."); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/numericals/role_distance.h b/src/core/parser_old/expressions/numericals/role_distance.h deleted file mode 100644 index 285417e9..00000000 --- a/src/core/parser_old/expressions/numericals/role_distance.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_NUMERICAL_ROLE_DISTANCE_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_NUMERICAL_ROLE_DISTANCE_H_ - -#include "../numerical.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class RoleDistanceNumerical : public Numerical { -private: - static inline const std::string m_name = "n_role_distance"; - -public: - RoleDistanceNumerical(const std::string &name, std::vector> &&children) - : Numerical(name, std::move(children)) { } - - std::shared_ptr parse_numerical(SyntacticElementFactory& factory) const override { - if (m_children.size() != 3) { - throw std::runtime_error("RoleDistanceNumerical::parse_numerical - number of children ("s + std::to_string(m_children.size()) + " != 3)."); - } - // 1. Parse children - auto role_from = m_children[0]->parse_role(factory); - auto role = m_children[1]->parse_role(factory); - auto role_to = m_children[2]->parse_role(factory); - if (!(role_from && role && role_to)) { - throw std::runtime_error("RoleDistanceNumerical::parse_numerical - child is not of type Role, Role, Role."); - } - return factory.make_role_distance_numerical(role_from, role, role_to); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/numericals/sum_concept_distance.h b/src/core/parser_old/expressions/numericals/sum_concept_distance.h deleted file mode 100644 index 889b5a9c..00000000 --- a/src/core/parser_old/expressions/numericals/sum_concept_distance.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_NUMERICAL_SUM_CONCEPT_DISTANCE_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_NUMERICAL_SUM_CONCEPT_DISTANCE_H_ - -#include "../numerical.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class SumConceptDistanceNumerical : public Numerical { -private: - static inline const std::string m_name = "n_sum_concept_distance"; - -public: - SumConceptDistanceNumerical(const std::string &name, std::vector> &&children) - : Numerical(name, std::move(children)) { } - - std::shared_ptr parse_numerical(SyntacticElementFactory& factory) const override { - if (m_children.size() != 3) { - throw std::runtime_error("SumConceptDistanceNumerical::parse_numerical - number of children ("s + std::to_string(m_children.size()) + " != 3)."); - } - // 1. Parse children - auto concept_from = m_children[0]->parse_concept(factory); - auto role = m_children[1]->parse_role(factory); - auto concept_to = m_children[2]->parse_concept(factory); - if (!(concept_from && role && concept_to)) { - throw std::runtime_error("SumConceptDistanceNumerical::parse_numerical - child is not of type Concept, Role, Concept."); - } - return factory.make_sum_concept_distance_numerical(concept_from, role, concept_to); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/numericals/sum_role_distance.h b/src/core/parser_old/expressions/numericals/sum_role_distance.h deleted file mode 100644 index 91320bf7..00000000 --- a/src/core/parser_old/expressions/numericals/sum_role_distance.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_NUMERICAL_SUM_ROLE_DISTANCE_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_NUMERICAL_SUM_ROLE_DISTANCE_H_ - -#include "../numerical.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class SumRoleDistanceNumerical : public Numerical { -private: - static inline const std::string m_name = "n_sum_role_distance"; - -public: - SumRoleDistanceNumerical(const std::string &name, std::vector> &&children) - : Numerical(name, std::move(children)) { } - - std::shared_ptr parse_numerical(SyntacticElementFactory& factory) const override { - if (m_children.size() != 3) { - throw std::runtime_error("SumRoleDistanceNumerical::parse_numerical - number of children ("s + std::to_string(m_children.size()) + " != 3)."); - } - // 1. Parse children - auto role_from = m_children[0]->parse_role(factory); - auto role = m_children[1]->parse_role(factory); - auto role_to = m_children[2]->parse_role(factory); - if (!(role_from && role && role_to)) { - throw std::runtime_error("SumRoleDistanceNumerical::parse_numerical - child is not of type Role, Role, Role."); - } - return factory.make_sum_role_distance_numerical(role_from, role, role_to); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/role.h b/src/core/parser_old/expressions/role.h deleted file mode 100644 index a75286ce..00000000 --- a/src/core/parser_old/expressions/role.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_ROLE_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_ROLE_H_ - -#include "expression.h" -#include "../../cache.h" - - -namespace dlplan::core { -class Role; -} - - -namespace dlplan::core::parser { - -class Role : public Expression { -public: - Role(const std::string &name, std::vector> &&children) - : Expression(name, std::move(children)) { } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/roles/and.h b/src/core/parser_old/expressions/roles/and.h deleted file mode 100644 index d9011c9d..00000000 --- a/src/core/parser_old/expressions/roles/and.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_ROLES_AND_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_ROLES_AND_H_ - -#include "../role.h" -#include "../../utils.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class AndRole : public Role { -private: - static inline const std::string m_name = "r_and"; - -public: - AndRole(const std::string &name, std::vector> &&children) - : Role(name, sort_children_lexicographically(std::move(children))) { } - - std::shared_ptr parse_role(SyntacticElementFactory& factory) const override { - if (m_children.size() != 2) { - throw std::runtime_error("AndRole::parse_role - number of children ("s + std::to_string(m_children.size()) + " != 2)."); - } - // 1. Parse children - auto role_left = m_children[0]->parse_role(factory); - auto role_right = m_children[1]->parse_role(factory); - if (!(role_left && role_right)) { - throw std::runtime_error("AndRole::parse_role - children are not of type Role."); - } - // 2. Construct element - return factory.make_and_role(role_left, role_right); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/roles/compose.h b/src/core/parser_old/expressions/roles/compose.h deleted file mode 100644 index 4c014acb..00000000 --- a/src/core/parser_old/expressions/roles/compose.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_ROLES_COMPOSE_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_ROLES_COMPOSE_H_ - -#include "../role.h" -#include "../../utils.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class ComposeRole : public Role { -private: - static inline const std::string m_name = "r_compose"; - -public: - ComposeRole(const std::string &name, std::vector> &&children) - : Role(name, std::move(children)) { } - - std::shared_ptr parse_role(SyntacticElementFactory& factory) const override { - if (m_children.size() != 2) { - throw std::runtime_error("ComposeRole::parse_role - number of children ("s + std::to_string(m_children.size()) + " != 2)."); - } - // 1. Parse children - auto role_left = m_children[0]->parse_role(factory); - auto role_right = m_children[1]->parse_role(factory); - if (!(role_left && role_right)) { - throw std::runtime_error("ComposeRole::parse_role - children are not of type Role."); - } - // 2. Construct element - return factory.make_compose_role(role_left, role_right); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/roles/diff.h b/src/core/parser_old/expressions/roles/diff.h deleted file mode 100644 index a37f52c7..00000000 --- a/src/core/parser_old/expressions/roles/diff.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_ROLES_DIFF_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_ROLES_DIFF_H_ - -#include "../role.h" -#include "../../utils.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class DiffRole : public Role { -private: - static inline const std::string m_name = "r_diff"; - -public: - DiffRole(const std::string &name, std::vector> &&children) - : Role(name, std::move(children)) { } - - std::shared_ptr parse_role(SyntacticElementFactory& factory) const override { - if (m_children.size() != 2) { - throw std::runtime_error("DiffRole::parse_role - number of children ("s + std::to_string(m_children.size()) + " != 2)."); - } - // 1. Parse children - auto role_left = m_children[0]->parse_role(factory); - auto role_right = m_children[1]->parse_role(factory); - if (!(role_left && role_right)) { - throw std::runtime_error("DiffRole::parse_role - children are not of type Role."); - } - // 2. Construct element - return factory.make_diff_role(role_left, role_right); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/roles/identity.h b/src/core/parser_old/expressions/roles/identity.h deleted file mode 100644 index 1ad71ba1..00000000 --- a/src/core/parser_old/expressions/roles/identity.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_ROLES_IDENTITY_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_ROLES_IDENTITY_H_ - -#include "../role.h" -#include "../concept.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class IdentityRole : public Role { -private: - static inline const std::string m_name = "r_identity"; - -public: - IdentityRole(const std::string &name, std::vector> &&children) - : Role(name, std::move(children)) { } - - std::shared_ptr parse_role(SyntacticElementFactory& factory) const override { - if (m_children.size() != 1) { - throw std::runtime_error("IdentityRole::parse_role - number of children ("s + std::to_string(m_children.size()) + " != 1)."); - } - // 1. Parse children - auto concept = m_children[0]->parse_concept(factory); - if (!concept) { - throw std::runtime_error("IdentityRole::parse_role - child is not of type concept"); - } - // 2. Construct element - return factory.make_identity_role(concept); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/roles/inverse.h b/src/core/parser_old/expressions/roles/inverse.h deleted file mode 100644 index 663bf75a..00000000 --- a/src/core/parser_old/expressions/roles/inverse.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_ROLES_INVERSE_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_ROLES_INVERSE_H_ - -#include "../role.h" -#include "../concept.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class InverseRole : public Role { -private: - static inline const std::string m_name = "r_inverse"; - -public: - InverseRole(const std::string &name, std::vector> &&children) - : Role(name, std::move(children)) { } - - std::shared_ptr parse_role(SyntacticElementFactory& factory) const override { - if (m_children.size() != 1) { - throw std::runtime_error("InverseRole::parse_role - number of children ("s + std::to_string(m_children.size()) + " != 1)."); - } - // 1. Parse children - auto role = m_children[0]->parse_role(factory); - if (!role) { - throw std::runtime_error("InverseRole::parse_role - child is not of type role"); - } - // 2. Construct element - return factory.make_inverse_role(role); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/roles/not.h b/src/core/parser_old/expressions/roles/not.h deleted file mode 100644 index 77699f63..00000000 --- a/src/core/parser_old/expressions/roles/not.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_ROLES_NOT_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_ROLES_NOT_H_ - -#include "../role.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class NotRole : public Role { -private: - static inline const std::string m_name = "r_not"; - -public: - NotRole(const std::string &name, std::vector> &&children) - : Role(name, std::move(children)) { } - - std::shared_ptr parse_role(SyntacticElementFactory& factory) const override { - if (m_children.size() != 1) { - throw std::runtime_error("NotRole::parse_role - number of children ("s + std::to_string(m_children.size()) + " != 1)."); - } - // 1. Parse children - auto role = m_children[0]->parse_role(factory); - if (!role) { - throw std::runtime_error("NotRole::parse_role - child is not of type Role."); - } - // 2. Construct element - return factory.make_not_role(role); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/roles/or.h b/src/core/parser_old/expressions/roles/or.h deleted file mode 100644 index 530d87dd..00000000 --- a/src/core/parser_old/expressions/roles/or.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_ROLES_OR_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_ROLES_OR_H_ - -#include "../role.h" -#include "../../utils.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class OrRole : public Role { -private: - static inline const std::string m_name = "r_or"; - -public: - OrRole(const std::string &name, std::vector> &&children) - : Role(name, sort_children_lexicographically(std::move(children))) { } - - std::shared_ptr parse_role(SyntacticElementFactory& factory) const override { - if (m_children.size() != 2) { - throw std::runtime_error("OrRole::parse_role - number of children ("s + std::to_string(m_children.size()) + " != 2)."); - } - // 1. Parse children - auto left_role = m_children[0]->parse_role(factory); - auto right_role = m_children[1]->parse_role(factory); - if (!(left_role && right_role)) { - throw std::runtime_error("OrRole::parse_role - children are not of type Concept."); - } - // 2. Construct element - return factory.make_or_role(left_role, right_role); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/roles/primitive.h b/src/core/parser_old/expressions/roles/primitive.h deleted file mode 100644 index 37e4e04e..00000000 --- a/src/core/parser_old/expressions/roles/primitive.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_ROLES_PRIMITIVE_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_ROLES_PRIMITIVE_H_ - -#include "../role.h" -#include "../../utils.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class PrimitiveRole : public Role { -private: - static inline const std::string m_name = "r_primitive"; - -public: - PrimitiveRole(const std::string &name, std::vector> &&children) - : Role(name, std::move(children)) { } - - std::shared_ptr parse_role(SyntacticElementFactory& factory) const override { - if (m_children.size() != 3) { - throw std::runtime_error("PrimitiveRole::parse_role - number of children ("s + std::to_string(m_children.size()) + " != 3)."); - } - // 1. Parse children - const auto& predicate_name = m_children[0]->get_name(); - int pos_1 = try_parse_number(m_children[1]->get_name()); - int pos_2 = try_parse_number(m_children[2]->get_name()); - // 2. Construct element - return factory.make_primitive_role(factory.get_vocabulary_info()->get_predicate(predicate_name), pos_1, pos_2); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/roles/restrict.h b/src/core/parser_old/expressions/roles/restrict.h deleted file mode 100644 index bb1474fb..00000000 --- a/src/core/parser_old/expressions/roles/restrict.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_ROLES_RESTRICT_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_ROLES_RESTRICT_H_ - -#include "../role.h" -#include "../concept.h" -#include "../../utils.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class RestrictRole : public Role { -private: - static inline const std::string m_name = "r_restrict"; - -public: - RestrictRole(const std::string &name, std::vector> &&children) - : Role(name, std::move(children)) { } - - std::shared_ptr parse_role(SyntacticElementFactory& factory) const override { - if (m_children.size() != 2) { - throw std::runtime_error("RestrictRole::parse_role - number of children ("s + std::to_string(m_children.size()) + " != 2)."); - } - // 1. Parse children - auto role = m_children[0]->parse_role(factory); - auto concept = m_children[1]->parse_concept(factory); - if (!(role && concept)) { - throw std::runtime_error("RestrictRole::parse_role - children are not of type Role."); - } - // 2. Construct element - return factory.make_restrict_role(role, concept); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/roles/top.h b/src/core/parser_old/expressions/roles/top.h deleted file mode 100644 index 35a06063..00000000 --- a/src/core/parser_old/expressions/roles/top.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_ROLES_TOP_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_ROLES_TOP_H_ - -#include "../role.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class TopRole : public Role { -private: - static inline const std::string m_name = "r_top"; - -public: - TopRole(const std::string &name, std::vector> &&children) - : Role(name, std::move(children)) { } - - std::shared_ptr parse_role(SyntacticElementFactory& factory) const override { - if (m_children.size() != 0) { - throw std::runtime_error("TopRole::parse_role - number of children ("s + std::to_string(m_children.size()) + " != 0)."); - } - // 2. Construct element - return factory.make_top_role(); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/roles/transitive_closure.h b/src/core/parser_old/expressions/roles/transitive_closure.h deleted file mode 100644 index 80af1ecb..00000000 --- a/src/core/parser_old/expressions/roles/transitive_closure.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_ROLES_TRANSITIVE_CLOSURE_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_ROLES_TRANSITIVE_CLOSURE_H_ - -#include "../role.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class TransitiveClosureRole : public Role { -private: - static inline const std::string m_name = "r_transitive_closure"; - -public: - TransitiveClosureRole(const std::string &name, std::vector> &&children) - : Role(name, std::move(children)) { } - - std::shared_ptr parse_role(SyntacticElementFactory& factory) const override { - if (m_children.size() != 1) { - throw std::runtime_error("TransitiveClosureRole::parse_role - number of children ("s + std::to_string(m_children.size()) + " != 1)."); - } - // 1. Parse children - auto role = m_children[0]->parse_role(factory); - if (!role) { - throw std::runtime_error("TransitiveClosureRole::parse_role - child is not of type Role."); - } - // 2. Construct element - return factory.make_transitive_closure(role); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/expressions/roles/transitive_reflexive_closure.h b/src/core/parser_old/expressions/roles/transitive_reflexive_closure.h deleted file mode 100644 index 72131334..00000000 --- a/src/core/parser_old/expressions/roles/transitive_reflexive_closure.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_ROLES_TRANSITIVE_REFLEXIVE_CLOSURE_H_ -#define DLPLAN_SRC_CORE_PARSER_EXPRESSIONS_ROLES_TRANSITIVE_REFLEXIVE_CLOSURE_H_ - -#include "../role.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { - -class TransitiveReflexiveClosureRole : public Role { -private: - static inline const std::string m_name = "r_transitive_reflexive_closure"; - -public: - TransitiveReflexiveClosureRole(const std::string &name, std::vector> &&children) - : Role(name, std::move(children)) { } - - std::shared_ptr parse_role(SyntacticElementFactory& factory) const override { - if (m_children.size() != 1) { - throw std::runtime_error("TransitiveReflexiveClosureRole::parse_role - number of children ("s + std::to_string(m_children.size()) + " != 1)."); - } - // 1. Parse children - auto role = m_children[0]->parse_role(factory); - if (!role) { - throw std::runtime_error("TransitiveReflexiveClosureRole::parse_role - child is not of type Role."); - } - // 2. Construct element - return factory.make_transitive_reflexive_closure(role); - } - - static const std::string& get_name() { - return m_name; - } -}; - -} - -#endif diff --git a/src/core/parser_old/parser.cpp b/src/core/parser_old/parser.cpp deleted file mode 100644 index 6e99c01c..00000000 --- a/src/core/parser_old/parser.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "parser.h" - -#include "expressions/expression.h" -#include "expression_factory.h" - -#include -#include - - -namespace dlplan::core::parser { -static TokenRegexes element_token_regexes = { - { TokenType::COMMA, Tokenizer::build_regex(",") }, - { TokenType::OPENING_PARENTHESIS, Tokenizer::build_regex("\\(") }, - { TokenType::CLOSING_PARENTHESIS, Tokenizer::build_regex("\\)") }, - { TokenType::NAME, Tokenizer::build_regex("[a-zA-Z0-9_\\-]+") }, -}; - - -/** - * Parses the canonical AST from the given tokens. - * Tokens in children are sorted lexicographically. - */ -std::unique_ptr Parser::parse_expressions_tree(Tokens &tokens) const { - if (tokens.empty()) { - throw std::runtime_error("Parser::parse_expressions_tree - Unexpected EOF\n"); - } - Token token = tokens.front(); - tokens.pop_front(); - // std::cout << token.first << " " << token.second << std::endl; - if (!tokens.empty() && tokens.front().first == TokenType::OPENING_PARENTHESIS) { - // Consume "(". - tokens.pop_front(); - std::vector> children; - while (!tokens.empty() && tokens.front().first != TokenType::CLOSING_PARENTHESIS) { - if (tokens.front().first == TokenType::COMMA) { - tokens.pop_front(); - } - children.push_back(parse_expressions_tree(tokens)); - } - // Consume ")". - if (tokens.empty()) throw std::runtime_error("Parser::parse_expressions_tree - Expected ')' is missing."); - tokens.pop_front(); - // Construct an expression that can be parsed into an element if the description is correct. - return ExpressionFactory().make_expression(token.second, std::move(children)); - } else if (token.first == TokenType::CLOSING_PARENTHESIS) { - throw std::runtime_error("Parser::parse_expressions_tree - Unexpected ')'"); - } else { - return ExpressionFactory().make_expression(token.second, {}); - } -} - -Parser::Parser() = default; - -std::unique_ptr Parser::parse( - const std::string &description) const { - Tokens tokens = Tokenizer().tokenize(description, element_token_regexes); - return parse_expressions_tree(tokens); -} - -} diff --git a/src/core/parser_old/parser.h b/src/core/parser_old/parser.h deleted file mode 100644 index 8cfa5798..00000000 --- a/src/core/parser_old/parser.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_PARSER_H_ -#define DLPLAN_SRC_CORE_PARSER_PARSER_H_ - -#include "../../utils/tokenizer.h" - -#include - - -namespace dlplan::core::parser { -class Expression; - -enum class TokenType { - COMMA, - OPENING_PARENTHESIS, - CLOSING_PARENTHESIS, - NAME -}; - -using Token = dlplan::utils::Tokenizer::Token; -using Tokens = dlplan::utils::Tokenizer::Tokens; -using Tokenizer = dlplan::utils::Tokenizer; -using TokenRegexes = dlplan::utils::Tokenizer::TokenRegexes; - -class Parser { -private: - /** - * Parses tokens into an abstract syntax tree. - */ - std::unique_ptr parse_expressions_tree(Tokens &tokens) const; - -public: - Parser(); - - /** - * Parses a textual description into an abstract syntax tree. - */ - std::unique_ptr parse(const std::string &description) const; -}; - -} - -#endif diff --git a/src/core/parser_old/utils.cpp b/src/core/parser_old/utils.cpp deleted file mode 100644 index a225270b..00000000 --- a/src/core/parser_old/utils.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "utils.h" - -using namespace std::string_literals; - - -namespace dlplan::core::parser { -int try_parse_number(const std::string& name) { - if (!std::all_of(name.begin(), name.end(), [](char c){ return isdigit(c); })) { - throw std::runtime_error("try_parse_number - error parsing ("s + name + ") to int."); - } - return atoi(name.c_str()); -} - - -bool is_number(const std::string& name) { - return std::all_of(name.begin(), name.end(), [](char c){ return isdigit(c); }); -} - -/** - * Sort child expressions lexicographically. - * We apply this in commutative expressions - * to obtain a canonical representation. - */ -std::vector> sort_children_lexicographically(std::vector> &&children) { - std::sort(children.begin(), children.end(), - [](const std::unique_ptr &l, const std::unique_ptr &r){ return l->get_name() < r->get_name(); }); - return std::move(children); -} - - -} diff --git a/src/core/parser_old/utils.h b/src/core/parser_old/utils.h deleted file mode 100644 index f77a2d13..00000000 --- a/src/core/parser_old/utils.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_PARSER_UTILS_H_ -#define DLPLAN_SRC_CORE_PARSER_UTILS_H_ - -#include "expressions/expression.h" - -#include -#include -#include -#include -#include - -using namespace std::string_literals; - - -namespace dlplan::core::parser { -extern int try_parse_number(const std::string& name); - -extern bool is_number(const std::string& name); - -/** - * Sort child expressions lexicographically. - * We apply this in commutative expressions - * to obtain a canonical representation. - */ -extern std::vector> sort_children_lexicographically(std::vector> &&children); - -} - -#endif