groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: Refine the grammar: 1)`def` is still required for performance when declaring tuple; 2)Stop supporting command expression in parentheses
Date Fri, 15 Sep 2017 15:54:00 GMT
Repository: groovy
Updated Branches:
  refs/heads/master a2fe3a5fd -> 7c773923e


Refine the grammar: 1)`def` is still required for performance when declaring tuple; 2)Stop
supporting command expression in parentheses


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/7c773923
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/7c773923
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/7c773923

Branch: refs/heads/master
Commit: 7c773923eddfbdf6a4a91e603fd4573927082bf2
Parents: a2fe3a5
Author: sunlan <sunlan@apache.org>
Authored: Fri Sep 15 23:53:49 2017 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Fri Sep 15 23:53:49 2017 +0800

----------------------------------------------------------------------
 src/antlr/GroovyParser.g4                         |  7 ++++++-
 .../apache/groovy/parser/antlr4/AstBuilder.java   | 18 +++++++++++++++++-
 .../groovy/parser/antlr4/GroovyParserTest.groovy  |  4 +++-
 .../core/LocalVariableDeclaration_02x.groovy      |  3 +++
 4 files changed, 29 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/7c773923/src/antlr/GroovyParser.g4
----------------------------------------------------------------------
diff --git a/src/antlr/GroovyParser.g4 b/src/antlr/GroovyParser.g4
index 009f415..8f8aad3 100644
--- a/src/antlr/GroovyParser.g4
+++ b/src/antlr/GroovyParser.g4
@@ -779,7 +779,7 @@ parExpression
     ;
 
 expressionInPar
-    :   LPAREN enhancedStatementExpression rparen
+    :   LPAREN enhancedExpression rparen
     ;
 
 expressionList[boolean canSpread]
@@ -915,6 +915,11 @@ expression
                      enhancedStatementExpression                                        
   #assignmentExprAlt
     ;
 
+enhancedExpression
+    :   expression
+    |   standardLambdaExpression
+    ;
+
 commandExpression
     :   pathExpression
         (

http://git-wip-us.apache.org/repos/asf/groovy/blob/7c773923/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
index 2f538fa..01f4213 100644
--- a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
+++ b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
@@ -1779,6 +1779,22 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object>
implements Groov
     }
 
     @Override
+    public Expression visitEnhancedExpression(EnhancedExpressionContext ctx) {
+        Expression expression;
+
+        if (asBoolean(ctx.expression())) {
+            expression = (Expression) this.visit(ctx.expression());
+        } else if (asBoolean(ctx.standardLambdaExpression())) {
+            expression = this.visitStandardLambdaExpression(ctx.standardLambdaExpression());
+        } else {
+            throw createParsingFailedException("Unsupported enhanced expression: " + ctx.getText(),
ctx);
+        }
+
+        return configureAST(expression, ctx);
+    }
+
+
+    @Override
     public ExpressionStatement visitCommandExprAlt(CommandExprAltContext ctx) {
         return configureAST(new ExpressionStatement(this.visitCommandExpression(ctx.commandExpression())),
ctx);
     }
@@ -1907,7 +1923,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object>
implements Groov
 
     @Override
     public Expression visitExpressionInPar(ExpressionInParContext ctx) {
-        return this.visitEnhancedStatementExpression(ctx.enhancedStatementExpression());
+        return this.visitEnhancedExpression(ctx.enhancedExpression());
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/groovy/blob/7c773923/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
index 84ff8fc..91cd61f 100644
--- a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
+++ b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
@@ -282,6 +282,8 @@ class GroovyParserTest extends GroovyTestCase {
 
     void "test groovy core - LocalVariableDeclaration"() {
         doTest('core/LocalVariableDeclaration_01.groovy', [Token]); // [class org.codehaus.groovy.syntax.Token][startLine]::
9 != 8
+        doRunAndTest('core/LocalVariableDeclaration_02x.groovy')
+
     }
 
     void "test groovy core - MethodDeclaration"() {
@@ -331,7 +333,7 @@ class GroovyParserTest extends GroovyTestCase {
         doTest('core/Command_03.groovy', [ExpressionStatement, Parameter]);
         doTest('core/Command_04.groovy', [ExpressionStatement]);
         doTest('core/Command_05.groovy');
-        doRunAndTest('core/Command_06x.groovy')
+//        doRunAndTest('core/Command_06x.groovy')
     }
 
     /*

http://git-wip-us.apache.org/repos/asf/groovy/blob/7c773923/subprojects/parser-antlr4/src/test/resources/core/LocalVariableDeclaration_02x.groovy
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/test/resources/core/LocalVariableDeclaration_02x.groovy
b/subprojects/parser-antlr4/src/test/resources/core/LocalVariableDeclaration_02x.groovy
new file mode 100644
index 0000000..1e3a2ba
--- /dev/null
+++ b/subprojects/parser-antlr4/src/test/resources/core/LocalVariableDeclaration_02x.groovy
@@ -0,0 +1,3 @@
+def (int x, int y) = [1, 2]
+assert 1 == x
+assert 2 == y


Mime
View raw message