Skip to content

Commit

Permalink
work on better error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed Oct 15, 2023
1 parent c29cdb6 commit 6f58bf9
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 14 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_count(c_and(c_primitive(on_g,0),c_pimitive(on,0)))");
auto numerical = factory.parse_numerical("n_cunt(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
2 changes: 0 additions & 2 deletions src/core/parsers/elements/common/error_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ namespace dlplan::core::parsers::elements
if (iter != id_map.end())
which = iter->second;

std::cout << "asd" << std::endl;

std::string message = "Error! Expecting: " + which + " here:";
auto& error_handler = x3::get<error_handler_tag>(context).get();
error_handler(x.where(), message);
Expand Down
4 changes: 4 additions & 0 deletions src/core/parsers/elements/stage_1_ast/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ namespace dlplan::core::parsers::elements::stage_1::ast
using base_type::operator=;
};

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

struct EmptyBoolean : x3::position_tagged {
x3::variant<Concept, Role> element;
};
Expand Down
1 change: 1 addition & 0 deletions src/core/parsers/elements/stage_1_ast/ast_adapted.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ 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::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::Element parse_ast(
ast::ElementWrapper 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::Element ast;
dlplan::core::parsers::elements::stage_1::ast::ElementWrapper 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::Element parse_ast(
extern ast::ElementWrapper parse_ast(
iterator_type& iter,
iterator_type end,
error_handler_type& error_handler);
Expand Down
6 changes: 2 additions & 4 deletions src/core/parsers/elements/stage_1_ast/parser_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ namespace dlplan::core::parsers::elements::stage_1
// rexpr public interface
///////////////////////////////////////////////////////////////////////////
namespace parser {
struct ElementClass;
typedef
x3::rule<ElementClass, ast::Element>
element_type;
struct ElementWrapperClass;
typedef x3::rule<ElementWrapperClass, ast::ElementWrapper> element_type;
BOOST_SPIRIT_DECLARE(element_type)
}
parser::element_type const& element();
Expand Down
16 changes: 12 additions & 4 deletions src/core/parsers/elements/stage_1_ast/parser_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace dlplan::core::parsers::elements::stage_1::parser
using x3::lit;
using x3::lexeme;
using x3::int_;
using x3::eps;

using ascii::alpha;
using ascii::alnum;
Expand All @@ -37,6 +38,7 @@ namespace dlplan::core::parsers::elements::stage_1::parser
struct ConceptClass;
struct NumericalClass;
struct RoleClass;
struct ElementClass;
struct EmptyBooleanClass;
struct InclusionBooleanClass;
struct NullaryBooleanClass;
Expand Down Expand Up @@ -99,6 +101,9 @@ namespace dlplan::core::parsers::elements::stage_1::parser
x3::rule<RoleClass, ast::Role> const
role = "role";

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

x3::rule<EmptyBooleanClass, ast::EmptyBoolean> const
empty_boolean = "empty_boolean";

Expand Down Expand Up @@ -198,7 +203,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 = "element";
element_type const element_wrapper = "element_wrapper";


///////////////////////////////////////////////////////////////////////////
Expand All @@ -225,6 +230,8 @@ namespace dlplan::core::parsers::elements::stage_1::parser

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

const auto element_wrapper_def = eps > element;

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

const auto inclusion_boolean_def = lit("b_inclusion") > lit('(') > (concept | role) > lit(')');
Expand Down Expand Up @@ -296,7 +303,7 @@ namespace dlplan::core::parsers::elements::stage_1::parser

BOOST_SPIRIT_DEFINE(
name, constant, predicate, position,
boolean, concept, numerical, role, element,
boolean, concept, numerical, role, element, element_wrapper,
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 Down Expand Up @@ -347,14 +354,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, error_handler_base {};
struct ElementClass : x3::annotate_on_success {};
struct ElementWrapperClass : x3::annotate_on_success, error_handler_base {};
}

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

Expand Down

0 comments on commit 6f58bf9

Please sign in to comment.