[antlr-interest] Returning subrule string template by default
Damien Cassou
damien.cassou at gmail.com
Thu Jun 11 05:41:11 PDT 2009
Hi,
I have a tree grammar which looks like:
document :
^(DOCUMENT (type_def {templates.add($type_def.st);})*)
;
type_def:
struct | enum | foo | ... | bar
;
where struct, enum, foo, bar and the other are rules which return
string templates.
This doesn't work because the type_def rule doesn't return the string
template returned by the subrules.
I tried other things like the following:
type_def: a=(struct | enum |...) {templates.add($a.st);}
type_def: (a=struct | a=enum | ...) {templates.add($a.st);}
type_def @init {templates.add($type_def.st);}
: struct | enum | ...;
None of them work. The only solution I found was to duplicate the
action on all subrules.
--
Damien Cassou
http://damiencassou.seasidehosting.st
"Lambdas are relegated to relative obscurity until Java makes them
popular by not having them." James Iry
More information about the antlr-interest
mailing list