From 751c97ca19ed0bb69e67222a1edd61e7d227b30f Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 26 May 2017 21:02:24 +0100 Subject: Pull out common code to a helper --- libsolidity/parsing/Parser.cpp | 38 ++++++++++++++------------------------ libsolidity/parsing/Parser.h | 1 + 2 files changed, 15 insertions(+), 24 deletions(-) (limited to 'libsolidity/parsing') 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 Parser::createEmptyParameterList() return nodeFactory.createNode(vector>()); } +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 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, SourceLocation>> const& _indices ); + std::string currentTokenName(); Token::Value expectAssignmentOperator(); ASTPointer expectIdentifierToken(); ASTPointer getLiteralAndAdvance(); -- cgit