[stringtemplate-interest] Re: [antlr-interest] StringTemplate + preserving comments

Sohail Somani sohail at taggedtype.net
Tue Nov 8 21:51:24 PST 2005


On Tue, 2005-08-11 at 21:40 -0800, Terence Parr wrote:
> On Nov 8, 2005, at 9:35 PM, Sohail Somani wrote:
> > A problem I'm having is that getHiddenBefore() becomes null when its
> > time to print it out (getText()).
> 
> really?  Hmm...it should always point at the hidden stuff in front.   
> Perhaps you are not setting the right token into the ST attribute.   
> For example, if a comment is between a '{' and an ID, then the ID  
> must go into the stringtemplate so that it can print itself out with  
> the comment before.

This is quite possible. The language I'm parsing is very whitespace
happy (sometimes!). No this was not fun to parse. So it could be that
the lexer passes:

COMMENT EOL SOME_THING

And of course when I try to print the text of SOME_THING, there is no
hidden before.

Any suggestions?

Perhaps using tokenrewriteengine would work because that would mean I
could keep track of the index of the last token printed and then print
all hidden things from there till now. But this doesn't sound too fun.

Sohail



More information about the antlr-interest mailing list