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/08/28 14:04:15 UTC
[groovy] branch master updated: Trivial tweak for parrot parser
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 166df38 Trivial tweak for parrot parser
166df38 is described below
commit 166df381927e68b93d58154a90439daaa87c8e46
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Aug 28 22:03:52 2021 +0800
Trivial tweak for parrot parser
---
src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java b/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
index c6078cb..250d17f 100644
--- a/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
+++ b/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
@@ -32,6 +32,7 @@ import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Recognizer;
import org.antlr.v4.runtime.Token;
+import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.atn.PredictionMode;
import org.antlr.v4.runtime.misc.Interval;
import org.antlr.v4.runtime.misc.ParseCancellationException;
@@ -405,10 +406,11 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
// parsing have to wait util clearing is complete.
AtnManager.READ_LOCK.lock();
try {
- if (SLL_THRESHOLD >= 0 && parser.getInputStream().size() > SLL_THRESHOLD) {
+ final TokenStream tokenStream = parser.getInputStream();
+ if (SLL_THRESHOLD >= 0 && tokenStream.size() > SLL_THRESHOLD) {
// The more tokens to parse, the more possibility SLL will fail and the more parsing time will waste.
// The option `groovy.antlr4.sll.threshold` could be tuned for better parsing performance, but it is disabled by default.
- // If the token count is greater than `groovy.antlr4.sll.threshold`, use ALL directly.
+ // If the token count is greater than `groovy.antlr4.sll.threshold`, use LL directly.
result = buildCST(PredictionMode.LL);
} else {
try {
@@ -419,6 +421,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
throw t;
}
+ tokenStream.seek(0);
result = buildCST(PredictionMode.LL);
}
}
@@ -438,7 +441,6 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
if (PredictionMode.SLL.equals(predictionMode)) {
this.removeErrorListeners();
} else {
- parser.getInputStream().seek(0);
this.addErrorListeners();
}