Simplify expectIdentifierToken by using expectToken

This commit is contained in:
Alex Beregszaszi
2018-05-03 22:10:51 +01:00
parent 73c99d15cd
commit ed9f80690b
13 changed files with 16 additions and 33 deletions
+2 -19
View File
@@ -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();
}
-1
View File
@@ -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();
///@}
+3 -2
View File
@@ -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()
+1 -1
View File
@@ -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;