[antlr-interest] Preserving comments
mail at martin-probst.com
Thu Aug 14 08:10:41 PDT 2008
> 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:
and the 'setHiddenPredecessor' in XQToken.java.
More information about the antlr-interest