[antlr-interest] partial tree rewrites

Benoit Fouletier benblo+ANTLR at gmail.com
Thu Jul 16 13:30:24 PDT 2009


On Thu, Jul 16, 2009 at 9:53 PM, Gavin Lambert <antlr at mirality.co.nz> wrote:

> At 02:10 17/07/2009, Benoit Fouletier wrote:
>
>> (VAR ID -> VAR ID)
>> (
>> ASSIGN INT
>> ->COLON TYPE["int"] ASSIGN INT
>> |ASSIGN StringValue
>> ->COLON TYPE["string"] ASSIGN StringValue
>> )
>>
>> Do I have the syntax wrong, or are partial rewrites simply not possible?
>>
>
> A rewrite always sets the output of the entire rule.  You cannot use it for
> only part of the rule.  This is important for iterative rules which need to
> build up a nested chain of nodes.
>

Ah, makes sense!


> (A workaround is to move the bit that you want to do a partial rewrite for
> into a subrule.)
>

Thanks I'll do that. It's simple and maybe even more elegant than the syntax
I had in mind.
BTW, should I mark these kind of subrule as fragments? I don't really get
when to use fragment.

Anyway thanks!

        Ben
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090716/16c7a5b4/attachment.html 


More information about the antlr-interest mailing list