Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Current »

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);}
    ;
  • No labels