[antlr-interest] How to read line/col from testLiteralsTable() ?

Daniel Zuberbuehler dzubi at users.sourceforge.net
Mon Oct 3 13:38:36 PDT 2005


Hi Alexey

> You can try other solutions:
> 1. Lexer takes line/column from input state. Unfortunately,
> LexerSharedInputState doesn't have observers for these fields.
> But you can make your own subclass of LexerSharedInputState
> and pass it to Lexer in constructor.

I didn't realized that I could set my own LexerSharedInputState. This surely 
is the cleanest solution for my problem

> 2. If you know tokens where literals are tested,
> you can set testLiterals = false and make token action
> where inputState field are accessed:
>
> ID :
>   ( LETTER | UNDERSCORE )
>   ( LETTER | UNDERSCORE | DIGIT )*
>   {
>
>     int line = inputState.line;
>     int column = inputState.column;
>     _ttype = testLiteralsTable( _ttype );
>   }
> ;
>

Wow, you're great! You just showed me the solution for another problem I had!

Thanks a lot for your help!

Cheers, Daniel


More information about the antlr-interest mailing list