aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-05-04 18:50:12 +0800
committerGitHub <noreply@github.com>2018-05-04 18:50:12 +0800
commit81d61ca086e8e45108b7989e7f1494d90077401e (patch)
tree7ed329c24ea5d5082c325e9ebc270b9b9c31dbc6 /libsolidity
parenta244f1a383ad46e9f789d66434a6828db0021f11 (diff)
parented9f80690bde53e56c6ef5cb046fb20713f3f780 (diff)
downloaddexon-solidity-81d61ca086e8e45108b7989e7f1494d90077401e.tar
dexon-solidity-81d61ca086e8e45108b7989e7f1494d90077401e.tar.gz
dexon-solidity-81d61ca086e8e45108b7989e7f1494d90077401e.tar.bz2
dexon-solidity-81d61ca086e8e45108b7989e7f1494d90077401e.tar.lz
dexon-solidity-81d61ca086e8e45108b7989e7f1494d90077401e.tar.xz
dexon-solidity-81d61ca086e8e45108b7989e7f1494d90077401e.tar.zst
dexon-solidity-81d61ca086e8e45108b7989e7f1494d90077401e.zip
Merge pull request #4059 from ethereum/parser-simplify
Simplify the parser expectations
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/parsing/Parser.cpp37
-rw-r--r--libsolidity/parsing/Parser.h2
-rw-r--r--libsolidity/parsing/ParserBase.cpp5
-rw-r--r--libsolidity/parsing/ParserBase.h2
4 files changed, 8 insertions, 38 deletions
diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp
index a9ee9016..37732a37 100644
--- a/libsolidity/parsing/Parser.cpp
+++ b/libsolidity/parsing/Parser.cpp
@@ -1194,7 +1194,8 @@ ASTPointer<Expression> Parser::parseExpression(
ASTPointer<Expression> expression = parseBinaryExpression(4, _lookAheadIndexAccessStructure);
if (Token::isAssignmentOp(m_scanner->currentToken()))
{
- Token::Value assignmentOperator = expectAssignmentOperator();
+ Token::Value assignmentOperator = m_scanner->currentToken();
+ m_scanner->next();
ASTPointer<Expression> rightHandSide = parseExpression();
ASTNodeFactory nodeFactory(*this, expression);
nodeFactory.setEndPositionFromNode(rightHandSide);
@@ -1601,40 +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);
-}
-
-Token::Value Parser::expectAssignmentOperator()
-{
- Token::Value op = m_scanner->currentToken();
- if (!Token::isAssignmentOp(op))
- fatalParserError(
- string("Expected assignment operator, got '") +
- currentTokenName() +
- string("'")
- );
- m_scanner->next();
- return op;
-}
-
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();
}
diff --git a/libsolidity/parsing/Parser.h b/libsolidity/parsing/Parser.h
index c4254231..7f02d895 100644
--- a/libsolidity/parsing/Parser.h
+++ b/libsolidity/parsing/Parser.h
@@ -165,8 +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();
- Token::Value expectAssignmentOperator();
ASTPointer<ASTString> expectIdentifierToken();
ASTPointer<ASTString> getLiteralAndAdvance();
///@}
diff --git a/libsolidity/parsing/ParserBase.cpp b/libsolidity/parsing/ParserBase.cpp
index 5b83c5bd..617a1779 100644
--- a/libsolidity/parsing/ParserBase.cpp
+++ b/libsolidity/parsing/ParserBase.cpp
@@ -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()
diff --git a/libsolidity/parsing/ParserBase.h b/libsolidity/parsing/ParserBase.h
index fd0de0d1..b28e1b1b 100644
--- a/libsolidity/parsing/ParserBase.h
+++ b/libsolidity/parsing/ParserBase.h
@@ -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;