[antlr-interest] Rewrite separators to root nodes.
Gavin Lambert
antlr at mirality.co.nz
Mon Aug 4 03:00:30 PDT 2008
At 21:44 4/08/2008, craig at palantir.co.za wrote:
>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*)
It might be possible to do that, but it'd be much easier to
generate a slightly different structure. If you change the
'rules' rule to this:
rules: rule (('and'|'or')^ rule)*;
It will produce trees that can be matched like this:
rules
: ^('or' a=rules b=rules)
| ^('and' a=rules b=rules)
| rule
;
rule
: ^(ROOT xname*)
;
I think that's much easier to deal with :)
More information about the antlr-interest
mailing list