diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2018-05-04 20:26:23 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2018-05-04 20:27:05 +0800 |
commit | c7ee649d8033aedf49f83342c76984fe53449679 (patch) | |
tree | f8343cd0f98d7d8d11b3513c21de84ca83b5a2ca | |
parent | 882248ce755d8c905b69bc25964b343906bb94ae (diff) | |
download | dexon-solidity-c7ee649d8033aedf49f83342c76984fe53449679.tar.gz dexon-solidity-c7ee649d8033aedf49f83342c76984fe53449679.tar.zst dexon-solidity-c7ee649d8033aedf49f83342c76984fe53449679.zip |
More user friendly output in case of Identifier and Token keywords
-rw-r--r-- | libsolidity/parsing/ParserBase.cpp | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/libsolidity/parsing/ParserBase.cpp b/libsolidity/parsing/ParserBase.cpp index 8277ff46..d0c7a551 100644 --- a/libsolidity/parsing/ParserBase.cpp +++ b/libsolidity/parsing/ParserBase.cpp @@ -68,23 +68,24 @@ void ParserBase::expectToken(Token::Value _value, bool _advance) Token::Value tok = m_scanner->currentToken(); if (tok != _value) { - string got; - if (Token::isReservedKeyword(tok)) - got = "reserved keyword '" + Token::friendlyName(tok) + "'"; - else if (Token::isElementaryTypeName(tok)) //for the sake of accuracy in reporting + auto tokenName = [this](Token::Value _token) { - ElementaryTypeNameToken elemTypeName = m_scanner->currentElementaryTypeNameToken(); - got = "'" + elemTypeName.toString() + "'"; - } - else - got = "'" + Token::friendlyName(tok) + "'"; - - fatalParserError( - string("Expected '") + - Token::friendlyName(_value) + - string("' but got ") + - got - ); + if (_token == Token::Identifier) + return string("identifier"); + else if (_token == Token::EOS) + return string("end of source"); + else if (Token::isReservedKeyword(_token)) + return string("reserved keyword '") + Token::friendlyName(_token) + "'"; + else if (Token::isElementaryTypeName(_token)) //for the sake of accuracy in reporting + { + ElementaryTypeNameToken elemTypeName = m_scanner->currentElementaryTypeNameToken(); + return string("'") + elemTypeName.toString() + "'"; + } + else + return string("'") + Token::friendlyName(_token) + "'"; + }; + + fatalParserError(string("Expected ") + tokenName(_value) + string(" but got ") + tokenName(tok)); } if (_advance) m_scanner->next(); |