diff --git a/include/loki/domain/ast/ast.hpp b/include/loki/domain/ast/ast.hpp index 80119b86..c98fb5d3 100644 --- a/include/loki/domain/ast/ast.hpp +++ b/include/loki/domain/ast/ast.hpp @@ -63,6 +63,8 @@ namespace loki::domain::ast struct Requirement; struct Type; + struct TypeObject; + struct TypeNumber; struct TypeEither; struct TypedListOfNamesRecursively; // :typing struct TypedListOfNames; @@ -71,9 +73,6 @@ namespace loki::domain::ast struct AtomicFormulaSkeleton; - struct FunctionTypeNumber; // :numeric-fluents - struct FunctionTypeType; // :object-fluents :typing - struct FunctionType; struct AtomicFunctionSkeletonTotalCost; struct AtomicFunctionSkeletonGeneral; struct AtomicFunctionSkeleton; @@ -325,12 +324,18 @@ namespace loki::domain::ast struct Type : x3::position_tagged, x3::variant< Name, + x3::forward_ast, + x3::forward_ast, x3::forward_ast> { using base_type::base_type; using base_type::operator=; }; + struct TypeObject : x3::position_tagged { }; + + struct TypeNumber : x3::position_tagged { }; + struct TypeEither : x3::position_tagged { std::vector types; @@ -377,24 +382,6 @@ namespace loki::domain::ast }; /* */ - struct FunctionTypeNumber : x3::position_tagged - { - Number number; - }; - - struct FunctionTypeType : x3::position_tagged - { - Type type; - }; - - struct FunctionType : x3::position_tagged, - x3::variant< - FunctionTypeNumber, - FunctionTypeType> { - using base_type::base_type; - using base_type::operator=; - }; - struct AtomicFunctionSkeletonTotalCost : x3::position_tagged { FunctionSymbol function_symbol; }; @@ -415,7 +402,7 @@ namespace loki::domain::ast struct FunctionTypedListOfAtomicFunctionSkeletonsRecursively : x3::position_tagged { std::vector atomic_function_skeletons; - FunctionType function_type; + TypeNumber function_type; boost::optional> function_typed_list_of_atomic_function_skeletons; }; diff --git a/include/loki/domain/ast/printer.hpp b/include/loki/domain/ast/printer.hpp index e66a4173..ecdec6f0 100644 --- a/include/loki/domain/ast/printer.hpp +++ b/include/loki/domain/ast/printer.hpp @@ -54,6 +54,8 @@ extern std::string parse_text(const domain::ast::RequirementActionCosts& node, c extern std::string parse_text(const domain::ast::Requirement& node, const FormattingOptions& options={}); extern std::string parse_text(const domain::ast::Type& node, const FormattingOptions& options={}); +extern std::string parse_text(const domain::ast::TypeObject& node, const FormattingOptions& options={}); +extern std::string parse_text(const domain::ast::TypeNumber& node, const FormattingOptions& options={}); extern std::string parse_text(const domain::ast::TypeEither& node, const FormattingOptions& options={}); extern std::string parse_text(const domain::ast::TypedListOfNamesRecursively& node, const FormattingOptions& options={}); extern std::string parse_text(const domain::ast::TypedListOfNames& node, const FormattingOptions& options={}); @@ -62,9 +64,6 @@ extern std::string parse_text(const domain::ast::TypedListOfVariables& node, con extern std::string parse_text(const domain::ast::AtomicFormulaSkeleton& node, const FormattingOptions& options={}); -extern std::string parse_text(const domain::ast::FunctionTypeNumber& node, const FormattingOptions& options={}); -extern std::string parse_text(const domain::ast::FunctionTypeType& node, const FormattingOptions& options={}); -extern std::string parse_text(const domain::ast::FunctionType& node, const FormattingOptions& options={}); extern std::string parse_text(const domain::ast::AtomicFunctionSkeletonTotalCost& node, const FormattingOptions& options={}); extern std::string parse_text(const domain::ast::AtomicFunctionSkeletonGeneral& node, const FormattingOptions& options={}); extern std::string parse_text(const domain::ast::AtomicFunctionSkeleton& node, const FormattingOptions& options={}); diff --git a/src/domain/ast/ast_adapted.hpp b/src/domain/ast/ast_adapted.hpp index 8bde90f3..034c7e42 100644 --- a/src/domain/ast/ast_adapted.hpp +++ b/src/domain/ast/ast_adapted.hpp @@ -38,8 +38,6 @@ BOOST_FUSION_ADAPT_STRUCT(loki::domain::ast::TypedListOfVariablesRecursively, va BOOST_FUSION_ADAPT_STRUCT(loki::domain::ast::AtomicFormulaSkeleton, predicate, typed_list_of_variables) -BOOST_FUSION_ADAPT_STRUCT(loki::domain::ast::FunctionTypeNumber, number) -BOOST_FUSION_ADAPT_STRUCT(loki::domain::ast::FunctionTypeType, type) BOOST_FUSION_ADAPT_STRUCT(loki::domain::ast::AtomicFunctionSkeletonTotalCost, function_symbol) BOOST_FUSION_ADAPT_STRUCT(loki::domain::ast::AtomicFunctionSkeletonGeneral, function_symbol, arguments) BOOST_FUSION_ADAPT_STRUCT(loki::domain::ast::FunctionTypedListOfAtomicFunctionSkeletonsRecursively, atomic_function_skeletons, function_type, function_typed_list_of_atomic_function_skeletons) diff --git a/src/domain/ast/parser.hpp b/src/domain/ast/parser.hpp index 502c027b..69b267f4 100644 --- a/src/domain/ast/parser.hpp +++ b/src/domain/ast/parser.hpp @@ -72,6 +72,8 @@ namespace loki::domain { struct RequirementClass; struct TypeClass; + struct TypeObjectClass; + struct TypeNumberClass; struct TypeEitherClass; struct TypedListOfNamesRecursivelyClass; struct TypedListOfNamesClass; @@ -80,9 +82,6 @@ namespace loki::domain { struct AtomicFormulaSkeletonClass; - struct FunctionTypeNumberClass; - struct FunctionTypeTypeClass; - struct FunctionTypeClass; struct AtomicFunctionSkeletonTotalCostClass; struct AtomicFunctionSkeletonGeneralClass; struct AtomicFunctionSkeletonClass; @@ -215,6 +214,8 @@ namespace loki::domain { typedef x3::rule requirement_type; typedef x3::rule type_type; + typedef x3::rule type_object_type; + typedef x3::rule type_number_type; typedef x3::rule type_either_type; typedef x3::rule typed_list_of_names_recursively_type; typedef x3::rule typed_list_of_names_type; @@ -223,9 +224,6 @@ namespace loki::domain { typedef x3::rule atomic_formula_skeleton_type; - typedef x3::rule function_type_number_type; - typedef x3::rule function_type_type_type; - typedef x3::rule function_type_type; typedef x3::rule atomic_function_skeleton_total_cost_type; typedef x3::rule atomic_function_skeleton_general_type; typedef x3::rule atomic_function_skeleton_type; @@ -337,13 +335,13 @@ namespace loki::domain { requirement_constraints_type, requirement_action_costs_type, requirement_type) BOOST_SPIRIT_DECLARE( - type_type, type_either_type, typed_list_of_names_recursively_type, typed_list_of_names_type, + type_type, type_object_type, type_number_type, type_either_type, + typed_list_of_names_recursively_type, typed_list_of_names_type, typed_list_of_variables_recursively_type, typed_list_of_variables_type) BOOST_SPIRIT_DECLARE(atomic_formula_skeleton_type) - BOOST_SPIRIT_DECLARE(function_type_number_type, function_type_type_type, function_type_type, - atomic_function_skeleton_total_cost_type, atomic_function_skeleton_general_type, atomic_function_skeleton_type, + BOOST_SPIRIT_DECLARE(atomic_function_skeleton_total_cost_type, atomic_function_skeleton_general_type, atomic_function_skeleton_type, function_typed_list_of_atomic_function_skeletons_recursively_type, function_typed_list_of_atomic_function_skeletons_type) BOOST_SPIRIT_DECLARE(atomic_formula_of_terms_type, atom_type, negated_atom_type, literal_type) @@ -440,6 +438,8 @@ namespace loki::domain { parser::requirement_type const& requirement(); parser::type_type const& type(); + parser::type_object_type const& type_object(); + parser::type_number_type const& type_number(); parser::type_either_type const& type_either(); parser::typed_list_of_names_recursively_type const& typed_list_of_names_recursively(); parser::typed_list_of_names_type const& typed_list_of_names(); @@ -462,9 +462,6 @@ namespace loki::domain { parser::binary_comparator_less_equal_type const& binary_comparator_less_equal(); parser::binary_comparator_type const& binary_comparator(); - parser::function_type_number_type const& function_type_number(); - parser::function_type_type_type const& function_type_type_(); - parser::function_type_type const& function_type(); parser::atomic_function_skeleton_total_cost_type const& atomic_function_skeleton_total_cost(); parser::atomic_function_skeleton_general_type const& atomic_function_skeleton_general(); parser::atomic_function_skeleton_type const& atomic_function_skeleton(); diff --git a/src/domain/ast/parser_def.hpp b/src/domain/ast/parser_def.hpp index 50c24ce8..d402af26 100644 --- a/src/domain/ast/parser_def.hpp +++ b/src/domain/ast/parser_def.hpp @@ -91,6 +91,8 @@ namespace loki::domain::parser { requirement_type const requirement = "requirement"; type_type const type = "type"; + type_object_type const type_object = "type_object"; + type_number_type const type_number = "type_number"; type_either_type const type_either = "type_either"; typed_list_of_names_recursively_type const typed_list_of_names_recursively = "typed_list_of_names_recursively"; typed_list_of_names_type const typed_list_of_names = "typed_list_of_names"; @@ -99,9 +101,6 @@ namespace loki::domain::parser { atomic_formula_skeleton_type const atomic_formula_skeleton = "atomic_formula_skeleton"; - function_type_number_type const function_type_number = "function_type_number"; - function_type_type_type const function_type_type_ = "function_type_type"; - function_type_type const function_type = "function_type"; atomic_function_skeleton_total_cost_type const atomic_function_skeleton_total_cost = "atomic_function_skeleton_total_cost"; atomic_function_skeleton_general_type const atomic_function_skeleton_general = "atomic_function_skeleton_general"; atomic_function_skeleton_type const atomic_function_skeleton = "atomic_function_skeleton"; @@ -239,8 +238,10 @@ namespace loki::domain::parser { | requirement_durative_actions | requirement_derived_predicates | requirement_timed_initial_literals | requirement_preferences | requirement_constraints | requirement_action_costs; - const auto type_def = type_either | name; - const auto type_either_def = (lit('(') >> keyword_lit("either") >> +type) > lit(')'); + const auto type_def = type_object | type_number | type_either | name; + const auto type_object_def = keyword_lit("object") > x3::attr(ast::TypeObject{}); + const auto type_number_def = keyword_lit("number") > x3::attr(ast::TypeNumber{}); + const auto type_either_def = (lit('(') >> keyword_lit("either") > +type) > lit(')'); const auto typed_list_of_names_recursively_def = (+name >> lit('-')) > type > typed_list_of_names; const auto typed_list_of_names_def = typed_list_of_names_recursively | *name; const auto typed_list_of_variables_recursively_def = (+variable >> lit('-')) > type > typed_list_of_variables; @@ -248,13 +249,10 @@ namespace loki::domain::parser { const auto atomic_formula_skeleton_def = lit('(') > predicate > typed_list_of_variables > lit(')'); - const auto function_type_number_def = number; - const auto function_type_type__def = type; - const auto function_type_def = function_type_number | function_type_type_; const auto atomic_function_skeleton_total_cost_def = lit('(') >> function_symbol_total_cost > lit(')'); const auto atomic_function_skeleton_general_def = lit('(') > function_symbol > typed_list_of_variables > lit(')'); const auto atomic_function_skeleton_def = atomic_function_skeleton_total_cost | atomic_function_skeleton_general; - const auto function_typed_list_of_atomic_function_skeletons_recursively_def = (+atomic_function_skeleton >> lit('-')) > function_type > -function_typed_list_of_atomic_function_skeletons; + const auto function_typed_list_of_atomic_function_skeletons_recursively_def = (+atomic_function_skeleton >> lit('-')) > type_number > -function_typed_list_of_atomic_function_skeletons; const auto function_typed_list_of_atomic_function_skeletons_def = function_typed_list_of_atomic_function_skeletons_recursively | +atomic_function_skeleton; const auto atomic_formula_of_terms_predicate_def = (lit('(') >> predicate) > *term > lit(')'); @@ -385,13 +383,12 @@ namespace loki::domain::parser { requirement_derived_predicates, requirement_timed_initial_literals, requirement_preferences, requirement_constraints, requirement_action_costs, requirement) - BOOST_SPIRIT_DEFINE(type, type_either, typed_list_of_names_recursively, + BOOST_SPIRIT_DEFINE(type, type_object, type_number, type_either, typed_list_of_names_recursively, typed_list_of_names, typed_list_of_variables_recursively, typed_list_of_variables) BOOST_SPIRIT_DEFINE(atomic_formula_skeleton) - BOOST_SPIRIT_DEFINE(function_type_number, function_type_type_, function_type, - atomic_function_skeleton_total_cost, atomic_function_skeleton_general, atomic_function_skeleton, + BOOST_SPIRIT_DEFINE(atomic_function_skeleton_total_cost, atomic_function_skeleton_general, atomic_function_skeleton, function_typed_list_of_atomic_function_skeletons_recursively, function_typed_list_of_atomic_function_skeletons) BOOST_SPIRIT_DEFINE(atomic_formula_of_terms_predicate, atomic_formula_of_terms_equality, @@ -472,6 +469,7 @@ namespace loki::domain::parser { struct TypeClass : x3::annotate_on_success {}; struct TypeObjectClass : x3::annotate_on_success {}; + struct TypeNumberClass : x3::annotate_on_success {}; struct TypeEitherClass : x3::annotate_on_success {}; struct TypedListOfNamesRecursivelyClass : x3::annotate_on_success {}; struct TypedListOfNamesClass : x3::annotate_on_success {}; @@ -480,10 +478,6 @@ namespace loki::domain::parser { struct AtomicFormulaSkeletonClass : x3::annotate_on_success {}; - struct FunctionTypeNumberClass : x3::annotate_on_success {}; - struct FunctionTypeObjectClass : x3::annotate_on_success {}; - struct FunctionTypeTypeClass : x3::annotate_on_success {}; - struct FunctionTypeClass : x3::annotate_on_success {}; struct AtomicFunctionSkeletonTotalCostClass : x3::annotate_on_success {}; struct AtomicFunctionSkeletonGeneralClass : x3::annotate_on_success {}; struct AtomicFunctionSkeletonClass : x3::annotate_on_success {}; @@ -682,6 +676,12 @@ namespace loki::domain parser::type_type const& type() { return parser::type; } + parser::type_object_type const& type_object() { + return parser::type_object; + } + parser::type_number_type const& type_number() { + return parser::type_number; + } parser::type_either_type const& type_either() { return parser::type_either; } @@ -702,15 +702,6 @@ namespace loki::domain return parser::atomic_formula_skeleton; } - parser::function_type_number_type const& function_type_number() { - return parser::function_type_number; - } - parser::function_type_type_type const& function_type_type_() { - return parser::function_type_type_; - } - parser::function_type_type const& function_type() { - return parser::function_type; - } parser::atomic_function_skeleton_total_cost_type const& atomic_function_skeleton_total_cost() { return parser::atomic_function_skeleton_total_cost; } diff --git a/src/domain/ast/parser_instantiations.cpp b/src/domain/ast/parser_instantiations.cpp index ccd941e3..a5e8581d 100644 --- a/src/domain/ast/parser_instantiations.cpp +++ b/src/domain/ast/parser_instantiations.cpp @@ -57,6 +57,8 @@ namespace loki::domain::parser BOOST_SPIRIT_INSTANTIATE(requirement_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(type_type, iterator_type, context_type) + BOOST_SPIRIT_INSTANTIATE(type_object_type, iterator_type, context_type) + BOOST_SPIRIT_INSTANTIATE(type_number_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(type_either_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(typed_list_of_names_recursively_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(typed_list_of_names_type, iterator_type, context_type) @@ -65,9 +67,6 @@ namespace loki::domain::parser BOOST_SPIRIT_INSTANTIATE(atomic_formula_skeleton_type, iterator_type, context_type) - BOOST_SPIRIT_INSTANTIATE(function_type_number_type, iterator_type, context_type) - BOOST_SPIRIT_INSTANTIATE(function_type_type_type, iterator_type, context_type) - BOOST_SPIRIT_INSTANTIATE(function_type_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(atomic_function_skeleton_total_cost_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(atomic_function_skeleton_general_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(atomic_function_skeleton_type, iterator_type, context_type) diff --git a/src/domain/ast/printer.cpp b/src/domain/ast/printer.cpp index 22116556..80888c73 100644 --- a/src/domain/ast/printer.cpp +++ b/src/domain/ast/printer.cpp @@ -108,6 +108,16 @@ namespace loki return boost::apply_visitor(NodeVisitorPrinter(options), node); } + string parse_text(const domain::ast::TypeObject& /*node*/, const FormattingOptions& /*options*/) + { + return "object"; + } + + string parse_text(const domain::ast::TypeNumber& /*node*/, const FormattingOptions& /*options*/) + { + return "number"; + } + string parse_text(const domain::ast::TypeEither& node, const FormattingOptions& options) { stringstream ss; @@ -183,19 +193,6 @@ namespace loki return ss.str(); } - std::string parse_text(const domain::ast::FunctionTypeNumber& node, const FormattingOptions& options) - { - return parse_text(node.number, options); - } - - std::string parse_text(const domain::ast::FunctionTypeType& node, const FormattingOptions& options) - { - return parse_text(node.type, options); - } - - std::string parse_text(const domain::ast::FunctionType& node, const FormattingOptions& options) { - return boost::apply_visitor(NodeVisitorPrinter(options), node); - } std::string parse_text(const domain::ast::AtomicFunctionSkeletonTotalCost& node, const FormattingOptions& options) { diff --git a/src/domain/pddl/parser/types.cpp b/src/domain/pddl/parser/types.cpp index f4f19b37..7021e2a0 100644 --- a/src/domain/pddl/parser/types.cpp +++ b/src/domain/pddl/parser/types.cpp @@ -31,22 +31,30 @@ namespace loki { TypeDeclarationTypeVisitor::TypeDeclarationTypeVisitor(Context& context_) : context(context_) { } -pddl::TypeList TypeDeclarationTypeVisitor::operator()(const ast::Type& type_node) { - return boost::apply_visitor(*this, type_node); +pddl::TypeList TypeDeclarationTypeVisitor::operator()(const ast::TypeObject& node) { + const auto type = context.factories.types.get_or_create("object"); + context.positions.push_back(type, node); + return { type }; +} + +pddl::TypeList TypeDeclarationTypeVisitor::operator()(const ast::TypeNumber& node) { + const auto type = context.factories.types.get_or_create("number"); + context.positions.push_back(type, node); + return { type }; } -pddl::TypeList TypeDeclarationTypeVisitor::operator()(const domain::ast::Name& name_node) { - auto name = parse(name_node); +pddl::TypeList TypeDeclarationTypeVisitor::operator()(const domain::ast::Name& node) { + auto name = parse(node); const auto type = context.factories.types.get_or_create(name); - context.positions.push_back(type, name_node); + context.positions.push_back(type, node); return { type }; } -pddl::TypeList TypeDeclarationTypeVisitor::operator()(const ast::TypeEither& either_type_node) { +pddl::TypeList TypeDeclarationTypeVisitor::operator()(const ast::TypeEither& node) { // we flatten nested either types pddl::TypeList type_list; - for (auto& type_node : either_type_node.types) { - auto types = this->operator()(type_node); + for (auto& child_node : node.types) { + auto types = boost::apply_visitor(*this, child_node); type_list.insert(type_list.end(), types.begin(), types.end()); } return type_list; @@ -57,26 +65,36 @@ pddl::TypeList TypeDeclarationTypeVisitor::operator()(const ast::TypeEither& eit TypeReferenceTypeVisitor::TypeReferenceTypeVisitor(const Context& context_) : context(context_) { } -pddl::TypeList TypeReferenceTypeVisitor::operator()(const ast::Type& type_node) { - return boost::apply_visitor(*this, type_node); +pddl::TypeList TypeReferenceTypeVisitor::operator()(const ast::TypeObject&) { + const auto binding = context.scopes.get("object"); + assert(binding.has_value()); + const auto& [type, _position, _error_handler] = binding.value(); + return {type}; +} + +pddl::TypeList TypeReferenceTypeVisitor::operator()(const ast::TypeNumber&) { + const auto binding = context.scopes.get("number"); + assert(binding.has_value()); + const auto& [type, _position, _error_handler] = binding.value(); + return {type}; } -pddl::TypeList TypeReferenceTypeVisitor::operator()(const domain::ast::Name& name_node) { - auto name = parse(name_node); +pddl::TypeList TypeReferenceTypeVisitor::operator()(const domain::ast::Name& node) { + auto name = parse(node); auto binding = context.scopes.get(name); if (!binding.has_value()) { - throw UndefinedTypeError(name, context.scopes.get_error_handler()(name_node, "")); + throw UndefinedTypeError(name, context.scopes.get_error_handler()(node, "")); } const auto& [type, _position, _error_handler] = binding.value(); - context.positions.push_back(type, name_node); + context.positions.push_back(type, node); return { type }; } -pddl::TypeList TypeReferenceTypeVisitor::operator()(const ast::TypeEither& either_type_node) { +pddl::TypeList TypeReferenceTypeVisitor::operator()(const ast::TypeEither& node) { // we flatten nested either types auto type_list = pddl::TypeList(); - for (auto& type_node : either_type_node.types) { - auto types = this->operator()(type_node); + for (auto& child_node : node.types) { + auto types = boost::apply_visitor(*this, child_node); type_list.insert(type_list.end(), types.begin(), types.end()); } return type_list; diff --git a/src/domain/pddl/parser/types.hpp b/src/domain/pddl/parser/types.hpp index 3d40c09c..2d3b5c69 100644 --- a/src/domain/pddl/parser/types.hpp +++ b/src/domain/pddl/parser/types.hpp @@ -32,11 +32,13 @@ class TypeDeclarationTypeVisitor : boost::static_visitor { public: TypeDeclarationTypeVisitor(Context& context_); - pddl::TypeList operator()(const domain::ast::Type& type_node); + pddl::TypeList operator()(const domain::ast::TypeObject& node); - pddl::TypeList operator()(const domain::ast::Name& name_node); + pddl::TypeList operator()(const domain::ast::TypeNumber& node); - pddl::TypeList operator()(const domain::ast::TypeEither& either_type_node); + pddl::TypeList operator()(const domain::ast::Name& node); + + pddl::TypeList operator()(const domain::ast::TypeEither& node); }; class TypeReferenceTypeVisitor : boost::static_visitor { @@ -46,11 +48,13 @@ class TypeReferenceTypeVisitor : boost::static_visitor { public: TypeReferenceTypeVisitor(const Context& context_); - pddl::TypeList operator()(const domain::ast::Type& type_node); + pddl::TypeList operator()(const domain::ast::TypeObject& node); + + pddl::TypeList operator()(const domain::ast::TypeNumber& node); - pddl::TypeList operator()(const domain::ast::Name& name_node); + pddl::TypeList operator()(const domain::ast::Name& node); - pddl::TypeList operator()(const domain::ast::TypeEither& either_type_node); + pddl::TypeList operator()(const domain::ast::TypeEither& node); }; class TypeDeclarationTypedListOfNamesVisitor : boost::static_visitor { @@ -60,13 +64,13 @@ class TypeDeclarationTypedListOfNamesVisitor : boost::static_visitor& name_nodes); + pddl::TypeList operator()(const std::vector& nodes); - pddl::TypeList operator()(const domain::ast::TypedListOfNamesRecursively& typed_list_of_names_recursively_node); + pddl::TypeList operator()(const domain::ast::TypedListOfNamesRecursively& node); }; -extern pddl::TypeList parse(const domain::ast::Types& types_node, Context& context); +extern pddl::TypeList parse(const domain::ast::Types& node, Context& context); } diff --git a/tests/common/pddl/reference.cpp b/tests/common/pddl/reference.cpp new file mode 100644 index 00000000..7f193210 --- /dev/null +++ b/tests/common/pddl/reference.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2023 Dominik Drexler + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "../../../include/loki/common/pddl/persistent_factory.hpp" +#include "../../../include/loki/common/pddl/reference.hpp" +#include "../../../include/loki/domain/pddl/object.hpp" + + +namespace loki::domain::tests { + +TEST(LokiTests, ReferenceTest) { + PersistentFactory factory; + const auto object_0 = factory.get_or_create("object_0"); + const auto object_1 = factory.get_or_create("object_1"); + + ReferencedPDDLObjects references; + EXPECT_TRUE(!references.exists(object_0)); + EXPECT_TRUE(!references.exists(object_1)); + references.track(object_0); + EXPECT_TRUE(references.exists(object_0)); + references.track(object_1); + EXPECT_TRUE(references.exists(object_1)); + references.untrack(object_0); + EXPECT_TRUE(!references.exists(object_0)); +} + +} diff --git a/tests/domain/ast/function_type.cpp b/tests/domain/ast/function_symbol_total_cost.cpp similarity index 52% rename from tests/domain/ast/function_type.cpp rename to tests/domain/ast/function_symbol_total_cost.cpp index c5a81397..ce63d24e 100644 --- a/tests/domain/ast/function_type.cpp +++ b/tests/domain/ast/function_symbol_total_cost.cpp @@ -24,29 +24,19 @@ namespace loki::domain::tests { -TEST(LokiTests, FunctionTypeTest) { - ast::FunctionType ast; - - // Number (int) - EXPECT_NO_THROW(parse_ast("5", function_type(), ast)); - EXPECT_EQ(parse_text(ast), "5"); - EXPECT_NO_THROW(parse_ast("6 7", function_type(), ast)); - EXPECT_EQ(parse_text(ast), "6"); - // TODO: Is this really what we want? - EXPECT_NO_THROW(parse_ast("1loki", function_type(), ast)); - EXPECT_EQ(parse_text(ast), "1"); - - // Number (float) - EXPECT_NO_THROW(parse_ast("4.2", function_type(), ast)); - EXPECT_EQ(parse_text(ast), "4.2"); - - // Type - EXPECT_NO_THROW(parse_ast("loki", function_type(), ast)); - EXPECT_EQ(parse_text(ast), "loki"); - EXPECT_NO_THROW(parse_ast("(either type1 type2)", function_type(), ast)); - EXPECT_EQ(parse_text(ast), "(either type1 type2)"); - - EXPECT_ANY_THROW(parse_ast("(5)", function_type(), ast)); +TEST(LokiTests, FunctionSymbolTotalCostTest) { + ast::FunctionSymbol ast; + + EXPECT_NO_THROW(parse_ast("total-cost ", function_symbol_total_cost(), ast)); + EXPECT_EQ(parse_text(ast), "total-cost"); + EXPECT_NO_THROW(parse_ast("total-cost(", function_symbol_total_cost(), ast)); + EXPECT_NO_THROW(parse_ast("total-cost)", function_symbol_total_cost(), ast)); + EXPECT_NO_THROW(parse_ast("total-cost\n", function_symbol_total_cost(), ast)); + + // no separator after "total-cost" keyword + EXPECT_ANY_THROW(parse_ast("total-cost", function_symbol_total_cost(), ast)); // no separator + // wrong keyword + EXPECT_ANY_THROW(parse_ast("loki ", function_symbol_total_cost(), ast)); } } diff --git a/tests/domain/ast/function_typed_list_of_atom_function_skeletons.cpp b/tests/domain/ast/function_typed_list_of_atom_function_skeletons.cpp index 9728e40b..e13f9c8f 100644 --- a/tests/domain/ast/function_typed_list_of_atom_function_skeletons.cpp +++ b/tests/domain/ast/function_typed_list_of_atom_function_skeletons.cpp @@ -27,10 +27,17 @@ namespace loki::domain::tests { TEST(LokiTests, FunctionTypedListOfAtomicFunctionSkeletonsTest) { ast::FunctionTypedListOfAtomicFunctionSkeletons ast; - EXPECT_NO_THROW(parse_ast("(function-symbol1 ?var1 ?var2) - function-type1", function_typed_list_of_atomic_function_skeletons(), ast)); - EXPECT_EQ(parse_text(ast), "(function-symbol1 ?var1 ?var2) - function-type1"); - - + EXPECT_NO_THROW(parse_ast("(function-symbol1 ?var1 ?var2) - number ", function_typed_list_of_atomic_function_skeletons(), ast)); + EXPECT_EQ(parse_text(ast), "(function-symbol1 ?var1 ?var2) - number"); + EXPECT_NO_THROW(parse_ast("(function-symbol1 ?var1 ?var2) - number)", function_typed_list_of_atomic_function_skeletons(), ast)); + EXPECT_NO_THROW(parse_ast("(function-symbol1 ?var1 ?var2) - number\n", function_typed_list_of_atomic_function_skeletons(), ast)); + + // trailing "(" indicates another atomic function skeleton that fails to be parsed. + EXPECT_ANY_THROW(parse_ast("(function-symbol1 ?var1 ?var2) - number(", function_typed_list_of_atomic_function_skeletons(), ast)); + // no trailing separator after "number" keyword + EXPECT_ANY_THROW(parse_ast("(function-symbol1 ?var1 ?var2) - number", function_typed_list_of_atomic_function_skeletons(), ast)); + // function type does not match "number" + EXPECT_ANY_THROW(parse_ast("(function-symbol1 ?var1 ?var2) - wrong ", function_typed_list_of_atomic_function_skeletons(), ast)); } }