[antlr-interest] Preserving comments
Martin Probst
mail at martin-probst.com
Thu Aug 14 08:10:41 PDT 2008
Hi,
> Unfortunately the actions must be context sensitive.
>
> What's the best way to tackle this practically?
It's possible to change the TokenStream implementation to link comment
tokens to either the previous or the next token, whatever suits you
best. For that, you'll also need a custom token class. You can then
after parsing walk the AST with a plain old Java program, and do
whatever you need to do.
I've used this technique in my ANTLR parser/pretty printer, see here:
http://code.google.com/p/xqpretty/source/browse/trunk/src/java/com/martinprobst/xqpretty/LazyTokenStream.java
and the 'setHiddenPredecessor' in XQToken.java.
Regards,
Martin
More information about the antlr-interest
mailing list