[antlr-interest] Rewriting in non tree grammar

Terence Parr parrt at cs.usfca.edu
Fri Feb 27 08:23:21 PST 2009


On Feb 27, 2009, at 12:43 AM, Indhu Bharathi wrote:

> Figured it out :-) Here is a sample grammar that does what is  
> required:
>
> grammar Test;
>
> @members {
> 	TokenRewriteStream input = (TokenRewriteStream) getTokenStream();
> }
>
> r
> @init {
> 	int pos;
> }
> 	:	a { pos = input.index(); } b
> 		{
> 			input.insertBefore(pos, "inserted");
> 		}
> 	;

$a.start.getTokenIndex() is better than relying on index probably.
Ter


More information about the antlr-interest mailing list