[antlr-interest] Rewrite separators to root nodes.

craig at palantir.co.za craig at palantir.co.za
Mon Aug 4 02:44:28 PDT 2008


Hi,

I am struggling to rewrite a tree with the separator (and/or in this case) to
come before the rules in the output tree.
I can do it by making root nodes out of the separator but that's not really what
I want. I then have a deep tree that is less practical.

Given the following two productions:
rules:	rule (('and'|'or') rule)*
                ;
rule
:	ROOT xn+=xname (':' xn+=xname)+
	-> ^(ROOT xname*);

I want to use tree rewrites to produce a tree that matches what i have below.

rule:    ^(ROOT 'and' xname*)
        |^(ROOT 'or' xname*)
        |^(ROOT xname*)

At the moment my tree looks like this. This doesn't match properly.
rule:    ^(ROOT *xname 'and') | ^(ROOT xname* 'or') | ^(ROOT xname*);

Unfortunately only the last match is ever made the and/or is not matched in the
tree. By moving them to the front as I have shown above I am pretty sure it
will work.

Does anyone have some pointers?

Regards
Craig.

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.




More information about the antlr-interest mailing list