Call visitErrorNodes properly in Python targets.

The consume method of the Parser class calls visitTerminal on both
TerminalNodes and ErrorNodes even if the comment above states that
ErrorNodes should be visited by visitErrorNodes. This behaviour
is also inconsitent with the Java target. The patch fixes this in
both Python targets.
This commit is contained in:
Renata Hodovan 2016-12-09 19:31:29 +01:00
parent 661c87b47c
commit bd09023209
2 changed files with 8 additions and 2 deletions

View File

@ -328,7 +328,10 @@ class Parser (Recognizer):
node = self._ctx.addTokenNode(o)
if hasListener:
for listener in self._parseListeners:
listener.visitTerminal(node)
if isinstance(node, ErrorNode):
listener.visitErrorNode(node)
elif isinstance(node, TerminalNode):
listener.visitTerminal(node)
return o
def addContextToParseTree(self):

View File

@ -335,7 +335,10 @@ class Parser (Recognizer):
node = self._ctx.addTokenNode(o)
if hasListener:
for listener in self._parseListeners:
listener.visitTerminal(node)
if isinstance(node, ErrorNode):
listener.visitErrorNode(node)
elif isinstance(node, TerminalNode):
listener.visitTerminal(node)
return o
def addContextToParseTree(self):