mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Move Solidity specific methods from ParserBase to the Solidity Parser
This commit is contained in:
parent
788b64ea61
commit
2fefe3b549
@ -1437,5 +1437,61 @@ ASTPointer<ParameterList> Parser::createEmptyParameterList()
|
|||||||
return nodeFactory.createNode<ParameterList>(vector<ASTPointer<VariableDeclaration>>());
|
return nodeFactory.createNode<ParameterList>(vector<ASTPointer<VariableDeclaration>>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Token::Value Parser::expectAssignmentOperator()
|
||||||
|
{
|
||||||
|
Token::Value op = m_scanner->currentToken();
|
||||||
|
if (!Token::isAssignmentOp(op))
|
||||||
|
{
|
||||||
|
if (Token::isElementaryTypeName(op)) //for the sake of accuracy in reporting
|
||||||
|
{
|
||||||
|
ElementaryTypeNameToken elemTypeName = m_scanner->currentElementaryTypeNameToken();
|
||||||
|
fatalParserError(
|
||||||
|
string("Expected assignment operator, got '") +
|
||||||
|
elemTypeName.toString() +
|
||||||
|
string("'")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
fatalParserError(
|
||||||
|
string("Expected assignment operator, got '") +
|
||||||
|
string(Token::name(m_scanner->currentToken())) +
|
||||||
|
string("'")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
m_scanner->next();
|
||||||
|
return op;
|
||||||
|
}
|
||||||
|
|
||||||
|
ASTPointer<ASTString> Parser::expectIdentifierToken()
|
||||||
|
{
|
||||||
|
Token::Value id = m_scanner->currentToken();
|
||||||
|
if (id != Token::Identifier)
|
||||||
|
{
|
||||||
|
if (Token::isElementaryTypeName(id)) //for the sake of accuracy in reporting
|
||||||
|
{
|
||||||
|
ElementaryTypeNameToken elemTypeName = m_scanner->currentElementaryTypeNameToken();
|
||||||
|
fatalParserError(
|
||||||
|
string("Expected identifier, got '") +
|
||||||
|
elemTypeName.toString() +
|
||||||
|
string("'")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
fatalParserError(
|
||||||
|
string("Expected identifier, got '") +
|
||||||
|
string(Token::name(id)) +
|
||||||
|
string("'")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return getLiteralAndAdvance();
|
||||||
|
}
|
||||||
|
|
||||||
|
ASTPointer<ASTString> Parser::getLiteralAndAdvance()
|
||||||
|
{
|
||||||
|
ASTPointer<ASTString> identifier = make_shared<ASTString>(m_scanner->currentLiteral());
|
||||||
|
m_scanner->next();
|
||||||
|
return identifier;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,6 +154,10 @@ private:
|
|||||||
std::vector<ASTPointer<PrimaryExpression>> const& _path,
|
std::vector<ASTPointer<PrimaryExpression>> const& _path,
|
||||||
std::vector<std::pair<ASTPointer<Expression>, SourceLocation>> const& _indices
|
std::vector<std::pair<ASTPointer<Expression>, SourceLocation>> const& _indices
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Token::Value expectAssignmentOperator();
|
||||||
|
ASTPointer<ASTString> expectIdentifierToken();
|
||||||
|
ASTPointer<ASTString> getLiteralAndAdvance();
|
||||||
///@}
|
///@}
|
||||||
|
|
||||||
/// Creates an empty ParameterList at the current location (used if parameters can be omitted).
|
/// Creates an empty ParameterList at the current location (used if parameters can be omitted).
|
||||||
|
@ -80,62 +80,6 @@ void ParserBase::expectToken(Token::Value _value)
|
|||||||
m_scanner->next();
|
m_scanner->next();
|
||||||
}
|
}
|
||||||
|
|
||||||
Token::Value ParserBase::expectAssignmentOperator()
|
|
||||||
{
|
|
||||||
Token::Value op = m_scanner->currentToken();
|
|
||||||
if (!Token::isAssignmentOp(op))
|
|
||||||
{
|
|
||||||
if (Token::isElementaryTypeName(op)) //for the sake of accuracy in reporting
|
|
||||||
{
|
|
||||||
ElementaryTypeNameToken elemTypeName = m_scanner->currentElementaryTypeNameToken();
|
|
||||||
fatalParserError(
|
|
||||||
string("Expected assignment operator, got '") +
|
|
||||||
elemTypeName.toString() +
|
|
||||||
string("'")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
fatalParserError(
|
|
||||||
string("Expected assignment operator, got '") +
|
|
||||||
string(Token::name(m_scanner->currentToken())) +
|
|
||||||
string("'")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
m_scanner->next();
|
|
||||||
return op;
|
|
||||||
}
|
|
||||||
|
|
||||||
ASTPointer<ASTString> ParserBase::expectIdentifierToken()
|
|
||||||
{
|
|
||||||
Token::Value id = m_scanner->currentToken();
|
|
||||||
if (id != Token::Identifier)
|
|
||||||
{
|
|
||||||
if (Token::isElementaryTypeName(id)) //for the sake of accuracy in reporting
|
|
||||||
{
|
|
||||||
ElementaryTypeNameToken elemTypeName = m_scanner->currentElementaryTypeNameToken();
|
|
||||||
fatalParserError(
|
|
||||||
string("Expected identifier, got '") +
|
|
||||||
elemTypeName.toString() +
|
|
||||||
string("'")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
fatalParserError(
|
|
||||||
string("Expected identifier, got '") +
|
|
||||||
string(Token::name(id)) +
|
|
||||||
string("'")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return getLiteralAndAdvance();
|
|
||||||
}
|
|
||||||
|
|
||||||
ASTPointer<ASTString> ParserBase::getLiteralAndAdvance()
|
|
||||||
{
|
|
||||||
ASTPointer<ASTString> identifier = make_shared<ASTString>(m_scanner->currentLiteral());
|
|
||||||
m_scanner->next();
|
|
||||||
return identifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ParserBase::parserError(string const& _description)
|
void ParserBase::parserError(string const& _description)
|
||||||
{
|
{
|
||||||
auto err = make_shared<Error>(Error::Type::ParserError);
|
auto err = make_shared<Error>(Error::Type::ParserError);
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <libsolidity/interface/Exceptions.h>
|
#include <libsolidity/interface/Exceptions.h>
|
||||||
#include <libsolidity/parsing/Token.h>
|
#include <libsolidity/parsing/Token.h>
|
||||||
#include <libsolidity/ast/ASTForward.h>
|
|
||||||
|
|
||||||
namespace dev
|
namespace dev
|
||||||
{
|
{
|
||||||
@ -52,9 +51,6 @@ protected:
|
|||||||
///@name Helper functions
|
///@name Helper functions
|
||||||
/// If current token value is not _value, throw exception otherwise advance token.
|
/// If current token value is not _value, throw exception otherwise advance token.
|
||||||
void expectToken(Token::Value _value);
|
void expectToken(Token::Value _value);
|
||||||
Token::Value expectAssignmentOperator();
|
|
||||||
ASTPointer<ASTString> expectIdentifierToken();
|
|
||||||
ASTPointer<ASTString> getLiteralAndAdvance();
|
|
||||||
///@}
|
///@}
|
||||||
|
|
||||||
/// Creates a @ref ParserError and annotates it with the current position and the
|
/// Creates a @ref ParserError and annotates it with the current position and the
|
||||||
|
Loading…
Reference in New Issue
Block a user