Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id E85E0200CE6 for ; Fri, 15 Sep 2017 17:54:02 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id E4D151609D2; Fri, 15 Sep 2017 15:54:02 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 4045D1609D1 for ; Fri, 15 Sep 2017 17:54:02 +0200 (CEST) Received: (qmail 47769 invoked by uid 500); 15 Sep 2017 15:54:00 -0000 Mailing-List: contact commits-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@groovy.apache.org Delivered-To: mailing list commits@groovy.apache.org Received: (qmail 47760 invoked by uid 99); 15 Sep 2017 15:54:00 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Sep 2017 15:54:00 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A0D97F55C0; Fri, 15 Sep 2017 15:54:00 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sunlan@apache.org To: commits@groovy.apache.org Message-Id: <70930241e8ac4b928db4e7f3d7fb5e8d@git.apache.org> X-Mailer: ASF-Git Admin Mailer 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 +0000 (UTC) archived-at: Fri, 15 Sep 2017 15:54:03 -0000 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 Authored: Fri Sep 15 23:53:49 2017 +0800 Committer: sunlan 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 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 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