Skip to content

Commit

Permalink
improved error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed Oct 15, 2023
1 parent 6f58bf9 commit 5b8e809
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 34 deletions.
2 changes: 1 addition & 1 deletion examples/core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ int main() {
State state_1(instance, {atom_1, atom_3, atom_6}, 1); // b on a
States states{state_0, state_1};

auto numerical = factory.parse_numerical("n_cunt(c_and(c_primitive(on_g,0),c_primitive(on,0)))");
auto numerical = factory.parse_numerical("n_count(c_and(c_primitive(on_g,0),c_primitive(on,0)))");
std::cout << "Element repr: " << numerical->compute_repr() << std::endl << std::endl;

std::cout << "Evaluate for single state without cache." << std::endl;
Expand Down
45 changes: 35 additions & 10 deletions src/core/parsers/elements/stage_1_ast/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,19 @@ namespace dlplan::core::parsers::elements::stage_1::ast
int value;
};

struct Boolean : x3::position_tagged, x3::variant<
struct BooleanInner : x3::position_tagged, x3::variant<
x3::forward_ast<EmptyBoolean>,
x3::forward_ast<InclusionBoolean>,
x3::forward_ast<NullaryBoolean>> {
using base_type::base_type;
using base_type::operator=;
};

struct Concept : x3::position_tagged, x3::variant<
struct Boolean : x3::position_tagged {
BooleanInner boolean;
};

struct ConceptInner : x3::position_tagged, x3::variant<
x3::forward_ast<PrimitiveConcept>,
x3::forward_ast<AllConcept>,
x3::forward_ast<AndConcept>,
Expand All @@ -100,8 +104,11 @@ namespace dlplan::core::parsers::elements::stage_1::ast
using base_type::operator=;
};

struct Concept : x3::position_tagged {
ConceptInner concept;
};

struct Numerical : x3::position_tagged, x3::variant<
struct NumericalInner : x3::position_tagged, x3::variant<
x3::forward_ast<ConceptDistanceNumerical>,
x3::forward_ast<CountNumerical>,
x3::forward_ast<RoleDistanceNumerical>,
Expand All @@ -111,7 +118,11 @@ namespace dlplan::core::parsers::elements::stage_1::ast
using base_type::operator=;
};

struct Role : x3::position_tagged, x3::variant<
struct Numerical : x3::position_tagged {
NumericalInner numerical;
};

struct RoleInner : x3::position_tagged, x3::variant<
x3::forward_ast<PrimitiveRole>,
x3::forward_ast<AndRole>,
x3::forward_ast<ComposeRole>,
Expand All @@ -128,8 +139,11 @@ namespace dlplan::core::parsers::elements::stage_1::ast
using base_type::operator=;
};

struct Role : x3::position_tagged {
RoleInner role;
};

struct Element : x3::position_tagged, x3::variant<
struct ElementInner : x3::position_tagged, x3::variant<
x3::forward_ast<Concept>,
x3::forward_ast<Role>,
x3::forward_ast<Boolean>,
Expand All @@ -138,16 +152,27 @@ namespace dlplan::core::parsers::elements::stage_1::ast
using base_type::operator=;
};

