[antlr-interest] How to stop lexer reporting errors to standard output?
Thomas Brandon
tbrandonau at gmail.com
Thu Aug 16 00:52:28 PDT 2007
On 8/16/07, Vaclav Barta <vbar at comp.cz> wrote:
> Hi,
>
> I'm writing a library (parsing SQL, among other things) using ANTLR
> (3.0, C# target), and I'd like it not to try any error recovery, but
> just throw an exception on invalid input (so that the library user can
> decide what to do about the error). I've managed to suppress error
> recovery by specifying an empty @rulecatch, but I still occasionally get
> warnings on standard output, i.e.
>
> SELECT '''
>
> results in
>
> line 1:10 mismatched character '<EOF>' expecting '''
>
> How do I get rid of the message (while still failing to parse the
> invalid input, of course)?
Override reportError in your lexer and do general handling there.
Tom.
>
> The lexer rule is AFAIK quite conventional
>
> fragment
> StringRun :
> (~ '\'' )+
> ;
>
> ASCIIStringLiteral :
> '\'' { text = ""; }
> ( s = StringRun { text = $s.text; } )? '\''
> ( '\'' {
> text = text + "\'";
> } ( s = StringRun { text = text + $s.text; } )? '\''
> )*
> ;
>
> if that helps.
>
> Bye
> Vasek
>
More information about the antlr-interest
mailing list