mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Simplify expectIdentifierToken by using expectToken
This commit is contained in:
@@ -1602,27 +1602,10 @@ 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);
|
||||
}
|
||||
|
||||
ASTPointer<ASTString> Parser::expectIdentifierToken()
|
||||
{
|
||||
Token::Value id = m_scanner->currentToken();
|
||||
if (id != Token::Identifier)
|
||||
fatalParserError(
|
||||
string("Expected identifier, got '") +
|
||||
currentTokenName() +
|
||||
string("'")
|
||||
);
|
||||
// do not advance on success
|
||||
expectToken(Token::Identifier, false);
|
||||
return getLiteralAndAdvance();
|
||||
}
|
||||
|
||||
|
||||
@@ -165,7 +165,6 @@ private:
|
||||
/// @returns an expression parsed in look-ahead fashion from something like "a.b[8][2**70]".
|
||||
ASTPointer<Expression> expressionFromIndexAccessStructure(IndexAccessedPath const& _pathAndIndices);
|
||||
|
||||
std::string currentTokenName();
|
||||
ASTPointer<ASTString> expectIdentifierToken();
|
||||
ASTPointer<ASTString> getLiteralAndAdvance();
|
||||
///@}
|
||||
|
||||
@@ -63,7 +63,7 @@ Token::Value ParserBase::advance()
|
||||
return m_scanner->next();
|
||||
}
|
||||
|
||||
void ParserBase::expectToken(Token::Value _value)
|
||||
void ParserBase::expectToken(Token::Value _value, bool _advance)
|
||||
{
|
||||
Token::Value tok = m_scanner->currentToken();
|
||||
if (tok != _value)
|
||||
@@ -98,7 +98,8 @@ void ParserBase::expectToken(Token::Value _value)
|
||||
string("'")
|
||||
);
|
||||
}
|
||||
m_scanner->next();
|
||||
if (_advance)
|
||||
m_scanner->next();
|
||||
}
|
||||
|
||||
void ParserBase::increaseRecursionDepth()
|
||||
|
||||
@@ -63,7 +63,7 @@ protected:
|
||||
///@{
|
||||
///@name Helper functions
|
||||
/// If current token value is not _value, throw exception otherwise advance token.
|
||||
void expectToken(Token::Value _value);
|
||||
void expectToken(Token::Value _value, bool _advance = true);
|
||||
Token::Value currentToken() const;
|
||||
Token::Value peekNextToken() const;
|
||||
std::string currentLiteral() const;
|
||||
|
||||
Reference in New Issue
Block a user