[antlr-interest] Default values in tree rewrite rules
Emond Papegaaij
e.papegaaij at student.utwente.nl
Fri Aug 11 09:22:35 PDT 2006
Hello,
I've got the following parser rule in which 'superclass' is optional:
nodeDecl
: (options {k = 1;} : (nodeNames ':')=> bindings=nodeNames ':')?
(declAbstract=ABSTRACT)?
type=targetClass
('extends' superclass=targetClass)?
( CBR_OPEN body CBR_CLOSE | SEMI )
-> ^(NODE_SPEC $type $declAbstract? $superclass? body? $bindings?)
;
Now I want superclass to become the tree ^(TYPE["Node"]) when it is not
defined in the input (and it will no longer be optional in the rewrite
rule). Is this possible? All I've come up with is:
('extends' superclass=targetClass)? {
if (superclass == null) {
superclass = new targetClass_return();
superclass.tree = adaptor.create(TYPE, "Node");
}
}
Which is quite nasty.
Best regards,
Emond
More information about the antlr-interest
mailing list