Skip to content

Commit

Permalink
Add a std::string data member, and an override of what() to parser_er…
Browse files Browse the repository at this point in the history
…ror, to

ensure that the messge is preserved exactly when translating exceptions in
failed lexer parsing.

See #202.
  • Loading branch information
tzlaine committed Nov 29, 2024
1 parent 092a761 commit 1421592
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions include/boost/parser/error_handling_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ namespace boost { namespace parser {
template<typename Iter>
struct parse_error : std::runtime_error
{
parse_error(Iter it, std::string const & msg) :
runtime_error(msg), iter(it)
parse_error(Iter it, std::string msg) :
runtime_error(""), message(msg), iter(it)
{}

char const * what() const noexcept override { return message.c_str(); }

std::string message;
Iter iter;
};

Expand Down
2 changes: 1 addition & 1 deletion include/boost/parser/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2329,7 +2329,7 @@ namespace boost { namespace parser {
auto const underlying_first = e.iter.range_begin();
auto const underlying_curr = e.iter->underlying_position();
auto const underlying_last = e.iter.range_end();
parse_error underlying_error{underlying_curr, e.what()};
parse_error underlying_error{underlying_curr, e.message()};
return error_handler(
underlying_first,
underlying_last,
Expand Down

0 comments on commit 1421592

Please sign in to comment.