什么可能导致 ANTLR4 4.7.1 中出现此运行时 Lexer 错误?
What could be causing this runtime Lexer error in ANTLR4 4.7.1?
我正在尝试从 4.5 更新到 ANTLR4 4.7.1。除了环境之外,唯一的变化是更新 ANTLRInputStream 和 ANTLRFileStream 对 CharStreams 的引用。然而,在 4.5 中工作的代码现在会抛出错误。
更新后,我在尝试 运行 测试时收到 NoSuchMethod 错误。
$ /usr/bin/java -cp $classpath org.antlr.v4.gui.TestRig com.greg.gumji_parser.Gumji2001 source_text -tokens -tree gumji/test_debug4.v
Exception in thread "main" java.lang.NoSuchMethodError: org.antlr.v4.runtime.atn.RuleTransition.<init>(Lorg/antlr/v4/runtime/atn/RuleStartState;IILorg/antlr/v4/runtime/atn/ATNState;)V
at org.antlr.v4.runtime.atn.ATNDeserializer.edgeFactory(ATNDeserializer.java:715)
at org.antlr.v4.runtime.atn.ATNDeserializer.deserialize(ATNDeserializer.java:332)
at com.greg.gumji_parser.Gumji2001Lexer.<clinit>(Gumji2001Lexer.java:3485)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.antlr.v4.gui.TestRig.process(TestRig.java:144)
at org.antlr.v4.gui.TestRig.main(TestRig.java:119)
$ echo $classpath
/home/greg/.m2/repository/com/greg/gumji2001-parser/1.0-SNAPSHOT/*:/usr/local/share/java/*:/home/greg/.m2/repository/org/antlr/antlr4/4.7.1/antlr4-4.7.1.jar:/home/greg/.m2/repository/org/antlr/antlr4-runtime/4.7.1/antlr4-runtime-4.7.1.jar
ATN 是否变得太大了?我将不胜感激有关如何调试此问题的任何建议。
Mark Rotteveel 在上面的评论中回答:
The fact you're using wildcards for your imports may lead to importing
unintended dependencies (eg from /usr/local/share/java
, or maybe
from that snapshot folder); it those paths contain older antlr
versions, you may actually be using an older versions of the runtime
than you think you're using, or worse: a combination of new and old!
我正在尝试从 4.5 更新到 ANTLR4 4.7.1。除了环境之外,唯一的变化是更新 ANTLRInputStream 和 ANTLRFileStream 对 CharStreams 的引用。然而,在 4.5 中工作的代码现在会抛出错误。
更新后,我在尝试 运行 测试时收到 NoSuchMethod 错误。
$ /usr/bin/java -cp $classpath org.antlr.v4.gui.TestRig com.greg.gumji_parser.Gumji2001 source_text -tokens -tree gumji/test_debug4.v
Exception in thread "main" java.lang.NoSuchMethodError: org.antlr.v4.runtime.atn.RuleTransition.<init>(Lorg/antlr/v4/runtime/atn/RuleStartState;IILorg/antlr/v4/runtime/atn/ATNState;)V
at org.antlr.v4.runtime.atn.ATNDeserializer.edgeFactory(ATNDeserializer.java:715)
at org.antlr.v4.runtime.atn.ATNDeserializer.deserialize(ATNDeserializer.java:332)
at com.greg.gumji_parser.Gumji2001Lexer.<clinit>(Gumji2001Lexer.java:3485)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.antlr.v4.gui.TestRig.process(TestRig.java:144)
at org.antlr.v4.gui.TestRig.main(TestRig.java:119)
$ echo $classpath
/home/greg/.m2/repository/com/greg/gumji2001-parser/1.0-SNAPSHOT/*:/usr/local/share/java/*:/home/greg/.m2/repository/org/antlr/antlr4/4.7.1/antlr4-4.7.1.jar:/home/greg/.m2/repository/org/antlr/antlr4-runtime/4.7.1/antlr4-runtime-4.7.1.jar
ATN 是否变得太大了?我将不胜感激有关如何调试此问题的任何建议。
Mark Rotteveel 在上面的评论中回答:
The fact you're using wildcards for your imports may lead to importing unintended dependencies (eg from
/usr/local/share/java
, or maybe from that snapshot folder); it those paths contain older antlr versions, you may actually be using an older versions of the runtime than you think you're using, or worse: a combination of new and old!