antlr / antlr4

ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.
http://antlr.org
BSD 3-Clause "New" or "Revised" License
17.11k stars 3.28k forks source link

invalid syntax `self.from = None` in python3 generated parsers #4028

Open chengchengpei opened 1 year ago

chengchengpei commented 1 year ago

Please include the following information

python3 antlr4 version is 4.9.3

import sys
import antlr4
from PrestoSqlLexer import PrestoSqlLexer
from PrestoSqlParser import PrestoSqlParser

def main():
    input_stream = antlr4.CharStream('select 1')
    lexer = PrestoSqlLexer(input_stream)
    tokens = antlr4.CommonTokenStream(lexer)
    tokens.fill()
    print([token.text for token in tokens.tokens][:-1])

if __name__ == '__main__':
    main()

error:

Traceback (most recent call last):
  File "/Users/clients/autocomplete/parseQuery.py", line 4, in <module>
    from PrestoSqlParser import PrestoSqlParser
  File "/Users/clients/autocomplete/PrestoSqlParser.py", line 1837
    self.from = None # QualifiedNameContext
         ^^^^
SyntaxError: invalid syntax
ericvergnaud commented 1 year ago

looks like you are using a reserved keyword in you grammar rules ?

chengchengpei commented 1 year ago

I changed to 4.11.1 and the errors gone...

ericvergnaud commented 1 year ago

Please close ?