-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved error_handler to common interface
- Loading branch information
Showing
6 changed files
with
158 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
117
include/dlplan/core/parsers/elements/common/error_handler.hpp
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.