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 13:07:49 UTC
[groovy] branch GROOVY_3_0_X updated: Tweak `identifier` rule
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
new 54cc7af Tweak `identifier` rule
54cc7af is described below
commit 54cc7afd2f188a78c5fe1c17f2e32d91bf3c1d32
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Jul 4 20:48:04 2020 +0800
Tweak `identifier` rule
(cherry picked from commit ce27b89eb7b698baea10d3b082b952fc7cf2717a)
---
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