From bd0902320933afab5b481724b4b6eb2a0f998d32 Mon Sep 17 00:00:00 2001 From: Renata Hodovan Date: Fri, 9 Dec 2016 19:31:29 +0100 Subject: [PATCH] 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. --- runtime/Python2/src/antlr4/Parser.py | 5 ++++- runtime/Python3/src/antlr4/Parser.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/runtime/Python2/src/antlr4/Parser.py b/runtime/Python2/src/antlr4/Parser.py index 97cf4924a..e70318dfc 100644 --- a/runtime/Python2/src/antlr4/Parser.py +++ b/runtime/Python2/src/antlr4/Parser.py @@ -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): diff --git a/runtime/Python3/src/antlr4/Parser.py b/runtime/Python3/src/antlr4/Parser.py index e831b6415..bf63ea56c 100644 --- a/runtime/Python3/src/antlr4/Parser.py +++ b/runtime/Python3/src/antlr4/Parser.py @@ -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):