From 42c43394040e68c3bb32ed1e73992e096e5d10d2 Mon Sep 17 00:00:00 2001 From: RJ Catalano Date: Tue, 15 Dec 2015 10:57:57 -0600 Subject: updated attempt, a couple of more things to sort through and change --- libsolidity/parsing/Parser.cpp | 10 ++++++---- test/libsolidity/SolidityParser.cpp | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index 2b886121..5a3ed56e 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -1034,26 +1034,28 @@ ASTPointer Parser::parsePrimaryExpression() nodeFactory.markEndPosition(); expression = nodeFactory.createNode(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> 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()); - 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(components); } default: diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp index fd9076c3..d8c1a3e6 100644 --- a/test/libsolidity/SolidityParser.cpp +++ b/test/libsolidity/SolidityParser.cpp @@ -1047,6 +1047,20 @@ BOOST_AUTO_TEST_CASE(using_for) BOOST_CHECK(successParse(text)); } +BOOST_AUTO_TEST_CASE(inline_array_declaration) +{ + char const* text = R"( + contract c { + uint[] a; + function f() returns (uint, uint) { + a = [1,2,3]; + return (a[3], [3,4][0]); + } + } + )"; + BOOST_CHECK(successParse(text)); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit v1.2.3