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 2021/02/13 04:26:38 UTC

[groovy] branch master updated: GROOVY-9936: Difference between old/new parser for variable declaration optimisation

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

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new c01eef4  GROOVY-9936: Difference between old/new parser for variable declaration optimisation
c01eef4 is described below

commit c01eef48e299c56e1c9315d0fe3a832f0e595c2f
Author: Paul King <pa...@asert.com.au>
AuthorDate: Thu Feb 11 17:38:52 2021 +1000

    GROOVY-9936: Difference between old/new parser for variable declaration optimisation
---
 .../groovy/parser/antlr4/SemanticPredicates.java   |  4 ++-
 src/test-resources/core/Command_07x.groovy         | 29 ++++++++++++++++++++++
 .../groovy/parser/antlr4/GroovyParserTest.groovy   |  1 +
 3 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/groovy/parser/antlr4/SemanticPredicates.java b/src/main/java/org/apache/groovy/parser/antlr4/SemanticPredicates.java
index 508dcd7..78e5877 100644
--- a/src/main/java/org/apache/groovy/parser/antlr4/SemanticPredicates.java
+++ b/src/main/java/org/apache/groovy/parser/antlr4/SemanticPredicates.java
@@ -179,10 +179,12 @@ public class SemanticPredicates {
         token = ts.LT(index);
         tokenType = token.getType();
         tokenType3 = ts.LT(index + 2).getType();
+        int nextCodePoint = token.getText().codePointAt(0);
 
         return // VOID == tokenType ||
                 !(BuiltInPrimitiveType == tokenType || Arrays.binarySearch(MODIFIER_ARRAY, tokenType) >= 0)
-                        && Character.isLowerCase(token.getText().codePointAt(0))
+                        && !Character.isUpperCase(nextCodePoint)
+                        && nextCodePoint != '@'
                         && !(ASSIGN == tokenType3 || (LT == tokenType2 || LBRACK == tokenType2));
 
     }
diff --git a/src/test-resources/core/Command_07x.groovy b/src/test-resources/core/Command_07x.groovy
new file mode 100644
index 0000000..7ddd3e1
--- /dev/null
+++ b/src/test-resources/core/Command_07x.groovy
@@ -0,0 +1,29 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+assert 1 == Eval.me('''
+def _foo(arg) { 1 }
+def bar = null
+_foo bar
+''')
+assert 2 == Eval.me('''
+def $foo(arg) { 2 }
+def bar = null
+$foo bar
+''')
+
diff --git a/src/test/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy b/src/test/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
index 6babb90..f7f0e59 100644
--- a/src/test/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
+++ b/src/test/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
@@ -368,6 +368,7 @@ final class GroovyParserTest extends GroovyTestCase {
         doTest('core/Command_04.groovy', [ExpressionStatement])
         doTest('core/Command_05.groovy')
         doRunAndTestAntlr4('core/Command_06x.groovy')
+        doRunAndTestAntlr4('core/Command_07x.groovy')
     }
 
     /*