I am having a problem generating and running grammar that produces Python code.
The problem is related to deserializing and failing the version check.
Here is my research on the problem, questions are at the bottom of this message
My VSCode settings for the plugin are
"antlr4.generation": {
"mode": "external",
"language": "Python3",
"listeners": true,
"visitors": false,
"outputDir": "./parser"
},
"antlr4.debug": {
"visualParseTreeHorizontal": true,
"visualParseTreeClustered": false
}
When I go to run my python code, the ATN deserializer is reporting that it needs version 4, this appears to be baked into the ANTLR4 runtime
It does not seem to report the version it found, but it emits this exception
Could not deserialize ATN with version (expected 4).
File "/Users/jgentilin/Projects/ANTLR/PythonExample/arithmeticLexer.py", line 28, in arithmeticLexer atn = ATNDeserializer().deserialize(serializedATN()) File "/Users/jgentilin/Projects/ANTLR/PythonExample/arithmeticLexer.py", line 26, in <module> class arithmeticLexer(Lexer): File "/Users/jgentilin/Projects/ANTLR/PythonExample/main.py", line 3, in <module> from arithmeticLexer import arithmeticLexer
if version != SERIALIZED_VERSION:
raise Exception("Could not deserialize ATN with version " + str(version) + " (expected " + str(SERIALIZED_VERSION) + ").")
Not sure why the str(version) is not bring printed unless ANTLR is not emitting the version into the ATN
It appears I can disable it by setting verifyATN to false, but haven't found docs on if I should do that or not and how to do it.
def verifyATN(self, atn:ATN):
if not self.deserializationOptions.verifyATN:
If I don't specify mode: External, it won't listen to either the language or outputDir options and builds a Java parser in the .antlr dir
Besides the ANTLR version installed in the plugin, this version of Antlr is installed in my system. ANTLR Parser Generator Version 4.9.3
If I download the latest jar, store it in the bin/ directory at the root of my workspace then add
"alternativeJar": "bin/antlr-4.10.1-complete.jar",
to my settings, I get the following exception when the plugin tries to process my grammar files
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main"
java.lang.UnsupportedClassVersionError: JVMCFRE003 bad major version; class=org/antlr/v4/Tool, offset=6
My questions are:
- Do I need to set the version somewhere in my code?
- Is there a way to have ANTLR just bake the runtime into my grammar output so I don't have to worry about versions.
- I am assuming this could happen again when the plugin updates but the runtime hasn't
- Any clue where to check next ?
Thank you
-John