You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2020/07/04 12:51:30 UTC

[groovy] branch danielsun/tweak-identifier-rule created (now 102e8bd)

This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a change to branch danielsun/tweak-identifier-rule
in repository https://gitbox.apache.org/repos/asf/groovy.git.


      at 102e8bd  Tweak `identifier` rule

This branch includes the following new commits:

     new 102e8bd  Tweak `identifier` rule

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[groovy] 01/01: Tweak `identifier` rule

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch danielsun/tweak-identifier-rule
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 102e8bd52e193edaa754af7c31feb49ca773f552
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Jul 4 20:48:04 2020 +0800

    Tweak `identifier` rule
---
 src/antlr/GroovyParser.g4                                    | 12 +++++++-----
 .../java/org/apache/groovy/parser/antlr4/AstBuilder.java     | 10 +++++++++-
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/src/antlr/GroovyParser.g4 b/src/antlr/GroovyParser.g4
index 9feca64..02cadee 100644
--- a/src/antlr/GroovyParser.g4
+++ b/src/antlr/GroovyParser.g4
@@ -892,7 +892,13 @@ commandArgument
  *      6: non-static inner class creator
  */
 pathExpression returns [int t]
-    :   primary (pathElement { $t = $pathElement.t; })*
+    :   (
+            primary
+        |
+            // if 'static' followed by DOT, we can treat them as identifiers, e.g. static.unused = { -> }
+            { DOT == _input.LT(2).getType() }?
+            STATIC
+        ) (pathElement { $t = $pathElement.t; })*
     ;
 
 pathElement returns [int t]
@@ -1183,10 +1189,6 @@ identifier
 //    |   DEF
     |   TRAIT
     |   AS
-    |
-        // if 'static' followed by DOT, we can treat them as identifiers, e.g. static.unused = { -> }
-        { DOT == _input.LT(2).getType() }?
-        STATIC
     ;
 
 builtInType
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 d138716..0721c14 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
@@ -2243,7 +2243,15 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
 
     @Override
     public Expression visitPathExpression(PathExpressionContext ctx) {
-        return this.createPathExpression((Expression) this.visit(ctx.primary()), ctx.pathElement());
+        final TerminalNode staticTerminalNode = ctx.STATIC();
+        Expression primaryExpr;
+        if (asBoolean(staticTerminalNode)) {
+            primaryExpr = configureAST(new VariableExpression(staticTerminalNode.getText()), staticTerminalNode);
+        } else {
+            primaryExpr = (Expression) this.visit(ctx.primary());
+        }
+
+        return this.createPathExpression(primaryExpr, ctx.pathElement());
     }
 
     @Override