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

Error while calling getText method #2051

Open faza opened 7 years ago

faza commented 7 years ago

Runtime: python 3.5 Library: antlr4-python3-runtime==4.5 Grammar: Java.g4

Input

char[0][0]='@';

I am getting the following error for the above assignment statement. It is due to incorrect syntax.

 in exitBlockStatement
    stmt = ctx.getText()
  File "/home/faza/.virtualenvs/env/lib/python3.5/site-packages/antlr4/RuleContext.py", line 106, in getText
    if self.getChildCount() == 0:
  File "/home/faza/.virtualenvs/env/lib/python3.5/site-packages/antlr4/ParserRuleContext.py", line 177, in getChildCount
    return len(self.children)
TypeError: object of type 'NoneType' has no len()
faza commented 7 years ago

But error is not thrown in case of

if(str.chaAt(0)=='N'){

        }

Is this the issue with the grammar or the runtime library?

faza commented 7 years ago

I understand that

char[0][0]='@';

is not a valid statement. But what should be the expected behaviour of getText() in this scenario?

faza commented 7 years ago

This issue has been resolved in 4.7 version of runtime library