diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-05-27 04:02:24 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2017-05-27 04:40:14 +0800 |
commit | 751c97ca19ed0bb69e67222a1edd61e7d227b30f (patch) | |
tree | f3251f62b6baddea299432becef1a6660f3eb2df /libsolidity | |
parent | 48f58aa3f9b4d8962b2c6f1bd7967b119893a889 (diff) | |
download | dexon-solidity-751c97ca19ed0bb69e67222a1edd61e7d227b30f.tar.gz dexon-solidity-751c97ca19ed0bb69e67222a1edd61e7d227b30f.tar.zst dexon-solidity-751c97ca19ed0bb69e67222a1edd61e7d227b30f.zip |
Pull out common code to a helper
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/parsing/Parser.cpp | 38 | ||||
-rw-r--r-- | libsolidity/parsing/Parser.h | 1 |
2 files changed, 15 insertions, 24 deletions
diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index dca49360..5b318b2b 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -1437,26 +1437,27 @@ ASTPointer<ParameterList> Parser::createEmptyParameterList() return nodeFactory.createNode<ParameterList>(vector<ASTPointer<VariableDeclaration>>()); } +string Parser::currentTokenName() +{ + Token::Value token = m_scanner->currentToken(); + if (Token::isElementaryTypeName(token)) //for the sake of accuracy in reporting + { + ElementaryTypeNameToken elemTypeName = m_scanner->currentElementaryTypeNameToken(); + return elemTypeName.toString(); + } + else + return Token::name(token); +} + Token::Value Parser::expectAssignmentOperator() { Token::Value op = m_scanner->currentToken(); if (!Token::isAssignmentOp(op)) - { - string tokenName; - if (Token::isElementaryTypeName(op)) //for the sake of accuracy in reporting - { - ElementaryTypeNameToken elemTypeName = m_scanner->currentElementaryTypeNameToken(); - tokenName = elemTypeName.toString(); - } - else - tokenName = Token::name(m_scanner->currentToken()); - fatalParserError( string("Expected assignment operator, got '") + - tokenName + + currentTokenName() + string("'") ); - } m_scanner->next(); return op; } @@ -1465,22 +1466,11 @@ ASTPointer<ASTString> Parser::expectIdentifierToken() { Token::Value id = m_scanner->currentToken(); if (id != Token::Identifier) - { - string tokenName; - if (Token::isElementaryTypeName(id)) //for the sake of accuracy in reporting - { - ElementaryTypeNameToken elemTypeName = m_scanner->currentElementaryTypeNameToken(); - tokenName = elemTypeName.toString(); - } - else - tokenName = Token::name(id); - fatalParserError( string("Expected identifier, got '") + - tokenName + + currentTokenName() + string("'") ); - } return getLiteralAndAdvance(); } diff --git a/libsolidity/parsing/Parser.h b/libsolidity/parsing/Parser.h index 05e99566..5ec3dbed 100644 --- a/libsolidity/parsing/Parser.h +++ b/libsolidity/parsing/Parser.h @@ -155,6 +155,7 @@ private: std::vector<std::pair<ASTPointer<Expression>, SourceLocation>> const& _indices ); + std::string currentTokenName(); Token::Value expectAssignmentOperator(); ASTPointer<ASTString> expectIdentifierToken(); ASTPointer<ASTString> getLiteralAndAdvance(); |