diff options
author | chriseth <chris@ethereum.org> | 2016-11-01 18:59:05 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-01 18:59:05 +0800 |
commit | 1a2c150e3b2f98ef44834aca281692734b74c0db (patch) | |
tree | 4cfc7d03d285133fe373b6f9df0b68a7412a9260 /liblll/Parser.cpp | |
parent | 9cb1d30eab34e530f3c8bf67367c04787048bace (diff) | |
parent | ac3c8a553a0b943984742f6b12d9d0a3cabcb877 (diff) | |
download | dexon-solidity-1a2c150e3b2f98ef44834aca281692734b74c0db.tar dexon-solidity-1a2c150e3b2f98ef44834aca281692734b74c0db.tar.gz dexon-solidity-1a2c150e3b2f98ef44834aca281692734b74c0db.tar.bz2 dexon-solidity-1a2c150e3b2f98ef44834aca281692734b74c0db.tar.lz dexon-solidity-1a2c150e3b2f98ef44834aca281692734b74c0db.tar.xz dexon-solidity-1a2c150e3b2f98ef44834aca281692734b74c0db.tar.zst dexon-solidity-1a2c150e3b2f98ef44834aca281692734b74c0db.zip |
Merge pull request #1298 from ethereum/lll-error-reporting
LLL: further improve error reporting
Diffstat (limited to 'liblll/Parser.cpp')
-rw-r--r-- | liblll/Parser.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/liblll/Parser.cpp b/liblll/Parser.cpp index 2754e9f5..219d4f54 100644 --- a/liblll/Parser.cpp +++ b/liblll/Parser.cpp @@ -101,8 +101,8 @@ void dev::eth::parseTreeLLL(string const& _s, sp::utree& o_out) qi::rule<it, string()> strsh = '\'' > qi::lexeme[+(~qi::char_(std::string(" ;$@()[]{}:\n\t") + '\0'))]; qi::rule<it, symbol_type()> symbol = qi::lexeme[+(~qi::char_(std::string(" $@[]{}:();\"\x01-\x1f\x7f") + '\0'))]; qi::rule<it, string()> intstr = qi::lexeme[ qi::no_case["0x"][qi::_val = "0x"] >> *qi::char_("0-9a-fA-F")[qi::_val += qi::_1]] | qi::lexeme[+qi::char_("0-9")[qi::_val += qi::_1]]; - qi::rule<it, bigint()> integer = intstr; - qi::rule<it, space_type, sp::utree()> atom = integer[qi::_val = px::construct<sp::any_ptr>(px::new_<bigint>(qi::_1))] | (str | strsh)[qi::_val = qi::_1] | symbol[qi::_val = qi::_1]; + qi::rule<it, sp::utree()> integer = intstr[qi::_val = px::construct<sp::any_ptr>(px::new_<bigint>(qi::_1))]; + qi::rule<it, space_type, sp::utree()> atom = integer[qi::_val = qi::_1] | (str | strsh)[qi::_val = qi::_1] | symbol[qi::_val = qi::_1]; qi::rule<it, space_type, sp::utree::list_type()> seq = '{' > *element > '}'; qi::rule<it, space_type, sp::utree::list_type()> mload = '@' > element; qi::rule<it, space_type, sp::utree::list_type()> sload = qi::lit("@@") > element; @@ -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")); } } - |