You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2016/08/24 07:32:44 UTC
groovy git commit: GROOVY-7911: Chained multiple assignment parsing
fail (closes #391)
Repository: groovy
Updated Branches:
refs/heads/master eec3b1f3d -> 9b0ffa1c9
GROOVY-7911: Chained multiple assignment parsing fail (closes #391)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/9b0ffa1c
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/9b0ffa1c
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/9b0ffa1c
Branch: refs/heads/master
Commit: 9b0ffa1c90218963f0add92cf5f2ced73bedecdb
Parents: eec3b1f
Author: paulk <pa...@asert.com.au>
Authored: Mon Aug 22 20:53:13 2016 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Wed Aug 24 17:32:06 2016 +1000
----------------------------------------------------------------------
src/main/org/codehaus/groovy/antlr/groovy.g | 10 ++++++++--
.../statements/MultipleAssignmentDeclarationTest.groovy | 7 +++++++
src/test/gls/statements/MultipleAssignmentTest.groovy | 9 +++++++++
3 files changed, 24 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/9b0ffa1c/src/main/org/codehaus/groovy/antlr/groovy.g
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/antlr/groovy.g b/src/main/org/codehaus/groovy/antlr/groovy.g
index bd40987..b973a5c 100644
--- a/src/main/org/codehaus/groovy/antlr/groovy.g
+++ b/src/main/org/codehaus/groovy/antlr/groovy.g
@@ -1443,7 +1443,10 @@ multipleAssignmentDeclaration {Token first = cloneToken(LT(1));}
(t:typeSpec[false]!)?
LPAREN^ nls! typeNamePairs[#mods,first] RPAREN!
ASSIGN^ nls!
- assignmentExpression[0]
+ (
+ (LPAREN nls IDENT (COMMA nls IDENT)* RPAREN ASSIGN) => multipleAssignment[0]
+ | assignmentExpression[0]
+ )
{#multipleAssignmentDeclaration=#(create(VARIABLE_DEF,"VARIABLE_DEF",first,LT(1)), #mods, #(create(TYPE,"TYPE",first,LT(1)),#t), #multipleAssignmentDeclaration);}
;
@@ -2330,7 +2333,10 @@ expression[int lc_stmt]
multipleAssignment[int lc_stmt] {Token first = cloneToken(LT(1));}
: LPAREN^ nls! listOfVariables[null,null,first] RPAREN!
ASSIGN^ nls!
- assignmentExpression[lc_stmt]
+ (
+ (LPAREN nls IDENT (COMMA nls IDENT)* RPAREN ASSIGN) => multipleAssignment[lc_stmt]
+ | assignmentExpression[lc_stmt]
+ )
;
http://git-wip-us.apache.org/repos/asf/groovy/blob/9b0ffa1c/src/test/gls/statements/MultipleAssignmentDeclarationTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/gls/statements/MultipleAssignmentDeclarationTest.groovy b/src/test/gls/statements/MultipleAssignmentDeclarationTest.groovy
index 3d08fb2..41d0fa3 100644
--- a/src/test/gls/statements/MultipleAssignmentDeclarationTest.groovy
+++ b/src/test/gls/statements/MultipleAssignmentDeclarationTest.groovy
@@ -104,4 +104,11 @@ class MultipleAssignmentDeclarationTest extends CompilableTestSupport {
assert j==3
"""
}
+
+ void testChainedMultiAssignmentDecl() {
+ def a, b
+ def (c, d) = (a, b) = [1, 2]
+ assert [a, b] == [1, 2]
+ assert [c, d] == [1, 2]
+ }
}
http://git-wip-us.apache.org/repos/asf/groovy/blob/9b0ffa1c/src/test/gls/statements/MultipleAssignmentTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/gls/statements/MultipleAssignmentTest.groovy b/src/test/gls/statements/MultipleAssignmentTest.groovy
index 4a682ef..537967f 100644
--- a/src/test/gls/statements/MultipleAssignmentTest.groovy
+++ b/src/test/gls/statements/MultipleAssignmentTest.groovy
@@ -70,4 +70,13 @@ class MultipleAssignmentTest extends CompilableTestSupport {
assert b == 2
assert c == null
}
+
+ void testChainedMultiAssignment() {
+ def a, b, c, d
+ (c, d) = (a, b) = [1, 2]
+ assert [a, b] == [1, 2]
+ assert [c, d] == [1, 2]
+ (c, d) = a = (a, b) = [3, 4]
+ assert [c, d] == [3, 4]
+ }
}
\ No newline at end of file