How do I combine fuzzy parsing and stream rewriting?

If you want to parse just pieces of, say, a Java file using filter mode (fuzzy parsing) and do some replacement like TokenRewriteStream does, how can you do it? TokenRewriteStream requires use of a parser/lexer combo whereas filter=true does everything with the scanner. Just match what you want then include print statements and actions to alter the text. Anything not matched by your rule or rules should be matched by an EVERYTHING_ELSE rule, which simply emits all characters verbatim.

/*
@grammar
...
@@ to
<begin lang="grammar">
...
</end>
*/
GRAMMAR
        :       '@grammar' '\n'
                {out.println("<begin lang=\"grammar\">");}
                CODE_CHUNK
                {out.println("</end>");}
        ;

EVERYTHING_ELSE
    :   c=.             {out.print((char)c);}
    ;