Trying to setup ANTLR for python following this instructions http://blog.anvard.org/articles/2016/03/15/antlr-python.html
and additionally using a local copy of antlr-4.7.2-complete.jar
there are syntax errors.
With python2 this:
> from antlr4 import *
File "/usr/local/lib/python2.7/dist-packages/antlr4/__init__.py",
line 1, in <module>
from antlr4.Token import Token
File "/usr/local/lib/python2.7/dist-packages/antlr4/Token.py", line 59
def text(self, text:str):
^
With python3 this:
> Traceback (most recent call last):
File "test_Hello.py", line 1, in <module>
from antlr4 import *
File "/usr/local/lib/python3.6/dist-packages/antlr4/__init__.py",
line 5, in <module>
from antlr4.BufferedTokenStream import TokenStream
File "/usr/local/lib/python3.6/dist-packages/antlr4
/BufferedTokenStream.py", line 18, in <module>
from antlr4.error.Errors import IllegalStateException
File "/usr/local/lib/python3.6/dist-packages/antlr4/error/Errors.py",
line 39, in <module>
from antlr4.Recognizer import Recognizer
File "/usr/local/lib/python3.6/dist-packages/antlr4/Recognizer.py", line
6, in <module>
from __builtin__ import unicode
ModuleNotFoundError: No module named '__builtin__'
To generate the python code I used a fresh copy of Antlr4 - Version 4.7.1 - jar in the working directory and generated the python files for python2 like this:
alias antlr4='java -jar antlr-4.7.2-complete.jar'
antlr4 -Dlanguage=Python2 Hello.g4
and
alias antlr4='java -jar antlr-4.7.2-complete.jar'
antlr4 -Dlanguage=Python3 Hello.g4
for python3.
Python 2 version is 2.7.15+ Python 3 version is 3.6.8.
I already had a look at some similar question, like this: Python+ANTLR4: No module named antlr4
but could not find a solution to this problem.