[antlr-interest] StringTemplate + preserving comments

sohail at taggedtype.net sohail at taggedtype.net
Tue Nov 8 11:30:22 PST 2005


> On Nov 8, 2005, at 10:00 AM, sohail at taggedtype.net wrote:
>>> Sohail Somani wrote:
>>>
>>>> I think the subject line is basically impossible with antlr
>>>> +stringtemplate, BUT in the off-chance someone has any ideas to
>>>> do this,
>>>> I would appreciate some pointers.
>>>>
>>>> It would be really nice if one could do it without a TreeParser :)
>>>>
>>> Hi
>>> I don't know much about Stringtemplate, but if you want to preserve
>>> comments,
>>> you could use a tokenstreamhiddentoken filter after pasrsing, see
>>> http://www.antlr.org/doc/streams.html
>>
>> Hi Ed!
>>
>> I am aware of this technique. I would ideally like the separation that
>> StringTemplate provides. This is a bit difficult because (I think) it
>> would require me to insert <comment>'s between every tag in my
>> template. I
>> should probably sign up for the stringtemplate ml now.
>
> Howdy.  For tweaking or augmenting input, ANTLR +
> TokenStreamRewriteEngine is pretty damn hard to beat. :)  That said,
> I'm hoping to learn how to build a pretty printer in the new few
> months as a way to test new v3 functionality.  As you say, preserving
> the comments in this scenario is pretty tough.  I will have to think
> about how to solve that.  Naturally ANTLR has all the info, the
> problem may be simply to assume that any token you insert into the
> template also includes any hidden tokens before it.  Heh, that might
> work :)  In v2 or v3, I think you can just alter Token.toString() to
> print hidden stuff before the token as well.  easy :) Damn!  That
> might work!

Exciting! I'll give that a shot when I get home tonight.


More information about the antlr-interest mailing list