struct ElementWrapper : x3::position_tagged {
Element element;
struct Element : x3::position_tagged {
ElementInner element;
};

struct ConceptOrRoleInner : x3::position_tagged, x3::variant<
x3::forward_ast<Concept>,
x3::forward_ast<Role>> {
using base_type::base_type;
using base_type::operator=;
};

struct ConceptOrRole : x3::position_tagged {
ConceptOrRoleInner inner;
};

struct EmptyBoolean : x3::position_tagged {
x3::variant<Concept, Role> element;
ConceptOrRole element;
};

struct InclusionBoolean : x3::position_tagged {
x3::variant<Concept, Role> element;
ConceptOrRole element;
};

struct NullaryBoolean : x3::position_tagged {
Expand Down Expand Up @@ -220,7 +245,7 @@ namespace dlplan::core::parsers::elements::stage_1::ast
};

struct CountNumerical : x3::position_tagged {
x3::variant<Concept, Role> element;
ConceptOrRole element;
};

struct RoleDistanceNumerical : x3::position_tagged {
Expand Down
7 changes: 6 additions & 1 deletion src/core/parsers/elements/stage_1_ast/ast_adapted.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ BOOST_FUSION_ADAPT_STRUCT(dlplan::core::parsers::elements::stage_1::ast::Name, a
BOOST_FUSION_ADAPT_STRUCT(dlplan::core::parsers::elements::stage_1::ast::Constant, name)
BOOST_FUSION_ADAPT_STRUCT(dlplan::core::parsers::elements::stage_1::ast::Predicate, name)
BOOST_FUSION_ADAPT_STRUCT(dlplan::core::parsers::elements::stage_1::ast::Position, value)
BOOST_FUSION_ADAPT_STRUCT(dlplan::core::parsers::elements::stage_1::ast::ElementWrapper, element)
BOOST_FUSION_ADAPT_STRUCT(dlplan::core::parsers::elements::stage_1::ast::Boolean, boolean)
BOOST_FUSION_ADAPT_STRUCT(dlplan::core::parsers::elements::stage_1::ast::Concept, concept)
BOOST_FUSION_ADAPT_STRUCT(dlplan::core::parsers::elements::stage_1::ast::Numerical, numerical)
BOOST_FUSION_ADAPT_STRUCT(dlplan::core::parsers::elements::stage_1::ast::Role, role)
BOOST_FUSION_ADAPT_STRUCT(dlplan::core::parsers::elements::stage_1::ast::Element, element)
BOOST_FUSION_ADAPT_STRUCT(dlplan::core::parsers::elements::stage_1::ast::ConceptOrRole, inner)
BOOST_FUSION_ADAPT_STRUCT(dlplan::core::parsers::elements::stage_1::ast::EmptyBoolean, element)
BOOST_FUSION_ADAPT_STRUCT(dlplan::core::parsers::elements::stage_1::ast::InclusionBoolean, element)
BOOST_FUSION_ADAPT_STRUCT(dlplan::core::parsers::elements::stage_1::ast::NullaryBoolean, predicate)
Expand Down
4 changes: 2 additions & 2 deletions src/core/parsers/elements/stage_1_ast/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

namespace dlplan::core::parsers::elements::stage_1::parser {

ast::ElementWrapper parse_ast(
ast::Element parse_ast(
iterator_type& iter,
iterator_type end,
error_handler_type& error_handler) {
assert(in_bounds(error_handler, iter, end));

// Our AST
dlplan::core::parsers::elements::stage_1::ast::ElementWrapper ast;
dlplan::core::parsers::elements::stage_1::ast::Element ast;

// Our parser
using boost::spirit::x3::with;
Expand Down
2 changes: 1 addition & 1 deletion src/core/parsers/elements/stage_1_ast/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace dlplan::core::parsers::elements::stage_1::parser {


/// @brief Parses the content from iter to end
extern ast::ElementWrapper parse_ast(
extern ast::Element parse_ast(
iterator_type& iter,
iterator_type end,
error_handler_type& error_handler);
Expand Down
4 changes: 2 additions & 2 deletions src/core/parsers/elements/stage_1_ast/parser_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace dlplan::core::parsers::elements::stage_1
// rexpr public interface
///////////////////////////////////////////////////////////////////////////
namespace parser {
struct ElementWrapperClass;
typedef x3::rule<ElementWrapperClass, ast::ElementWrapper> element_type;
struct ElementClass;
typedef x3::rule<ElementClass, ast::Element> element_type;
BOOST_SPIRIT_DECLARE(element_type)
}
parser::element_type const& element();
Expand Down
76 changes: 59 additions & 17 deletions src/core/parsers/elements/stage_1_ast/parser_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,17 @@ namespace dlplan::core::parsers::elements::stage_1::parser
struct ConstantClass;
struct PredicateClass;
struct PositionClass;
struct BooleanInnerClass;
struct BooleanClass;
struct ConceptInnerClass;
struct ConceptClass;
struct NumericalInnerClass;
struct NumericalClass;
struct RoleInnerClass;
struct RoleClass;
struct ElementClass;
struct ElementInnerClass;
struct ConceptOrRoleInnerClass;
struct ConceptOrRoleClass;
struct EmptyBooleanClass;
struct InclusionBooleanClass;
struct NullaryBooleanClass;
Expand Down Expand Up @@ -89,20 +95,38 @@ namespace dlplan::core::parsers::elements::stage_1::parser
x3::rule<PositionClass, ast::Position> const
position = "position";

x3::rule<BooleanInnerClass, ast::BooleanInner> const
boolean_inner = "boolean_inner";

x3::rule<BooleanClass, ast::Boolean> const
boolean = "boolean";

x3::rule<ConceptInnerClass, ast::ConceptInner> const
concept_inner = "concept_inner";

x3::rule<ConceptClass, ast::Concept> const
concept = "concept";

x3::rule<NumericalInnerClass, ast::NumericalInner> const
numerical_inner = "numerical_inner";

x3::rule<NumericalClass, ast::Numerical> const
numerical = "numerical";

x3::rule<RoleInnerClass, ast::RoleInner> const
role_inner = "role_inner";

x3::rule<RoleClass, ast::Role> const
role = "role";

x3::rule<ElementClass, ast::Element> const
element = "element";
x3::rule<ElementInnerClass, ast::ElementInner> const
element_inner = "element_inner";

x3::rule<ConceptOrRoleInnerClass, ast::ConceptOrRoleInner> const
concept_or_role_inner = "concept_or_role_inner";

x3::rule<ConceptOrRoleClass, ast::ConceptOrRole> const
concept_or_role = "concept_or_role";

x3::rule<EmptyBooleanClass, ast::EmptyBoolean> const
empty_boolean = "empty_boolean";
Expand Down Expand Up @@ -203,7 +227,7 @@ namespace dlplan::core::parsers::elements::stage_1::parser
x3::rule<TransitiveReflexiveClosureRoleClass, ast::TransitiveReflexiveClosureRole> const
transitive_reflexive_closure_role = "transitive_reflexive_closure_role";

element_type const element_wrapper = "element_wrapper";
element_type const element = "element";


///////////////////////////////////////////////////////////////////////////
Expand All @@ -218,23 +242,35 @@ namespace dlplan::core::parsers::elements::stage_1::parser

const auto position_def = int_;

const auto boolean_def = empty_boolean | inclusion_boolean | nullary_boolean;
const auto boolean_inner_def = empty_boolean | inclusion_boolean | nullary_boolean;

const auto boolean_def = boolean_inner_def;

// Note: non recursive comes first, i.e., primitive_concept
const auto concept_def = primitive_concept | all_concept | and_concept | bot_concept | diff_concept | equal_concept | not_concept | one_of_concept | or_concept | projection_concept | some_concept | subset_concept | top_concept;
const auto concept_inner_def = primitive_concept | all_concept | and_concept | bot_concept | diff_concept | equal_concept | not_concept | one_of_concept | or_concept | projection_concept | some_concept | subset_concept | top_concept;

const auto concept_def = concept_inner_def;

const auto numerical_inner_def = concept_distance_numerical | count_numerical | role_distance_numerical | sum_concept_distance_numerical | sum_role_distance_numerical;

const auto numerical_def = concept_distance_numerical | count_numerical | role_distance_numerical | sum_concept_distance_numerical | sum_role_distance_numerical;
const auto numerical_def = numerical_inner;

// Note: non recursive comes first, i.e., primitive_role
const auto role_def = primitive_role | and_role | compose_role | diff_role | identity_role | inverse_role | not_role | or_role | restrict_role | top_role | transitive_closure_role | transitive_reflexive_closure_role;
const auto role_inner_def = primitive_role | and_role | compose_role | diff_role | identity_role | inverse_role | not_role | or_role | restrict_role | top_role | transitive_closure_role | transitive_reflexive_closure_role;

const auto role_def = role_inner;

const auto element_inner_def = boolean | concept | numerical | role;

const auto element_def = eps > element_inner;

const auto element_def = boolean | concept | numerical | role;
const auto concept_or_role_inner_def = concept | role;

const auto element_wrapper_def = eps > element;
const auto concept_or_role_def = concept_or_role_inner;

const auto empty_boolean_def = lit("b_empty") > lit('(') > (concept | role) > lit(')');
const auto empty_boolean_def = lit("b_empty") > lit('(') > concept_or_role > lit(')');

const auto inclusion_boolean_def = lit("b_inclusion") > lit('(') > (concept | role) > lit(')');
const auto inclusion_boolean_def = lit("b_inclusion") > lit('(') > concept_or_role > lit(')');

const auto nullary_boolean_def = lit("b_nullary") > lit('(') > predicate > lit(')');

Expand Down Expand Up @@ -268,7 +304,7 @@ namespace dlplan::core::parsers::elements::stage_1::parser

const auto concept_distance_numerical_def = lit("n_concept_distance") > lit('(') > concept > lit(',') > role > lit(',') > concept > lit(')');

const auto count_numerical_def = lit("n_count") > lit('(') > (concept | role) > lit(')');
const auto count_numerical_def = lit("n_count") > lit('(') > concept_or_role > lit(')');

const auto role_distance_numerical_def = lit("n_role_distance") > lit('(') > role > lit(',') > role > lit(',') > role > lit(')');

Expand Down Expand Up @@ -303,7 +339,7 @@ namespace dlplan::core::parsers::elements::stage_1::parser

BOOST_SPIRIT_DEFINE(
name, constant, predicate, position,
boolean, concept, numerical, role, element, element_wrapper,
boolean_inner, boolean, concept_inner, concept, numerical_inner, numerical, role_inner, role, element_inner, element, concept_or_role_inner, concept_or_role,
empty_boolean, inclusion_boolean, nullary_boolean,
all_concept, and_concept, bot_concept, diff_concept, equal_concept, not_concept, one_of_concept, or_concept, primitive_concept, projection_concept, some_concept, subset_concept, top_concept,
concept_distance_numerical, count_numerical, role_distance_numerical, sum_concept_distance_numerical, sum_role_distance_numerical,
Expand All @@ -317,10 +353,16 @@ namespace dlplan::core::parsers::elements::stage_1::parser
struct ConstantClass : x3::annotate_on_success {};
struct PredicateClass : x3::annotate_on_success {};
struct PositionClass : x3::annotate_on_success {};
struct BooleanInnerClass : x3::annotate_on_success {};
struct BooleanClass : x3::annotate_on_success {};
struct ConceptInnerClass : x3::annotate_on_success {};
struct ConceptClass : x3::annotate_on_success {};
struct NumericalInnerClass : x3::annotate_on_success {};
struct NumericalClass : x3::annotate_on_success {};
struct RoleInnerClass : x3::annotate_on_success {};
struct RoleClass : x3::annotate_on_success {};
struct ConceptOrRoleInnerClass : x3::annotate_on_success {};
struct ConceptOrRoleClass : x3::annotate_on_success {};
struct EmptyBooleanClass : x3::annotate_on_success {};
struct InclusionBooleanClass : x3::annotate_on_success {};
struct NullaryBooleanClass : x3::annotate_on_success {};
Expand Down Expand Up @@ -354,15 +396,15 @@ namespace dlplan::core::parsers::elements::stage_1::parser
struct TopRoleClass : x3::annotate_on_success {};
struct TransitiveClosureRoleClass : x3::annotate_on_success {};
struct TransitiveReflexiveClosureRoleClass : x3::annotate_on_success {};
struct ElementClass : x3::annotate_on_success {};
struct ElementWrapperClass : x3::annotate_on_success, error_handler_base {};
struct ElementInnerClass : x3::annotate_on_success {};
struct ElementClass : x3::annotate_on_success, error_handler_base {};
}

namespace dlplan::core::parsers::elements::stage_1
{
parser::element_type const& element()
{
return parser::element_wrapper;
return parser::element;
}
}

Expand Down

0 comments on commit 5b8e809

Please sign in to comment.