[antlr-interest] Preserve source code comments

Stanislas Rusinsky rusinskystanislas at yahoo.fr
Fri Oct 19 03:36:11 PDT 2012


A twisted issue indeed, one I also faced, as the comment handling had to be added after the fact.

We translate 2 million LoC, and the result has to have comment quite near the original position in the translated version.

We developed something in-house that looks backwards and forwards on key nodes, checks nearby comments with precedence rules (checking for newlines, commas, ...) attaches them to the most relevant node and marks comments as processed.

I recommend you to read this blogpost on an implementation: http://meri-stuff.blogspot.be/2012/09/tackling-comments-in-antlr-compiler.html



________________________________
 De : Jim Idle <jimi at temporal-wave.com>
À : 
Cc : antlr-interest at antlr.org 
Envoyé le : Vendredi 19 octobre 2012 6h08
Objet : Re: [antlr-interest] Preserve source code comments
 
It's a thorny problem. Your assumptions (and you have to make some) about
which comment belongs to which piece of code will always get you in to
trouble in the end.

But, as most programmers don’t use comments, perhaps you can ignore the
issue ;)

Jim

-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Juancarlo Añez
Sent: Friday, October 19, 2012 10:53 AM
To: Terence Parr
Cc: antlr-interest at antlr.org
Subject: Re: [antlr-interest] Preserve source code comments

Terrence,

This is what hidden channels are for :)
>
> http://www.antlr.org/wiki/pages/viewpage.action?pageId=557063
>

That would work.

How do I recover the current token index? Mmm. this.input.index() ?

-- 
Juancarlo *Añez*

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address


More information about the antlr-interest mailing list