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 14:56:22 UTC
[groovy] branch GROOVY_3_0_X updated: 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_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 8946bd6 Tweak the fix for GROOVY-9588
8946bd6 is described below
commit 8946bd6953244d27f197f380b43af751b99d6977
Author: Daniel Sun <su...@apache.org>
AuthorDate: Thu Jun 25 22:43:41 2020 +0800
Tweak the fix for GROOVY-9588
Whether we tweak the error alternative or not, the parsing performance is still impacted quite a lot. Use the default error reporting as antlr2 parser does.
(cherry picked from commit 83d399e3ce3ad35f564b22a8713ad8b7530d1e5a)
---
src/antlr/GroovyParser.g4 | 3 ---
src/test/gls/generics/GenericsUsageTest.groovy | 4 ++--
src/test/groovy/bugs/Groovy4252Bug.groovy | 6 +++---
.../groovy/org/apache/groovy/groovysh/Groovysh.groovy | 8 ++++----
.../antlr4/internal/DescriptiveErrorStrategy.java | 3 +--
.../parser/antlr4/util/PositionConfigureUtils.java | 17 -----------------
.../apache/groovy/parser/antlr4/SyntaxErrorTest.groovy | 7 +++++--
7 files changed, 15 insertions(+), 33 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 c9f74ef..8448ff4 100644
--- a/src/test/gls/generics/GenericsUsageTest.groovy
+++ b/src/test/gls/generics/GenericsUsageTest.groovy
@@ -124,7 +124,7 @@ final class GenericsUsageTest extends CompilableTestSupport {
void testGenericsDiamondShortcutIllegalPosition() {
shouldFailCompilationWithAnyMessage '''
List<> list4 = []
- ''', ['unexpected token: <', 'Unexpected input: \'<\'']
+ ''', ['unexpected token: <', 'Unexpected input: \'<>\'']
}
void testGenericsInAsType() {
@@ -206,7 +206,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/src/test/groovy/bugs/Groovy4252Bug.groovy b/src/test/groovy/bugs/Groovy4252Bug.groovy
index 10830bd..f5a8faf 100644
--- a/src/test/groovy/bugs/Groovy4252Bug.groovy
+++ b/src/test/groovy/bugs/Groovy4252Bug.groovy
@@ -31,7 +31,7 @@ class Groovy4252Bug extends GroovyShellTestCase {
} catch (MultipleCompilationErrorsException e) {
def syntaxError = e.errorCollector.getSyntaxError(0)
assert syntaxError.message.contains("Expression list of the form (a; b; c) is not supported in this context") ||
- syntaxError.message.contains("Missing ')'")
+ syntaxError.message.contains("Unexpected input: '('")
}
}
@@ -44,7 +44,7 @@ class Groovy4252Bug extends GroovyShellTestCase {
} catch (MultipleCompilationErrorsException e) {
def syntaxError = e.errorCollector.getSyntaxError(0)
assert syntaxError.message.contains("Expression list of the form (a; b; c) is not supported in this context") ||
- syntaxError.message.contains("Missing ')'")
+ syntaxError.message.contains("Unexpected input: ';'")
}
}
@@ -57,7 +57,7 @@ class Groovy4252Bug extends GroovyShellTestCase {
} catch (MultipleCompilationErrorsException e) {
def syntaxError = e.errorCollector.getSyntaxError(0)
assert syntaxError.message.contains("Expression list of the form (a; b; c) is not supported in this context") ||
- syntaxError.message.contains("Missing ')'")
+ syntaxError.message.contains("Unexpected input: '('")
}
}
diff --git a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Groovysh.groovy b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Groovysh.groovy
index 99f7c79..701c947 100644
--- a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Groovysh.groovy
+++ b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Groovysh.groovy
@@ -248,11 +248,11 @@ class Groovysh extends Shell {
// TODO antlr4 parser errors pop out here - can we rework to be like antlr2?
(
t.message.contains('Unexpected input:') && !(
- t.message.contains('Unexpected input: \'}\';')
- || t.message.contains('Unexpected input: \')\';')
- || t.message.contains('Unexpected input: \']\';')
+ t.message.contains('Unexpected input: \'}\'')
+ || t.message.contains('Unexpected input: \')\'')
+ || t.message.contains('Unexpected input: \']\'')
)
- ) || t.message.contains("Missing ')'")
+ )
}
/**
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( {