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:23:43 UTC
[groovy] branch GROOVY_3_0_X updated: Trivial tweak for parrot
parser
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 db98141 Trivial tweak for parrot parser
db98141 is described below
commit db98141e72d2f251a5788a8d8dca0262f4096ee5
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Aug 28 22:03:52 2021 +0800
Trivial tweak for parrot parser
(cherry picked from commit 166df381927e68b93d58154a90439daaa87c8e46)
---
.../src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
index e67947b..fcecc85 100644
--- a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
+++ b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
@@ -29,6 +29,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;
@@ -208,10 +209,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 {
@@ -222,6 +224,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
throw t;
}
+ tokenStream.seek(0);
result = buildCST(PredictionMode.LL);
}
}
@@ -241,7 +244,6 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
if (PredictionMode.SLL.equals(predictionMode)) {
this.removeErrorListeners();
} else {
- parser.getInputStream().seek(0);
this.addErrorListeners();
}