foonathan / lexy

C++ parsing DSL
https://lexy.foonathan.net
Boost Software License 1.0
1.01k stars 67 forks source link

Is there an easy way to get an error-string from a lexy::parse call? #145

Closed Cthaeeh closed 1 year ago

Cthaeeh commented 1 year ago

E.g.

std::expected<X, std::string> parseX(
      const std::string &str)
{
    auto result = lexy::parse<grammar::Table>(lexy::string_input(str),
                                              lexy_ext::report_error);

    if (result.is_success()) {
        return result.value();
    } else {
        return std::unexpected( ? ); //<-
    }
}

Or do I have to implement my own lexy_ext::report_error in some form?