[antlr-interest] TokenRewriteStream and lexical filters

Terence Parr parrt at cs.usfca.edu
Thu Dec 7 12:20:12 PST 2006


On Dec 7, 2006, at 10:15 AM, Jose San Leandro wrote:

> Hi all,
>
> I'm trying to define a lexer that, from a Java source, is able to  
> provide the
> same source with small modifications (initially, just modifications in
> the 'extends' and 'implements' clauses).
> I started from FuzzyJava example, since I want to avoid checking  
> source
> correctness (just digest anything and manage only the class  
> declarations of
> the source).
> As long as I know, to use TokenRewriteStream I'll need a parser. So  
> far, I
> only have the lexer, and don't know what the parser will be like.  
> How can I
> make use of both lexical filters and TokenRewriteStream?

Good question.  I do something like this for a translator using  
filter mode:

/*
@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);}
     ;

Ter



More information about the antlr-interest mailing list