LLL: catch and display spirit::qi errors

This commit is contained in:
Alex Beregszaszi 2016-10-26 14:29:08 +01:00
parent 5be1996ea5
commit b92bb41be7

View File

@ -135,10 +135,19 @@ void dev::eth::parseTreeLLL(string const& _s, sp::utree& o_out)
s.push_back(i);
}
auto ret = s.cbegin();
qi::phrase_parse(ret, s.cend(), element, space, qi::skip_flag::dont_postskip, o_out);
try
{
qi::phrase_parse(ret, s.cend(), element, space, qi::skip_flag::dont_postskip, o_out);
}
catch (qi::expectation_failure<it> const& e)
{
std::string fragment(e.first, e.last);
std::string loc = std::to_string(std::distance(s.cbegin(), e.first) - 1);
std::string reason("Lexer failure at " + loc + ": '" + fragment + "'");
BOOST_THROW_EXCEPTION(ParserException() << errinfo_comment(reason));
}
for (auto i = ret; i != s.cend(); ++i)
if (!isspace(*i)) {
BOOST_THROW_EXCEPTION(ParserException() << errinfo_comment("Non-whitespace left in parser"));
}
}