[antlr-interest] Lexer.getNumberOfSyntaxErrors not reliable; is this a bug?

Johan Cockx johan at sikanda.be
Wed May 6 07:18:25 PDT 2009


Hi,

I am using ANTLR 3.1.3.

The class BaseRecognizer has a method getNumberOfSyntaxErrors() that is
supposed to return the number of syntax errors detected.

The count is maintained in BaseRecognizer.reportError(...).

However,  the Lexer class overrides this method and does not update the
syntax error count when a lexer error is reported.  As a result,  the syntax
error count is not reliable in the lexer.

The only way to reliably count lexer syntax errors seems to be to override
reportError again and maintain the count yourself.

Is this a bug?  If it is a feature,  it seems to be an undocumented one.

Is there a better way to detect whether an error has ocurred during
parsing?  I could not find a way to suppress error recovery in the lexer,
and the comment in the Lexer.reportError implementation is not very
promising: it reads "TODO: not thought about recovery in lexer yet."

I am looking for a way to reliably detect whether my ANTLR-generated parser
and lexer have detected any syntax errors.

Regards, Johan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090506/a7c3b139/attachment.html 


More information about the antlr-interest mailing list