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/06/25 13:47:18 UTC

[groovy] 02/02: Tweak the fix for GROOVY-9588

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

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

commit f521ef8adeba890957939bff034a1b8ca63ee208
Author: Daniel Sun <su...@apache.org>
AuthorDate: Thu Jun 25 21:35:17 2020 +0800

    Tweak the fix for GROOVY-9588
---
 src/antlr/GroovyParser.g4                               |  3 ---
 src/test/gls/generics/GenericsUsageTest.groovy          |  4 ++--
 .../antlr4/internal/DescriptiveErrorStrategy.java       |  3 +--
 .../parser/antlr4/util/PositionConfigureUtils.java      | 17 -----------------
 .../apache/groovy/parser/antlr4/SyntaxErrorTest.groovy  |  7 +++++--
 5 files changed, 8 insertions(+), 26 deletions(-)

diff --git a/src/antlr/GroovyParser.g4 b/src/antlr/GroovyParser.g4
index c29212f..968bd62 100644
--- a/src/antlr/GroovyParser.g4
+++ b/src/antlr/GroovyParser.g4
@@ -42,7 +42,6 @@ options {
 @header {
     import java.util.Map;
     import org.codehaus.groovy.ast.NodeMetaDataHandler;
-    import org.apache.groovy.parser.antlr4.util.PositionConfigureUtils;
 }
 
 @members {
@@ -1256,8 +1255,6 @@ keywords
 
 rparen
     :   RPAREN
-    |   r=~RPAREN // !!!Error Alternative
-        { require(false, "Missing ')'", PositionConfigureUtils.calcMissingRparenOffset($r, _input)); }
     ;
 
 nls
diff --git a/src/test/gls/generics/GenericsUsageTest.groovy b/src/test/gls/generics/GenericsUsageTest.groovy
index 88a16d8..b4e05f4 100644
--- a/src/test/gls/generics/GenericsUsageTest.groovy
+++ b/src/test/gls/generics/GenericsUsageTest.groovy
@@ -122,7 +122,7 @@ final class GenericsUsageTest extends CompilableTestSupport {
     void testGenericsDiamondShortcutIllegalPosition() {
         shouldFailCompilationWithAnyMessage '''
             List<> list4 = []
-        ''', ['unexpected token: <', 'Unexpected input: \'<\'']
+        ''', ['unexpected token: <', 'Unexpected input: \'<>\'']
     }
 
     void testGenericsInAsType() {
@@ -166,7 +166,7 @@ final class GenericsUsageTest extends CompilableTestSupport {
 
         shouldFailCompilationWithMessage """
             def m(Class<Integer someParam) {}
-        """, "Unexpected input: '<'"
+        """, "Unexpected input: 'Class<Integer someParam'"
 
         shouldFailCompilationWithMessage """
             abstract class ArrayList1<E extends AbstractList<E> implements List<E> {}
diff --git a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/internal/DescriptiveErrorStrategy.java b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/internal/DescriptiveErrorStrategy.java
index 97bfb5a..897133a 100644
--- a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/internal/DescriptiveErrorStrategy.java
+++ b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/internal/DescriptiveErrorStrategy.java
@@ -94,8 +94,7 @@ public class DescriptiveErrorStrategy extends BailErrorStrategy {
 
     protected String createInputMismatchErrorMessage(Parser recognizer,
                                                      InputMismatchException e) {
-        return "Unexpected input: " + getTokenErrorDisplay(e.getOffendingToken(recognizer)) +
-                "; Expecting " + e.getExpectedTokens().toString(recognizer.getVocabulary());
+        return "Unexpected input: " + getTokenErrorDisplay(e.getOffendingToken(recognizer));
     }
 
     protected void reportInputMismatch(Parser recognizer,
diff --git a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/util/PositionConfigureUtils.java b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/util/PositionConfigureUtils.java
index de7a299..a009468 100644
--- a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/util/PositionConfigureUtils.java
+++ b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/util/PositionConfigureUtils.java
@@ -18,13 +18,10 @@
  */
 package org.apache.groovy.parser.antlr4.util;
 
-import groovy.lang.Tuple;
 import groovy.lang.Tuple2;
 import org.antlr.v4.runtime.Token;
-import org.antlr.v4.runtime.TokenStream;
 import org.antlr.v4.runtime.tree.TerminalNode;
 import org.apache.groovy.parser.antlr4.GroovyParser;
-import org.apache.groovy.parser.antlr4.SyntaxErrorReportable;
 import org.codehaus.groovy.ast.ASTNode;
 
 import static groovy.lang.Tuple.tuple;
@@ -34,20 +31,6 @@ import static org.codehaus.groovy.runtime.DefaultGroovyMethods.asBoolean;
  * Utilities for configuring node positions
  */
 public class PositionConfigureUtils {
-    public static Tuple2<Integer, Integer> calcMissingRparenOffset(Token errorToken, TokenStream tokenStream) {
-        Token token = tokenStream.LT(-2);
-        int tokenType = token.getType();
-
-        // DON'T adjust the offset for type casting, e.g. `println ((int) 6`
-        if (GroovyParser.RPAREN == tokenType) {
-            return SyntaxErrorReportable.NO_OFFSET;
-        }
-
-        final int errorTokenLength = errorToken.getText().length();
-
-        return Tuple.tuple(0, -errorTokenLength);
-    }
-
     /**
      * Sets location(lineNumber, colNumber, lastLineNumber, lastColumnNumber) for node using standard context information.
      * Note: this method is implemented to be closed over ASTNode. It returns same node as it received in arguments.
diff --git a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
index de3ad53..54d87f2 100644
--- a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
+++ b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
@@ -99,7 +99,7 @@ final class SyntaxErrorTest extends GroovyTestCase {
         // TODO: Could the character be escaped in the error message?
         assert err == '''\
             |startup failed:
-            |test.groovy: 1: Unexpected input: '\u200B'; Expecting <EOF> @ line 1, column 7.
+            |test.groovy: 1: Unexpected input: '\u200B' @ line 1, column 7.
             |   def na\u200Bme = null
             |         ^
             |
@@ -115,7 +115,7 @@ final class SyntaxErrorTest extends GroovyTestCase {
         // TODO: Could the character be escaped in the error message?
         assert err == '''\
             |startup failed:
-            |test.groovy: 1: Unexpected input: '\u000C'; Expecting <EOF> @ line 1, column 7.
+            |test.groovy: 1: Unexpected input: '\u000C' @ line 1, column 7.
             |   def na\u000Cme = null
             |         ^
             |
@@ -386,6 +386,7 @@ final class SyntaxErrorTest extends GroovyTestCase {
         TestUtils.doRunAndShouldFail('fail/Array_02x.groovy')
     }
 
+    @NotYetImplemented
     void 'test error alternative - Missing ")" 1'() {
         def err = expectParseError '''\
             |println ((int 123)
@@ -401,6 +402,7 @@ final class SyntaxErrorTest extends GroovyTestCase {
             |'''.stripMargin()
     }
 
+    @NotYetImplemented
     void 'test error alternative - Missing ")" 2'() {
         def err = expectParseError '''\
             |def x() {
@@ -418,6 +420,7 @@ final class SyntaxErrorTest extends GroovyTestCase {
             |'''.stripMargin()
     }
 
+    @NotYetImplemented
     void 'test error alternative - Missing ")" 3'() {
         def err = expectParseError '''\
             |def m( {