-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Closed
Closed
Copy link
Labels
Milestone
Description
ANTLR 4.7.1 is generating incorrect Python3 code for the grammer :
var_defs
locals [ varlist = [] ]
: 'var' var_def ( ',' var_def )* ';' {print($varlist)}
;
var_def
: v=VARIABLE ':' var_type {$var_defs::varlist.append($v.text)}
;
The code generated for the parser is :
...
self.state = 45
self.var_type()
getInvokingContext(1).varlist.append((None if localctx.v is None else localctx.v.text))
...
instead of :
...
self.state = 45
self.var_type()
self.getInvokingContext(1).varlist.append((None if localctx.v is None else localctx.v.text))
...
When the getInvokingContext function is called then the following error pops up in Parser.py: ctx.ruleIndex is not defined.
def getInvokingContext(self, ruleIndex:int):
ctx = self._ctx
while ctx is not None:
>>>>>> if ctx.ruleIndex == ruleIndex:
return ctx
ctx = ctx.parentCtx
return None
I had to change it to:
def getInvokingContext(self, ruleIndex:int):
ctx = self._ctx
while ctx is not None:
>>>>>> if ctx.getRuleIndex() == ruleIndex:
return ctx
ctx = ctx.parentCtx
return None
I am using Python 3.8.1, vs code ANTLR4 grammer plugin. with ANTLR 4.7.1