From 574e48b0b51bbf890702a0c0fbae799473945bdb Mon Sep 17 00:00:00 2001 From: RJ Catalano Date: Mon, 14 Dec 2015 17:40:35 -0600 Subject: Inline array declarations complete --- libsolidity/parsing/Parser.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'libsolidity/parsing/Parser.cpp') diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index 2b886121..50e4d29d 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -1056,6 +1056,28 @@ ASTPointer Parser::parsePrimaryExpression() expectToken(Token::RParen); return nodeFactory.createNode(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> 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()); + 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(components); + } default: if (Token::isElementaryTypeName(token)) { -- cgit v1.2.3 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 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'libsolidity/parsing/Parser.cpp') 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: -- cgit v1.2.3 From 5a462afd03dc425ab77e718e430f19512740c6b1 Mon Sep 17 00:00:00 2001 From: RJ Catalano Date: Tue, 15 Dec 2015 11:37:00 -0600 Subject: fixed case statements --- libsolidity/parsing/Parser.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'libsolidity/parsing/Parser.cpp') diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index ba92d2aa..149948f7 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -1034,7 +1034,8 @@ ASTPointer Parser::parsePrimaryExpression() nodeFactory.markEndPosition(); expression = nodeFactory.createNode(getLiteralAndAdvance()); break; - case Token::LParen || Token::LBrack: + 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 -- cgit v1.2.3 From aebce8a1d5aa8bf06719341432f487acd347d297 Mon Sep 17 00:00:00 2001 From: RJ Catalano Date: Tue, 15 Dec 2015 12:22:52 -0600 Subject: now is compiling and passing soltest...but I think there may be a few more things to do --- libsolidity/parsing/Parser.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'libsolidity/parsing/Parser.cpp') diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index 149948f7..cb5968e9 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -1037,11 +1037,13 @@ ASTPointer Parser::parsePrimaryExpression() 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> components; - Token::Value oppositeToken = (token == LParen ? Token::RParen : Token::RBrack); + Token::Value oppositeToken = (token == Token::LParen ? Token::RParen : Token::RBrack); + bool isArray = (token == Token::LParen ? false : true); if (m_scanner->currentToken() != Token::RParen) while (true) @@ -1057,7 +1059,7 @@ ASTPointer Parser::parsePrimaryExpression() } nodeFactory.markEndPosition(); expectToken(oppositeToken); - return nodeFactory.createNode(components); + return nodeFactory.createNode(components, isArray); } default: -- cgit v1.2.3 From 0ba24a5289eaaf1941c1e84e774f938353b9b94c Mon Sep 17 00:00:00 2001 From: RJ Catalano Date: Wed, 16 Dec 2015 12:55:52 -0600 Subject: changed a couple of small nuances, made an attempt at fixing the parsing in the inline arrays case (fails), and added test for inline arrays per Chriseth request --- libsolidity/parsing/Parser.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'libsolidity/parsing/Parser.cpp') diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index cb5968e9..e7391dff 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -1043,9 +1043,10 @@ ASTPointer Parser::parsePrimaryExpression() m_scanner->next(); vector> components; Token::Value oppositeToken = (token == Token::LParen ? Token::RParen : Token::RBrack); - bool isArray = (token == Token::LParen ? false : true); - - if (m_scanner->currentToken() != Token::RParen) + bool isArray = (token == Token::RBrace ? true : false); + if (isArray && (m_scanner->currentToken() == Token::Comma)) + fatalParserError("Expected value in array cell after '[' ."); + if (m_scanner->currentToken() != oppositeToken) while (true) { if (m_scanner->currentToken() != Token::Comma && m_scanner->currentToken() != oppositeToken) @@ -1055,6 +1056,8 @@ ASTPointer Parser::parsePrimaryExpression() if (m_scanner->currentToken() == oppositeToken) break; else if (m_scanner->currentToken() == Token::Comma) + if (isArray && (m_scanner->peekNextToken() == (Token::Comma || oppositeToken))) + fatalParserError("Expected value in array cell after ',' ."); m_scanner->next(); } nodeFactory.markEndPosition(); -- cgit v1.2.3 From de969945ea819b06a787e8aba47a2c5353a966ba Mon Sep 17 00:00:00 2001 From: RJ Catalano Date: Wed, 16 Dec 2015 13:17:41 -0600 Subject: Parsing is complete --- libsolidity/parsing/Parser.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'libsolidity/parsing/Parser.cpp') diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index e7391dff..3df3ac17 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -1043,9 +1043,9 @@ ASTPointer Parser::parsePrimaryExpression() m_scanner->next(); vector> components; Token::Value oppositeToken = (token == Token::LParen ? Token::RParen : Token::RBrack); - bool isArray = (token == Token::RBrace ? true : false); + bool isArray = (token == Token::LBrack ? true : false); if (isArray && (m_scanner->currentToken() == Token::Comma)) - fatalParserError("Expected value in array cell after '[' ."); + fatalParserError(std::string("Expected value in array cell after '[' .")); if (m_scanner->currentToken() != oppositeToken) while (true) { @@ -1057,7 +1057,7 @@ ASTPointer Parser::parsePrimaryExpression() break; else if (m_scanner->currentToken() == Token::Comma) if (isArray && (m_scanner->peekNextToken() == (Token::Comma || oppositeToken))) - fatalParserError("Expected value in array cell after ',' ."); + fatalParserError(std::string("Expected value in array cell after ',' .")); m_scanner->next(); } nodeFactory.markEndPosition(); -- cgit v1.2.3 From fe04d7f7f7686ae8fa406880b3c3069e60ee1c20 Mon Sep 17 00:00:00 2001 From: RJ Catalano Date: Wed, 16 Dec 2015 14:50:40 -0600 Subject: added one more test and realized that there was one last change before the parser is perfect --- libsolidity/parsing/Parser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libsolidity/parsing/Parser.cpp') diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index 3df3ac17..4fad65bb 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -1056,7 +1056,7 @@ ASTPointer Parser::parsePrimaryExpression() if (m_scanner->currentToken() == oppositeToken) break; else if (m_scanner->currentToken() == Token::Comma) - if (isArray && (m_scanner->peekNextToken() == (Token::Comma || oppositeToken))) + if (isArray && (m_scanner->peekNextToken() == Token::Comma || m_scanner->peekNextToken() == oppositeToken)) fatalParserError(std::string("Expected value in array cell after ',' .")); m_scanner->next(); } -- cgit v1.2.3