Skip to content

Commit

Permalink
some tests on parsing types and typed list of atomic function skeletons
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed Jan 3, 2024
1 parent 932d797 commit 6e907b2
Show file tree
Hide file tree
Showing 12 changed files with 163 additions and 133 deletions.
31 changes: 9 additions & 22 deletions include/loki/domain/ast/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ namespace loki::domain::ast
struct Requirement;

struct Type;
struct TypeObject;
struct TypeNumber;
struct TypeEither;
struct TypedListOfNamesRecursively; // :typing
struct TypedListOfNames;
Expand All @@ -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;
Expand Down Expand Up @@ -325,12 +324,18 @@ namespace loki::domain::ast
struct Type : x3::position_tagged,
x3::variant<
Name,
x3::forward_ast<TypeObject>,
x3::forward_ast<TypeNumber>,
x3::forward_ast<TypeEither>>
{
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<Type> types;
Expand Down Expand Up @@ -377,24 +382,6 @@ namespace loki::domain::ast
};

/* <function typed list (atomic function skeleton)> */
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;
};
Expand All @@ -415,7 +402,7 @@ namespace loki::domain::ast
struct FunctionTypedListOfAtomicFunctionSkeletonsRecursively : x3::position_tagged
{
std::vector<AtomicFunctionSkeleton> atomic_function_skeletons;
FunctionType function_type;
TypeNumber function_type;
boost::optional<x3::forward_ast<FunctionTypedListOfAtomicFunctionSkeletons>> function_typed_list_of_atomic_function_skeletons;
};

Expand Down
5 changes: 2 additions & 3 deletions include/loki/domain/ast/printer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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={});
Expand All @@ -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={});
Expand Down
2 changes: 0 additions & 2 deletions src/domain/ast/ast_adapted.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 9 additions & 12 deletions src/domain/ast/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ namespace loki::domain {
struct RequirementClass;

struct TypeClass;
struct TypeObjectClass;
struct TypeNumberClass;
struct TypeEitherClass;
struct TypedListOfNamesRecursivelyClass;
struct TypedListOfNamesClass;
Expand All @@ -80,9 +82,6 @@ namespace loki::domain {

struct AtomicFormulaSkeletonClass;

struct FunctionTypeNumberClass;
struct FunctionTypeTypeClass;
struct FunctionTypeClass;
struct AtomicFunctionSkeletonTotalCostClass;
struct AtomicFunctionSkeletonGeneralClass;
struct AtomicFunctionSkeletonClass;
Expand Down Expand Up @@ -215,6 +214,8 @@ namespace loki::domain {
typedef x3::rule<RequirementClass, ast::Requirement> requirement_type;

typedef x3::rule<TypeClass, ast::Type> type_type;
typedef x3::rule<TypeObjectClass, ast::TypeObject> type_object_type;
typedef x3::rule<TypeNumberClass, ast::TypeNumber> type_number_type;
typedef x3::rule<TypeEitherClass, ast::TypeEither> type_either_type;
typedef x3::rule<TypedListOfNamesRecursivelyClass, ast::TypedListOfNamesRecursively> typed_list_of_names_recursively_type;
typedef x3::rule<TypedListOfNamesClass, ast::TypedListOfNames> typed_list_of_names_type;
Expand All @@ -223,9 +224,6 @@ namespace loki::domain {

typedef x3::rule<AtomicFormulaSkeletonClass, ast::AtomicFormulaSkeleton> atomic_formula_skeleton_type;

typedef x3::rule<FunctionTypeNumberClass, ast::FunctionTypeNumber> function_type_number_type;
typedef x3::rule<FunctionTypeTypeClass, ast::FunctionTypeType> function_type_type_type;
typedef x3::rule<FunctionTypeClass, ast::FunctionType> function_type_type;
typedef x3::rule<AtomicFunctionSkeletonTotalCostClass, ast::AtomicFunctionSkeletonTotalCost> atomic_function_skeleton_total_cost_type;
typedef x3::rule<AtomicFunctionSkeletonGeneralClass, ast::AtomicFunctionSkeletonGeneral> atomic_function_skeleton_general_type;
typedef x3::rule<AtomicFunctionSkeletonClass, ast::AtomicFunctionSkeleton> atomic_function_skeleton_type;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
41 changes: 16 additions & 25 deletions src/domain/ast/parser_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand Down Expand Up @@ -239,22 +238,21 @@ 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;
const auto typed_list_of_variables_def = typed_list_of_variables_recursively | *variable;

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(')');
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {};
Expand All @@ -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 {};
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
5 changes: 2 additions & 3 deletions src/domain/ast/parser_instantiations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
23 changes: 10 additions & 13 deletions src/domain/ast/printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down
Loading

0 comments on commit 6e907b2

Please sign in to comment.