[antlr-interest] Preserving comments

Vitaliy Vitaliy at dbsophic.com
Sun Aug 17 12:26:43 PDT 2008


Hi guys,

Thanks so much for all the suggestions.
I see now that I have no choice, but to go with comment granularity level of a rule -
That is I'll associate all the comments that appear inside some rule with that rule in general.

When translated, this will move the comments from their original location to the end of the rule -
Also I'll have to deal with the association in each rule separately,
But I don't see any better solution from the discussion.

Anyway, thanks for your efforts,
Vitaliy

-----Original Message-----
From: Andy Tripp [mailto:antlr at jazillian.com]
Sent: Friday, August 15, 2008 00:30
To: Vitaliy
Cc: antlr-interest at antlr.org
Subject: Re: [antlr-interest] Preserving comments

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.





__________ Information from ESET NOD32 Antivirus, version of virus signature database 3361 (20080816) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com



__________ Information from ESET NOD32 Antivirus, version of virus signature database 3362 (20080817) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com



More information about the antlr-interest mailing list