[antlr-interest] [v3] Rule references in rewrite rules?
David Holroyd
dave at badgers-in-foil.co.uk
Wed Sep 20 15:41:36 PDT 2006
On Mon, Aug 21, 2006 at 12:55:24PM +0000, David Holroyd wrote:
> Should the following do what I think it should..?
>
> compilationUnit:
> 'package' packageBlock -> ^(COMPILATION_UNIT $compilationUnit)
> ;
>
> I was expecting this to give me a result tree which looks like,
>
> #( COMPILATION_UNIT 'package' ..etc.. )
>
> but instead I just get,
>
> #( COMPILATION_UNIT )
>
>
> Is my syntax wrong, or is $compilationUnit not actually a reference to
> the entire pre-rewrite tree for the compilationUnit rule? (I can't
> remember where I read that it should be, any more.)
To answer my own question for the record:
I think that the issue is that $rulename is assigned the result of the
last rewrite which executed in the current rule, and before that it is
empty.
So, $rulename can't be used as a shorthand for the default tree for the
l.h.s., as I had for some reason hoped.
ta,
dave
--
http://david.holroyd.me.uk/
More information about the antlr-interest
mailing list