@@ -87,27 +87,19 @@ private Statement statement() {
8787 if (match (TokenType .MATCH )) {
8888 return new ExprStatement (match ());
8989 }
90- if (match (TokenType .EXTRACT )) {
91- return destructuringAssignment ();
92- }
9390 if (lookMatch (0 , TokenType .WORD ) && lookMatch (1 , TokenType .LPAREN )) {
9491 return new ExprStatement (function (qualifiedName ()));
9592 }
9693 return assignmentStatement ();
9794 }
9895
9996 private Statement assignmentStatement () {
100- if (lookMatch (0 , TokenType .WORD ) && lookMatch (1 , TokenType .EQ )) {
101- final String variable = consume (TokenType .WORD ).getText ();
102- consume (TokenType .EQ );
103- return new AssignmentStatement (variable , expression ());
97+ if (match (TokenType .EXTRACT )) {
98+ return destructuringAssignment ();
10499 }
105-
106- final Expression qualifiedNameExpr = qualifiedName ();
107- if (lookMatch (0 , TokenType .EQ ) && (qualifiedNameExpr instanceof ContainerAccessExpression )) {
108- consume (TokenType .EQ );
109- final ContainerAccessExpression containerExpr = (ContainerAccessExpression ) qualifiedNameExpr ;
110- return new ContainerAssignmentStatement (containerExpr , expression ());
100+ final Expression assignment = assignmentStrict ();
101+ if (assignment != null ) {
102+ return new ExprStatement (assignment );
111103 }
112104 throw new ParseException ("Unknown statement: " + get (0 ));
113105 }
@@ -330,9 +322,36 @@ private MatchExpression match() {
330322 }
331323
332324 private Expression expression () {
325+ return assignment ();
326+ }
327+
328+ private Expression assignment () {
329+ final Expression assignment = assignmentStrict ();
330+ if (assignment != null ) {
331+ return assignment ;
332+ }
333333 return ternary ();
334334 }
335335
336+ private Expression assignmentStrict () {
337+ if (lookMatch (0 , TokenType .WORD ) && lookMatch (1 , TokenType .EQ )) {
338+ final String variable = consume (TokenType .WORD ).getText ();
339+ consume (TokenType .EQ );
340+ return new AssignmentExpression (variable , expression ());
341+ }
342+
343+ final int position = pos ;
344+ final Expression qualifiedNameExpr = qualifiedName ();
345+ if (lookMatch (0 , TokenType .EQ ) && (qualifiedNameExpr instanceof ContainerAccessExpression )) {
346+ consume (TokenType .EQ );
347+ final ContainerAccessExpression containerExpr = (ContainerAccessExpression ) qualifiedNameExpr ;
348+ return new ContainerAssignmentExpression (containerExpr , expression ());
349+ }
350+ pos = position ;
351+
352+ return null ;
353+ }
354+
336355 private Expression ternary () {
337356 Expression result = logicalOr ();
338357
0 commit comments