Skip to content

Commit

Permalink
some more convenient parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed Nov 27, 2023
1 parent 5ffd21d commit bcaed73
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
7 changes: 5 additions & 2 deletions include/dlplan/policy/parsers/syntactic/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <boost/spirit/home/x3/support/ast/position_tagged.hpp>
#include <boost/spirit/home/x3/support/ast/variant.hpp>
#include <boost/optional.hpp>

#include <vector>

Expand Down Expand Up @@ -285,8 +286,10 @@ namespace dlplan::policy::ast

/* Policy */
struct Policy : x3::position_tagged {
Booleans booleans;
Numericals numericals;
boost::optional<Booleans> booleans;
boost::optional<Numericals> numericals;
boost::optional<Concepts> concepts;
boost::optional<Roles> roles;
Rules rules;
};
}
Expand Down
8 changes: 6 additions & 2 deletions src/policy/parsers/semantic/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,12 @@ Rules parse(

std::shared_ptr<const Policy> parse(
const ast::Policy& node, const dlplan::error_handler_type& error_handler, Context& context) {
parse(node.booleans, error_handler, context);
parse(node.numericals, error_handler, context);
if (node.booleans.has_value()) {
parse(node.booleans.value(), error_handler, context);
}
if (node.numericals.has_value()) {
parse(node.numericals.value(), error_handler, context);
}
return context.policy_factory.make_policy(parse(node.rules, error_handler, context));
}

Expand Down
2 changes: 1 addition & 1 deletion src/policy/parsers/syntactic/ast_adapted.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ BOOST_FUSION_ADAPT_STRUCT(dlplan::policy::ast::EqualConceptEffect, reference)

BOOST_FUSION_ADAPT_STRUCT(dlplan::policy::ast::Rule, feature_conditions, feature_effects)
BOOST_FUSION_ADAPT_STRUCT(dlplan::policy::ast::Rules, rules)
BOOST_FUSION_ADAPT_STRUCT(dlplan::policy::ast::Policy, booleans, numericals, rules)
BOOST_FUSION_ADAPT_STRUCT(dlplan::policy::ast::Policy, booleans, numericals, concepts, roles, rules)

#endif
6 changes: 4 additions & 2 deletions src/policy/parsers/syntactic/parser_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,10 @@ namespace dlplan::policy::parser
const auto rules_def = *rule;

const auto policy_def = lit('(') > lit(":policy")
> booleans
> numericals
> -booleans
> -numericals
> -concepts
> -roles
> rules
> lit(')');
const auto policy_root_def = policy;
Expand Down

0 comments on commit bcaed73

Please sign in to comment.