Let's say I've got a tree with a series of nested SPANs with TEXT leaves.
Let's say I want to write a tree grammar that causes SPANs with a
"boo" TEXT child to become a SPAN with a "moo" TEXT child.
rule: ^(SPAN 'boo') -> ^(SPAN 'moo')
That clearly doesn't work, because 'boo' and 'moo' aren't tokens.
So I did the following:
tree grammar Boo2Moo;
options {
ASTLabelType = CommonTree;
tokenVocab = IntermediateTree;
filter = true;
output = AST;
}
bottomup: spantag;
spantag: ^(parent=SPAN e=TEXT) {"boo".equals($e.getText())}?
{adaptor.setChild($parent, 0, adaptor.create(TEXT, "moo"));};
This works. Is there a more elegant way, or is this a reasonable approach?
Thanks,
-Adam
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.