[antlr-interest] Write comments to templates

Chris Sekszczynska Development at ChrisSek.de
Sat Nov 22 10:39:02 PST 2008


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081122/49d56a56/attachment.html 


More information about the antlr-interest mailing list