aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/parsing/ParserBase.cpp
diff options
context:
space:
mode:
authorVoR0220 <catalanor0220@gmail.com>2016-03-30 11:32:40 +0800
committerVoR0220 <catalanor0220@gmail.com>2016-03-31 00:54:00 +0800
commit6c61e28dc22894a8b035ba25ed727db664a4b163 (patch)
treea4dea06ac33b8eae2e6c8a6fc9ffdc7be6aec3b8 /libsolidity/parsing/ParserBase.cpp
parent63951683717004449eb85dd41157ee586953b55d (diff)
downloaddexon-solidity-6c61e28dc22894a8b035ba25ed727db664a4b163.tar.gz
dexon-solidity-6c61e28dc22894a8b035ba25ed727db664a4b163.tar.zst
dexon-solidity-6c61e28dc22894a8b035ba25ed727db664a4b163.zip
Got it working exactly like you wanted ;)
Diffstat (limited to 'libsolidity/parsing/ParserBase.cpp')
-rw-r--r--libsolidity/parsing/ParserBase.cpp87
1 files changed, 68 insertions, 19 deletions
diff --git a/libsolidity/parsing/ParserBase.cpp b/libsolidity/parsing/ParserBase.cpp
index 64e42841..9148946c 100644
--- a/libsolidity/parsing/ParserBase.cpp
+++ b/libsolidity/parsing/ParserBase.cpp
@@ -44,14 +44,32 @@ int ParserBase::endPosition() const
void ParserBase::expectToken(Token::Value _value)
{
- if (m_scanner->currentToken() != _value)
- fatalParserError(
- string("Expected token ") +
- string(Token::name(_value)) +
- string(" got '") +
- string(Token::name(m_scanner->currentToken())) +
- string("'")
- );
+ Token::Value tok = m_scanner->currentToken();
+ if (tok != _value)
+ {
+ if (Token::isElementaryTypeName(tok)) //for the sake of accuracy in reporting
+ {
+ unsigned firstSize;
+ unsigned secondSize;
+ tie(firstSize, secondSize) = m_scanner->currentTokenInfo();
+ ElementaryTypeNameToken elemTypeName(tok, firstSize, secondSize);
+ fatalParserError(
+ string("Expected token ") +
+ string(Token::name(_value)) +
+ string(" got '") +
+ elemTypeName.toString() +
+ string("'")
+ );
+ }
+ else
+ fatalParserError(
+ string("Expected token ") +
+ string(Token::name(_value)) +
+ string(" got '") +
+ string(Token::name(m_scanner->currentToken())) +
+ string("'")
+ );
+ }
m_scanner->next();
}
@@ -59,23 +77,54 @@ Token::Value ParserBase::expectAssignmentOperator()
{
Token::Value op = m_scanner->currentToken();
if (!Token::isAssignmentOp(op))
- fatalParserError(
- string("Expected assignment operator, got '") +
- string(Token::name(m_scanner->currentToken())) +
- string("'")
- );
+ {
+ if (Token::isElementaryTypeName(op)) //for the sake of accuracy in reporting
+ {
+ unsigned firstSize;
+ unsigned secondSize;
+ tie(firstSize, secondSize) = m_scanner->currentTokenInfo();
+ ElementaryTypeNameToken elemTypeName(op, firstSize, secondSize);
+ fatalParserError(
+ string("Expected assignment operator, got '") +
+ elemTypeName.toString() +
+ string("'")
+ );
+ }
+ else
+ fatalParserError(
+ string("Expected assignment operator, got '") +
+ string(Token::name(m_scanner->currentToken())) +
+ string("'")
+ );
+ }
m_scanner->next();
return op;
}
ASTPointer<ASTString> ParserBase::expectIdentifierToken()
{
- if (m_scanner->currentToken() != Token::Identifier)
- fatalParserError(
- string("Expected identifier, got '") +
- string(Token::name(m_scanner->currentToken())) +
- string("'")
- );
+ Token::Value id = m_scanner->currentToken();
+ if (id != Token::Identifier)
+ {
+ if (Token::isElementaryTypeName(id)) //for the sake of accuracy in reporting
+ {
+ unsigned firstSize;
+ unsigned secondSize;
+ tie(firstSize, secondSize) = m_scanner->currentTokenInfo();
+ ElementaryTypeNameToken elemTypeName(id, firstSize, secondSize);
+ fatalParserError(
+ string("Expected identifier, got '") +
+ elemTypeName.toString() +
+ string("'")
+ );
+ }
+ else
+ fatalParserError(
+ string("Expected identifier, got '") +
+ string(Token::name(id)) +
+ string("'")
+ );
+ }
return getLiteralAndAdvance();
}