[antlr-interest] getting the correct line # from an exception

Vladimir Sutskever vs667 at nyu.edu
Fri Mar 3 19:32:42 PST 2006


Dear Mark,

You can add the additional newline() function into your lexer rule, that 
fixed it for me. Below is my grammar for white space.

//========================================================[WHITE SPACE]
WS   
    :    (SPACE
    |    '\t'
    |    '\n'
    |    '\r')
        {
            $setType(Token.SKIP);
            newline();
        }
    ;

Hope This Helps
Vladimir Sutskever

Mark Felzer wrote:
> Dear Friends,
>
> When my grammar contains an illegal token an exception is properly thrown
> The exceptions message seems to always indicate the line # as being 
> "1" which is sorta useless when it comes to debugging,
>
> My grammar indicates that "\n\r" should be skipped by the lexer, 
> should I increment something each time "\n\r" is encountered so that 
> the exception translates to the correct line?
>
>
> Thank You Very Much,
> Mark F.
>


More information about the antlr-interest mailing list