groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [groovy] branch master updated: Trivial refactoring: simplify code and extract common variable
Date Wed, 15 Jan 2020 09:59:38 GMT
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 13ab93b  Trivial refactoring: simplify code and extract common variable
13ab93b is described below

commit 13ab93b1319972cd63bff70486a9be1d1252a2d1
Author: Daniel Sun <sunlan@apache.org>
AuthorDate: Wed Jan 15 17:59:00 2020 +0800

    Trivial refactoring: simplify code and extract common variable
---
 src/antlr/GroovyLexer.g4 | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/src/antlr/GroovyLexer.g4 b/src/antlr/GroovyLexer.g4
index bdad910..016824f 100644
--- a/src/antlr/GroovyLexer.g4
+++ b/src/antlr/GroovyLexer.g4
@@ -38,7 +38,6 @@ options {
 }
 
 @header {
-    import static org.apache.groovy.parser.antlr4.SemanticPredicates.*;
     import java.util.Deque;
     import java.util.ArrayDeque;
     import java.util.Map;
@@ -48,6 +47,8 @@ options {
     import java.util.Collections;
     import java.util.Arrays;
     import java.util.stream.IntStream;
+    import org.apache.groovy.util.Maps;
+    import static org.apache.groovy.parser.antlr4.SemanticPredicates.*;
 }
 
 @members {
@@ -139,13 +140,12 @@ options {
         }
     }
 
-    private static final Map<String, String> PAREN_MAP = Collections.unmodifiableMap(new
HashMap<String, String>() {
-        {
-            put("(", ")");
-            put("[", "]");
-            put("{", "}");
-        }
-    });
+    private static final Map<String, String> PAREN_MAP =
+        Maps.of(
+            "(", ")",
+            "[", "]",
+            "{", "}"
+        );
 
     protected void enterParenCallback(String text) {}
 
@@ -300,7 +300,8 @@ GStringPathPart
 RollBackOne
     :   . {
             // a trick to handle GStrings followed by EOF properly
-            if (EOF == _input.LA(1) && ('"' == _input.LA(-1) || '/' == _input.LA(-1)))
{
+            int readChar = _input.LA(-1);
+            if (EOF == _input.LA(1) && ('"' == readChar || '/' == readChar)) {
                 setType(GStringEnd);
             } else {
                 setChannel(HIDDEN);


Mime
View raw message