From 6e02088e6abb687f4752b3d0bfcf9fe56e8b3992 Mon Sep 17 00:00:00 2001 From: Renata Hodovan Date: Tue, 18 Jul 2017 18:29:36 +0200 Subject: [PATCH] Python: add public getter to parsers to access syntax error count. ANTLR parsers in Java are allowed to access the number of encountered syntax errors via the getNumberOfSyntaxErrors method. However, the Python variants must use the protected _syntaxErrors member to get this value. The patch defines the same getter for Python targets too. --- runtime/Python2/src/antlr4/Parser.py | 7 +++++++ runtime/Python3/src/antlr4/Parser.py | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/runtime/Python2/src/antlr4/Parser.py b/runtime/Python2/src/antlr4/Parser.py index d88f77918..69abe739b 100644 --- a/runtime/Python2/src/antlr4/Parser.py +++ b/runtime/Python2/src/antlr4/Parser.py @@ -218,6 +218,13 @@ class Parser (Recognizer): self._ctx.exitRule(listener) listener.exitEveryRule(self._ctx) + # Gets the number of syntax errors reported during parsing. This value is + # incremented each time {@link #notifyErrorListeners} is called. + # + # @see #notifyErrorListeners + # + def getNumberOfSyntaxErrors(self): + return self._syntaxErrors def getTokenFactory(self): return self._input.tokenSource._factory diff --git a/runtime/Python3/src/antlr4/Parser.py b/runtime/Python3/src/antlr4/Parser.py index 03f10a438..c461bbdc0 100644 --- a/runtime/Python3/src/antlr4/Parser.py +++ b/runtime/Python3/src/antlr4/Parser.py @@ -227,6 +227,14 @@ class Parser (Recognizer): listener.exitEveryRule(self._ctx) + # Gets the number of syntax errors reported during parsing. This value is + # incremented each time {@link #notifyErrorListeners} is called. + # + # @see #notifyErrorListeners + # + def getNumberOfSyntaxErrors(self): + return self._syntaxErrors + def getTokenFactory(self): return self._input.tokenSource._factory