سؤال

Is it possible to use the antlr4 python runtime with python 2.6 or is the minimun required version python 2.7? I want to use it on CentOS 6.3 that comes with python 2.6.6. If it is not possible, is it known what features of python 2.7 that is used?

هل كانت مفيدة؟

المحلول

Finally I can answer this myself. It is not possible to use antlr4-python2 runtime on centos6.3 (that has python 2.6.6), I have installed it and tried this example. The result is as follows:

[lg@localhost py]$ python test.py data.txt 
Traceback (most recent call last):
  File "test.py", line 15, in <module>
    main(sys.argv)
  File "test.py", line 10, in main
    tree = parser.r()
  File "/home/lg/antlr/py/HelloParser.py", line 74, in r
    self.enterRule(localctx, 0, self.RULE_r)
  File "/usr/lib/python2.6/site-packages/antlr4/Parser.py", line 367, in enterRule
    self._ctx.start = self._input.LT(1)
  File "/usr/lib/python2.6/site-packages/antlr4/CommonTokenStream.py", line 85, in LT
    self.lazyInit()
  File "/usr/lib/python2.6/site-packages/antlr4/BufferedTokenStream.py", line 209, in lazyInit
    self.setup()
  File "/usr/lib/python2.6/site-packages/antlr4/BufferedTokenStream.py", line 212, in setup
    self.sync(0)
  File "/usr/lib/python2.6/site-packages/antlr4/BufferedTokenStream.py", line 134, in sync
    fetched = self.fetch(n)
  File "/usr/lib/python2.6/site-packages/antlr4/BufferedTokenStream.py", line 146, in fetch
    t = self.tokenSource.nextToken()
  File "/usr/lib/python2.6/site-packages/antlr4/Lexer.py", line 131, in nextToken
    tokenStartMarker = self._input.mark()
AttributeError: 'builtin_function_or_method' object has no attribute 'mark'
[lg@localhost py]$ 

نصائح أخرى

The example you used was badly written. input is the name of a built-in Python function. Give the Lexer a FileStream and it might work.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top