Skip to content

Commit

Permalink
Pull out common code to a helper
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed May 26, 2017
1 parent 48f58aa commit 751c97c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
38 changes: 14 additions & 24 deletions libsolidity/parsing/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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();
}

Expand Down
1 change: 1 addition & 0 deletions libsolidity/parsing/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class Parser: public ParserBase
std::vector<std::pair<ASTPointer<Expression>, SourceLocation>> const& _indices
);

std::string currentTokenName();
Token::Value expectAssignmentOperator();
ASTPointer<ASTString> expectIdentifierToken();
ASTPointer<ASTString> getLiteralAndAdvance();
Expand Down

0 comments on commit 751c97c

Please sign in to comment.