diff options
Diffstat (limited to 'libsolidity/parsing/Parser.cpp')
-rw-r--r-- | libsolidity/parsing/Parser.cpp | 33 |
1 files changed, 7 insertions, 26 deletions
diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index 50e4d29d..ba92d2aa 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -1034,50 +1034,31 @@ ASTPointer<Expression> Parser::parsePrimaryExpression() nodeFactory.markEndPosition(); expression = nodeFactory.createNode<Identifier>(getLiteralAndAdvance()); break; - case Token::LParen: + case Token::LParen || Token::LBrack: { // Tuple or parenthesized expression. // Special cases: () is empty tuple type, (x) is not a real tuple, (x,) is one-dimensional tuple m_scanner->next(); vector<ASTPointer<Expression>> components; + Token::Value oppositeToken = (token == LParen ? Token::RParen : Token::RBrack); + if (m_scanner->currentToken() != Token::RParen) while (true) { - if (m_scanner->currentToken() != Token::Comma && m_scanner->currentToken() != Token::RParen) + if (m_scanner->currentToken() != Token::Comma && m_scanner->currentToken() != oppositeToken) components.push_back(parseExpression()); else components.push_back(ASTPointer<Expression>()); - if (m_scanner->currentToken() == Token::RParen) + if (m_scanner->currentToken() == oppositeToken) break; else if (m_scanner->currentToken() == Token::Comma) m_scanner->next(); } nodeFactory.markEndPosition(); - expectToken(Token::RParen); + expectToken(oppositeToken); return nodeFactory.createNode<TupleExpression>(components); } - case Token::LBrack: - { - // Inline array expression - // Special cases: [] is empty tuple type, (x) is not a real tuple, (x,) is one-dimensional tuple - m_scanner->next(); - vector<ASTPointer<Expression>> components; - if (m_scanner->currentToken() != Token::RBrack) - while (true) - { - if (m_scanner->currentToken() != Token::Comma && m_scanner->currentToken() != Token::RBrack) - components.push_back(parseExpression()); - else - components.push_back(ASTPointer<Expression>()); - if (m_scanner->currentToken() == Token::RBrack) - break; - else if (m_scanner->currentToken() == Token::Comma) - m_scanner->next(); - } - nodeFactory.markEndPosition(); - expectToken(Token::RBrack); - return nodeFactory.createNode<TupleExpression>(components); - } + default: if (Token::isElementaryTypeName(token)) { |