Skip to content

Commit 5c5e988

Browse files
committed
Переезд на antlr 4.13.1.
Версия не совместима с прошлыми
2 parents ae01b3c + 9199a9a commit 5c5e988

File tree

5 files changed

+38
-152
lines changed

5 files changed

+38
-152
lines changed

.github/dependabot.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ updates:
99
directory: "/" # Location of package manifests
1010
schedule:
1111
interval: "daily"
12+
groups:
13+
freefair:
14+
patterns:
15+
- "io.freefair.*"
1216
- package-ecosystem: "github-actions"
1317
directory: "/"
1418
schedule:
1519
interval: "daily"
16-

build.gradle.kts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ plugins {
77
jacoco
88
`java-library`
99
signing
10-
id("org.sonarqube") version "4.4.1.3373"
10+
id("org.sonarqube") version "5.0.0.4638"
1111
id("org.cadixdev.licenser") version "0.6.1"
1212
id("me.qoomon.git-versioning") version "6.4.3"
13-
id("io.freefair.javadoc-links") version "8.4"
14-
id("io.freefair.javadoc-utf-8") version "8.4"
15-
id("com.github.ben-manes.versions") version "0.50.0"
16-
id("io.freefair.maven-central.validate-poms") version "8.4"
17-
id("ru.vyarus.pom") version "2.2.2"
13+
id("io.freefair.javadoc-links") version "8.6"
14+
id("io.freefair.javadoc-utf-8") version "8.6"
15+
id("com.github.ben-manes.versions") version "0.51.0"
16+
id("io.freefair.maven-central.validate-poms") version "8.6"
17+
id("ru.vyarus.pom") version "3.0.0"
1818
id("io.codearte.nexus-staging") version "0.30.0"
1919
}
2020

@@ -43,7 +43,7 @@ gitVersioning.apply {
4343
val isSnapshot = gitVersioning.gitVersionDetails.refType != GitRefType.TAG
4444

4545
dependencies {
46-
implementation("com.tunnelvisionlabs", "antlr4", "4.9.0")
46+
implementation("org.antlr", "antlr4", "4.13.1")
4747
implementation("com.github.1c-syntax", "utils", "0.5.1")
4848
implementation("commons-io", "commons-io", "2.15.1")
4949
}

src/main/java/com/github/_1c_syntax/bsl/parser/CRAwareLexerATNSimulator.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@
2525
import org.antlr.v4.runtime.Lexer;
2626
import org.antlr.v4.runtime.atn.ATN;
2727
import org.antlr.v4.runtime.atn.LexerATNSimulator;
28+
import org.antlr.v4.runtime.atn.PredictionContextCache;
29+
import org.antlr.v4.runtime.dfa.DFA;
2830

2931
public class CRAwareLexerATNSimulator extends LexerATNSimulator {
30-
public CRAwareLexerATNSimulator(ATN atn) {
31-
super(atn);
32-
}
33-
34-
public CRAwareLexerATNSimulator(Lexer recog, ATN atn) {
35-
super(recog, atn);
32+
public CRAwareLexerATNSimulator(Lexer recog, ATN atn, DFA[] dfas, PredictionContextCache sharedContextCache) {
33+
super(recog, atn, dfas, sharedContextCache);
3634
}
3735

3836
@Override

src/main/java/com/github/_1c_syntax/bsl/parser/CaseChangingCharStream.java

Lines changed: 0 additions & 133 deletions
This file was deleted.

src/main/java/com/github/_1c_syntax/bsl/parser/Tokenizer.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.antlr.v4.runtime.CommonToken;
2828
import org.antlr.v4.runtime.CommonTokenStream;
2929
import org.antlr.v4.runtime.ConsoleErrorListener;
30+
import org.antlr.v4.runtime.IntStream;
3031
import org.antlr.v4.runtime.Lexer;
3132
import org.antlr.v4.runtime.Parser;
3233
import org.antlr.v4.runtime.Token;
@@ -36,12 +37,13 @@
3637

3738
import java.io.IOException;
3839
import java.io.InputStream;
39-
import java.io.InputStreamReader;
40-
import java.io.Reader;
4140
import java.lang.reflect.InvocationTargetException;
41+
import java.lang.reflect.Method;
4242
import java.nio.charset.StandardCharsets;
4343
import java.util.ArrayList;
44+
import java.util.Arrays;
4445
import java.util.List;
46+
import java.util.Optional;
4547

4648
import static java.util.Objects.requireNonNull;
4749
import static org.antlr.v4.runtime.Token.EOF;
@@ -62,6 +64,8 @@ public abstract class Tokenizer<T extends BSLParserRuleContext, P extends Parser
6264
private final Class<P> parserClass;
6365
protected P parser;
6466

67+
private final Optional<Method> setInputStreamMethod;
68+
6569
protected Tokenizer(String content, Lexer lexer, Class<P> parserClass) {
6670
this(IOUtils.toInputStream(content, StandardCharsets.UTF_8), lexer, parserClass);
6771
}
@@ -72,6 +76,11 @@ protected Tokenizer(InputStream content, Lexer lexer, Class<P> parserClass) {
7276
this.content = content;
7377
this.lexer = lexer;
7478
this.parserClass = parserClass;
79+
var methods = lexer.getClass().getMethods();
80+
setInputStreamMethod = Arrays.stream(methods)
81+
.filter(method -> "setInputStream".equals(method.getName())
82+
&& method.getParameterCount() == 1
83+
&& method.getParameterTypes()[0] == IntStream.class).findFirst();
7584
}
7685

7786
/**
@@ -85,6 +94,7 @@ public List<Token> getTokens() {
8594

8695
/**
8796
* Возвращает абстрактное синтаксическое дерево, полученное на основании парсинга
97+
*
8898
* @return AST
8999
*/
90100
public T getAst() {
@@ -123,15 +133,23 @@ private CommonTokenStream computeTokenStream() {
123133

124134
try (
125135
var ubis = new UnicodeBOMInputStream(content);
126-
Reader inputStreamReader = new InputStreamReader(ubis, StandardCharsets.UTF_8)
127136
) {
128137
ubis.skipBOM();
129-
input = CharStreams.fromReader(inputStreamReader);
138+
input = CharStreams.fromStream(ubis);
130139
} catch (IOException e) {
131140
throw new RuntimeException(e);
132141
}
133142

134-
lexer.setInputStream(input);
143+
if (setInputStreamMethod.isPresent()) {
144+
try {
145+
setInputStreamMethod.get().invoke(lexer, input);
146+
} catch (IllegalAccessException | InvocationTargetException e) {
147+
throw new RuntimeException(e);
148+
}
149+
} else {
150+
lexer.setInputStream(input);
151+
}
152+
135153
lexer.removeErrorListener(ConsoleErrorListener.INSTANCE);
136154

137155
var tempTokenStream = new CommonTokenStream(lexer);

0 commit comments

Comments
 (0)