[antlr-interest] Preserving comments

Andy Tripp antlr at jazillian.com
Thu Aug 14 15:29:38 PDT 2008


It's very difficult, in practice, to associate comments with code.
A comment may "go with" code that's above it, below it, left or right of it.
It has a lot do do with how people perceive whitespace.
Peter Ahe at Sun wrote a good paper on the subject years ago.

I wrote some pretty involved heuristics to try to figure out what
comments "go with" certain code. 

I have the ANTLR lexer preserve the comments and whitespace and then my own processor
analyses them before stripping them out of the stream of tokens.
But to attach comments to individual AST nodes doesn't work well if the AST changes a lot.

Andy

Vitaliy wrote:
 
> But failed to find a good-enough way to preserve comments.


More information about the antlr-interest mailing list