[antlr-interest] Need help with rewrite rules

Chrobot, Stefan Stefan.Chrobot at sabre.com
Wed Mar 24 06:54:59 PDT 2010


-----Original Message-----
From: Mark Wright [mailto:markwright at internode.on.net] 
Sent: Wednesday, March 24, 2010 2:32 PM

Hi Stefan,

This is described in chapter 9 (in particular starting at section 9.5
on)
of the ANTLR book (The Definitive ANTLR Reference).  One way that
is described in the book (which is highly recommended) which
would probably be easier for your situation is to use:

options { /* other options you need */
          rewrite = true; }

if this is supported by the ANTLR runtime target you are using,
and whatever the equivalent of TokenRewriteStream is for that
target (it could be called something completely different).

------------------------------------------

Mark,

thanks for the reply. I was looking into the book, but just couldn't
find the way to do, what I wanted.
I was using the technique you mentioned. And I got to this point:

function
	:	ID
		'('
		(
		arg1 = expression
		(',' arg2 = expression
		)*
		)?		
		')'
		-> template() "aaaaa"
	;

This replaces the whole function with the text "aaaaa". But what I
really wanted to do is to get the replacement text from a function call.
Now I know, that what I wanted to do is:

-> { new StringTemplate(myFunction(myParams)) }



More information about the antlr-interest mailing list