[antlr-interest] Write comments to templates

Jared Bunting jared.bunting at peachjean.com
Sat Nov 22 20:34:47 PST 2008

Not sure if it will meet your needs or not, but you might want to look at
the rewrite functionality.  It should allow you to use your source file as a
starting point, and replace code in it with your template output.  By
ignoring comments in your parser, I would think the rewrite would simply
leave those where they are.


On Sat, Nov 22, 2008 at 12:39 PM, Chris Sekszczynska <
Development at chrissek.de> wrote:

> Hi all,
> after a longer search, I don't found a good way  to write comments from the
> source file to template output. My workflow is the following:
> Lexer (which puts comments into the hidden channel) -> parser (which
> creates an AST) -> walker (which writes output using StringTemplate)
> Now I like to write all comments occurring in the source file to the
> (nearly) same position in the destination file. So I have to pass the
> comments to the walker. Of cause, I could simply put the comments into the
> default token stream and add "Comment?" to *every* position in *every*rule. This will make my parser and walker grammars unreadable.
> Isn't there a better solution? Is it, for example, possible to scan the
> token stream parallel while the AST is parsed? So it could be possible to
> write comments to the StringTemplate output just after they appear in the
> input stream at the nearly same position (using token.index).
> I know, that it is not quite clear where to put comments occurring in the
> input stream. But it's not so important to keep the context. It's more
> important to write the comments more or less to the same position.
> Thanks for your help in advance.
> Kind regards,
> Chris
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081122/e25c6864/attachment.html 

More information about the antlr-interest mailing list