Skip to content

Commit

Permalink
moved error_handler to common interface
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed Oct 16, 2023
1 parent 1c63f1b commit d08c0ba
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 222 deletions.
58 changes: 58 additions & 0 deletions include/dlplan/common/parsers/error_handler.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#ifndef DLPLAN_INCLUDE_DLPLAN_CORE_PARSERS_ELEMENTS_COMMON_ERROR_HANDLER_HPP_
#define DLPLAN_INCLUDE_DLPLAN_CORE_PARSERS_ELEMENTS_COMMON_ERROR_HANDLER_HPP_

#include <map>
#include <iostream>

#include "include/dlplan/common/parsers/config.hpp"


namespace dlplan::common::parsers
{
namespace x3 = boost::spirit::x3;

////////////////////////////////////////////////////////////////////////////
// Our error handler
////////////////////////////////////////////////////////////////////////////

// ErrorMessages must be default constructible
template<typename ErrorMessages>
struct error_handler_base
{
error_handler_base() { }

template <typename Iterator, typename Exception, typename Context>
x3::error_handler_result on_error(
Iterator& /*first*/, Iterator const& /*last*/
, Exception const& x, Context const& context) {
{
auto& error_counter = x3::get<dlplan::parsers::error_counter_tag>(context).get();
if (error_counter.count > 0) {
// We only print the first occurence of an error
return x3::error_handler_result::fail;
}
error_counter.increment();

// Construct a nice error message using the map.
std::string which = x.which();
const auto& id_map = error_messages.id_map;
auto iter = id_map.find(which);
if (iter != id_map.end())
which = iter->second;

std::string message = "Error! Expecting: " + which + " here:";
auto& error_handler = x3::get<dlplan::parsers::error_handler_tag>(context).get();
error_handler(x.where(), message);

return x3::error_handler_result::fail;
}
}

ErrorMessages error_messages;
};



}

#endif
117 changes: 0 additions & 117 deletions include/dlplan/core/parsers/elements/common/error_handler.hpp

This file was deleted.

1 change: 0 additions & 1 deletion src/core/element_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
#include "elements/roles/transitive_reflexive_closure.h"

#include "include/dlplan/common/parsers/config.hpp"
#include "include/dlplan/core/parsers/elements/common/error_handler.hpp"
#include "include/dlplan/core/parsers/elements/stage_1/parser.hpp"
#include "include/dlplan/core/parsers/elements/stage_2/parser.hpp"

Expand Down
99 changes: 46 additions & 53 deletions src/core/parsers/elements/stage_1/error_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,52 @@ std::map<std::string, std::string> error_messages::id_map = {
{"name", "name"},
{"constant", "constant"},
{"predicate", "predicate"},
{"position", "position"}
{"position", "position"},
{"boolean_inner", "boolean_inner"},
{"concept_inner", "concept_inner"},
{"numerical_inner","numerical_inner"},
{"role_inner","role_inner"},
{"element_inner","element_inner"},
{"concept_or_role_inner","concept_or_role_inner"},
{"concept_or_role","concept_or_role"},
{"empty_boolean","empty_boolean"},
{"inclusion_boolean","inclusion_boolean"},
{"nullary_boolean","nullary_boolean"},
{"all_concept","all_concept"},
{"and_concept","and_concept"},
{"bot_concept","bot_concept"},
{"diff_concept","diff_concept"},
{"equal_concept","equal_concept"},
{"not_concept","not_concept"},
{"one_of_concept","one_of_concept"},
{"or_concept","or_concept"},
{"primitive_concept","primitive_concept"},
{"projection_concept","projection_concept"},
{"some_concept","some_concept"},
{"subset_concept","subset_concept"},
{"top_concept","top_concept"},
{"concept_distance_numerical","concept_distance_numerical"},
{"count_numerical","count_numerical"},
{"role_distance_numerical","role_distance_numerical"},
{"sum_concept_distance_numerical","sum_concept_distance_numerical"},
{"sum_role_distance_numerical","sum_role_distance_numerical"},
{"and_role","and_role"},
{"compose_role","compose_role"},
{"diff_role","diff_role"},
{"identity_role","identity_role"},
{"inverse_role","inverse_role"},
{"not_role","not_role"},
{"or_role","or_role"},
{"primitive_role","primitive_role"},
{"restrict_role","restrict_role"},
{"top_role","top_role"},
{"transitive_closure_role","transitive_closure_role"},
{"transitive_reflexive_closure_role","transitive_reflexive_closure_role"},
{"boolean","boolean"},
{"numerical","numerical"},
{"concept","concept"},
{"role","role"},
{"element","element"}
};


// TODO: add more precise error messages.
/* id_map["name"] = "name";
id_map["constant"] = "constant";
id_map["predicate"] = "predicate";
id_map["position"] = "position";
id_map["boolean_inner"] = "boolean_inner";
id_map["concept_inner"] = "concept_inner";
id_map["numerical_inner"] = "numerical_inner";
id_map["role_inner"] = "role_inner";
id_map["element_inner"] = "element_inner";
id_map["concept_or_role_inner"] = "concept_or_role_inner";
id_map["concept_or_role"] = "concept_or_role";
id_map["empty_boolean"] = "empty_boolean";
id_map["inclusion_boolean"] = "inclusion_boolean";
id_map["nullary_boolean"] = "nullary_boolean";
id_map["all_concept"] = "all_concept";
id_map["and_concept"] = "and_concept";
id_map["bot_concept"] = "bot_concept";
id_map["diff_concept"] = "diff_concept";
id_map["equal_concept"] = "equal_concept";
id_map["not_concept"] = "not_concept";
id_map["one_of_concept"] = "one_of_concept";
id_map["or_concept"] = "or_concept";
id_map["primitive_concept"] = "primitive_concept";
id_map["projection_concept"] = "projection_concept";
id_map["some_concept"] = "some_concept";
id_map["subset_concept"] = "subset_concept";
id_map["top_concept"] = "top_concept";
id_map["concept_distance_numerical"] = "concept_distance_numerical";
id_map["count_numerical"] = "count_numerical";
id_map["role_distance_numerical"] = "role_distance_numerical";
id_map["sum_concept_distance_numerical"] = "sum_concept_distance_numerical";
id_map["sum_role_distance_numerical"] = "sum_role_distance_numerical";
id_map["and_role"] = "and_role";
id_map["compose_role"] = "compose_role";
id_map["diff_role"] = "diff_role";
id_map["identity_role"] = "identity_role";
id_map["inverse_role"] = "inverse_role";
id_map["not_role"] = "not_role";
id_map["or_role"] = "or_role";
id_map["primitive_role"] = "primitive_role";
id_map["restrict_role"] = "restrict_role";
id_map["top_role"] = "top_role";
id_map["transitive_closure_role"] = "transitive_closure_role";
id_map["transitive_reflexive_closure_role"] = "transitive_reflexive_closure_role";
id_map["boolean"] = "boolean";
id_map["numerical"] = "numerical";
id_map["concept"] = "concept";
id_map["role"] = "role";
id_map["element"] = "element";
*/
}
2 changes: 1 addition & 1 deletion src/core/parsers/elements/stage_1/error_messages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace dlplan::core::parsers::elements
{
struct error_messages
{
error_messages();
error_messages() = default;

static std::map<std::string, std::string> id_map;
};
Expand Down
Loading

0 comments on commit d08c0ba

Please sign in to comment.