From b92bb41be78c4277a16974353ec2e21ea8cd5f7b Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 26 Oct 2016 14:29:08 +0100 Subject: LLL: catch and display spirit::qi errors --- liblll/Parser.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'liblll') diff --git a/liblll/Parser.cpp b/liblll/Parser.cpp index 2754e9f5..7d594e31 100644 --- a/liblll/Parser.cpp +++ b/liblll/Parser.cpp @@ -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 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")); } } - -- cgit