[antlr-interest] Preserve source code comments
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
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
This is what hidden channels are for :)
That would work.
How do I recover the current token index? Mmm. this.input.index() ?
More information about the antlr-interest