[antlr-interest] Recovering white space in V3.0

Terence Parr parrt at cs.usfca.edu
Sat Jun 4 17:36:56 PDT 2005


On Jun 4, 2005, at 5:25 PM, Matthew Ford wrote:

> Hi Ter,
>
>> Hmm...well, having never actually tried it, you might simply walk
>> backwards from w.getTokenIndex() instead of remembering where you
>> were last time.  The edge case might need something like the token
>>
>
> I don't think walking backwards from the end will do it.
> i) the WS come out in the wrong order
> ii) in need to display WORD  ws ws ws WORD
> not WORD WORD ws ws ws

Oh, right...yeah, I was thinking about buffering, but you're  
right...my thing won't work so easily...I'll have to poke around. :)

>> starts with a MINUS, so you could just avoid going back past that.
>>
> How do you avoid going back pass minus?
> Do you use  something like
> for ( int i = ...  ;  i> $MINUS.getTokenIndex(); i--)

Yep.

> ie. do I understand you that $MINUS is the minus token (assuming  
> MINUS in
> unique in the rule otherwise it is just the last MINUS seen/parsed?)

Yes, you can refer to the toke by $TOKEN_NAME as long as it's unique  
in the alt.  It will always be the last matched, but it must be unique.

Ter




More information about the antlr-interest mailing list