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.
-Jared On Sat, Nov 22, 2008 at 12:39 PM, Chris Sekszczynska < [EMAIL PROTECTED]> 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:8080/mailman/listinfo/antlr-interest > Unsubscribe: > http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en -~----------~----~----~----~------~----~------~--~---
List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address
