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

Alexey Demakov demakov at ispras.ru
Mon Oct 3 04:40:07 PDT 2005


Hi Daniel,

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.
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 );
  }
;

Hope it will work :)

Regards,
Alexey

-----
Alexey Demakov
TreeDL: Tree Description Language: http://treedl.sourceforge.net
RedVerst Group: http://www.unitesk.com



----- Original Message ----- 
From: "Daniel Zuberbuehler" <dzubi at users.sourceforge.net>
To: <antlr-interest at antlr.org>
Sent: Monday, October 03, 2005 3:24 PM
Subject: Re: [antlr-interest] How to read line/col from testLiteralsTable() ?


> Hi
>
> too bad I've got no feedback for my problem. However I've found a solution, I
> just call super.makeToken() myself and query the instantiated token for it's
> line/column values. I belief this should have no sideeffects, but it seems
> not very elegant to me to instantiate a token just to access the line/col
> values. So if anyone knows a direct way to access these values, I'd
> appreciate to hear from you.
>
> Cheers, Daniel
>
>
> On Friday 30 September 2005 23:21, Daniel Zuberbuehler wrote:
> > Hi
> >
> > I want to call a method every time the lexer matches a token in the literal
> > table. So I override the testLiteralsTable() method. I first call
> > super.testLiteralsTable() and check, if it was a match. If so, I call my
> > method.
> > But for that method call, I need the line and col value of the keyword.
> > Unfourtunately I see in the source of the generated lexer that makeToken()
> > is called after testLiteralsTable(), so I can't query the token for those
> > values. I also can't read the tokenStartColumn/tokenStartLine fields of the
> > inputstate, as those are protected, and the CharScanner offers no methods
> > to access those fields.
> > Is there any way to get those values? Or do you see a better approach?
> >
> > Thanks and cheers,
> > Daniel Zuberbühler
>
>




More information about the antlr-interest mailing list