Hi All
I have the following rule in a tree grammar (BTW, rewrite = true
here). Both AS_TEXT and AS_NAME are imaginary tokens.
text_block
: ^(AS_TEXT text_option* name? phrase+ )
-> ?????
;
what I want for the ????? part is the rewrite
^(AS_TEXT name phrase+)
if the optional name was present in the input tree, and
^(AS_TEXT { <generated-name> } phrase+)
if no name was present in the input tree. One variant I tried was
text_block
: ^(AS_TEXT text_option* name? phrase+ )
-> ^(AS_TEXT { ($name.tree == null) ? pm.generateName() :
$name.tree } phrase+)
;
where pm is a helper class instance and generateName looks like
CommonTree generateName() {
String name = ....
return new CommonTree( new CommonToken(AS_NAME, name) );
}
First question is, is this a good approach to "filling in a blank" in
a rewritten tree? If not, please advise. If so, I'll post another
message showing what I did and the null pointer exception that results.
Thanks in advance!
.bill
Bill Andersen
Ontology Works, Inc. (www.ontologyworks.com)
3600 O'Donnell Street, Suite 600
Baltimore, MD 21224
Office: +1.410.675.1201
Cell: +1.443.858.6444
Fax: +1.410.675.1204
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---