diff --git a/include/ircd/spirit.h b/include/ircd/spirit.h index c8077ed74..34f4dfb52 100644 --- a/include/ircd/spirit.h +++ b/include/ircd/spirit.h @@ -81,6 +81,10 @@ namespace ircd::spirit using karma::attr_cast; using karma::maxwidth; using karma::buffer; + + template struct expectation_failure; + + extern thread_local char rulebuf[64]; // parse.cc } namespace ircd::spirit::local @@ -89,3 +93,46 @@ namespace ircd::spirit::local using qi::_2; using qi::_3; } + +template +struct ircd::spirit::expectation_failure +:parent_error +{ + template + expectation_failure(const qi::expectation_failure &e, + const ssize_t &show_max = 64); + + template + expectation_failure(const qi::expectation_failure &e, + const it &start, + const ssize_t &show_max = 64); +}; + +template +template +ircd::spirit::expectation_failure::expectation_failure(const qi::expectation_failure &e, + const ssize_t &show_max) +:parent +{ + "Expected %s. You input %zd invalid characters :%s", + ircd::string(rulebuf, e.what_), + std::distance(e.first, e.last), + string_view{e.first, e.first + std::min(std::distance(e.first, e.last), show_max)} +} +{} + +template +template +ircd::spirit::expectation_failure::expectation_failure(const qi::expectation_failure &e, + const it &start, + const ssize_t &show_max) +:parent +{ + "Expected %s. You input %zd invalid characters somewhere between position %zd and %zd: %s", + ircd::string(rulebuf, e.what_), + std::distance(e.first, e.last), + std::distance(start, e.first), + std::distance(start, e.last), + string_view{e.first, e.first + std::min(std::distance(e.first, e.last), show_max)} +} +{} diff --git a/ircd/parse.cc b/ircd/parse.cc index f424c0094..815e40b28 100644 --- a/ircd/parse.cc +++ b/ircd/parse.cc @@ -23,11 +23,10 @@ * USA */ -namespace ircd -{ - -} +#include +decltype(ircd::spirit::rulebuf) thread_local +ircd::spirit::rulebuf; // // Museum of historical comments