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

Terence Parr parrt at cs.usfca.edu
Tue Nov 8 21:54:21 PST 2005


On Nov 8, 2005, at 9:51 PM, Sohail Somani wrote:

> 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?

Yes.  Make that IF a WHILE loop to print ALL hidden tokens between  
your token and the previous :)  It chains them all together :)

> 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.

Either way you need a loop to walk back and print the hidden stuff :)

Ter


More information about the antlr-interest mailing list