diff options
author | RJ Catalano <catalanor0220@gmail.com> | 2015-12-17 06:01:45 +0800 |
---|---|---|
committer | RJ Catalano <catalanor0220@gmail.com> | 2015-12-17 06:01:45 +0800 |
commit | 559c2106432c8af121cb794d596fd79cf1031973 (patch) | |
tree | 8fffda3a6ffc1e5ff789aac0ce2ac0f1c6c7de38 /libsolidity/parsing/Parser.cpp | |
parent | 734318ed0408a59bd8efc3fc51978a41df110d70 (diff) | |
parent | fe04d7f7f7686ae8fa406880b3c3069e60ee1c20 (diff) | |
download | dexon-solidity-559c2106432c8af121cb794d596fd79cf1031973.tar.gz dexon-solidity-559c2106432c8af121cb794d596fd79cf1031973.tar.zst dexon-solidity-559c2106432c8af121cb794d596fd79cf1031973.zip |
Merge branch 'inlineArrays' into develop
Diffstat (limited to 'libsolidity/parsing/Parser.cpp')
-rw-r--r-- | libsolidity/parsing/Parser.cpp | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index 2b886121..4fad65bb 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -1035,27 +1035,36 @@ ASTPointer<Expression> Parser::parsePrimaryExpression() expression = nodeFactory.createNode<Identifier>(getLiteralAndAdvance()); break; case Token::LParen: + case Token::LBrack: { - // Tuple or parenthesized expression. - // Special cases: () is empty tuple type, (x) is not a real tuple, (x,) is one-dimensional tuple + // Tuple/parenthesized expression or inline array/bracketed expression. + // Special cases: ()/[] is empty tuple/array type, (x)/[] is not a real tuple/array, + // (x,) is one-dimensional tuple m_scanner->next(); vector<ASTPointer<Expression>> components; - if (m_scanner->currentToken() != Token::RParen) + Token::Value oppositeToken = (token == Token::LParen ? Token::RParen : Token::RBrack); + bool isArray = (token == Token::LBrack ? true : false); + if (isArray && (m_scanner->currentToken() == Token::Comma)) + fatalParserError(std::string("Expected value in array cell after '[' .")); + if (m_scanner->currentToken() != oppositeToken) 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) + if (isArray && (m_scanner->peekNextToken() == Token::Comma || m_scanner->peekNextToken() == oppositeToken)) + fatalParserError(std::string("Expected value in array cell after ',' .")); m_scanner->next(); } nodeFactory.markEndPosition(); - expectToken(Token::RParen); - return nodeFactory.createNode<TupleExpression>(components); + expectToken(oppositeToken); + return nodeFactory.createNode<TupleExpression>(components, isArray); } + default: if (Token::isElementaryTypeName(token)) { |