Index: src/org/python/antlr/RecordingErrorHandler.java =================================================================== --- src/org/python/antlr/RecordingErrorHandler.java (revision 6429:ba74f5e6dcd8) +++ src/org/python/antlr/RecordingErrorHandler.java (revision 6429+:ba74f5e6dcd8+) @@ -26,7 +26,6 @@ public List errs = new ArrayList(); public void reportError(BaseRecognizer br, RecognitionException re) { - br.reportError(re); errs.add(re); } Index: grammar/Python.g =================================================================== --- grammar/Python.g (revision 6429:ba74f5e6dcd8) +++ grammar/Python.g (revision 6429+:ba74f5e6dcd8+) @@ -191,11 +191,22 @@ this.encoding = encoding; } + @Override + public void reportError(RecognitionException e) { + // Update syntax error count and output error. + super.reportError(e); + errorHandler.reportError(this, e); -} + } + @Override + public void displayRecognitionError(String[] tokenNames, RecognitionException e) { + // Do nothing. We record errors instead of printing them. + } +} + @rulecatch { catch (RecognitionException re) { - errorHandler.reportError(this, re); + reportError(re); errorHandler.recover(this, input,re); retval.tree = (PythonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re); } @@ -257,16 +268,16 @@ } return state.token; } catch (NoViableAltException nva) { - errorHandler.reportError(this, nva); + reportError(nva); errorHandler.recover(this, nva); // throw out current char and try again } catch (FailedPredicateException fp) { //XXX: added this for failed STRINGPART -- the FailedPredicateException // hides a NoViableAltException. This should be the only // FailedPredicateException that gets thrown by the lexer. - errorHandler.reportError(this, fp); + reportError(fp); errorHandler.recover(this, fp); // throw out current char and try again } catch (RecognitionException re) { - errorHandler.reportError(this, re); + reportError(re); // match() routine has already called recover() } } @@ -298,7 +309,7 @@ ; //XXX: this block is duplicated in three places, how to extract? catch [RecognitionException re] { - errorHandler.reportError(this, re); + reportError(re); errorHandler.recover(this, input,re); PythonTree badNode = (PythonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re); retval.tree = new ErrorMod(badNode); @@ -337,7 +348,7 @@ ; //XXX: this block is duplicated in three places, how to extract? catch [RecognitionException re] { - errorHandler.reportError(this, re); + reportError(re); errorHandler.recover(this, input,re); PythonTree badNode = (PythonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re); retval.tree = new ErrorMod(badNode); @@ -358,7 +369,7 @@ ; //XXX: this block is duplicated in three places, how to extract? catch [RecognitionException re] { - errorHandler.reportError(this, re); + reportError(re); errorHandler.recover(this, input,re); PythonTree badNode = (PythonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re); retval.tree = new ErrorMod(badNode);