[antlr-interest] Rewrite rule and optional parts
Martin Probst
mail at martin-probst.com
Fri Oct 2 05:34:47 PDT 2009
Hi,
I have a rewrite rule like this:
rule: FOO (BAR baz)? BAM -> ^(FOO (^BAR baz BAM)? BAM);
For more generality, I'd like to include the BAM twice in the tree.
Believe me, that actually makes sense when the names are not BAM and
BAZ ;-)
The problem is that ANTLR generates this code:
if ( stream_BAR.hasNext()||stream_baz.hasNext()||stream_BAM.hasNext() ) {
// construct optional tree part, causes EmptyRewriteStream exception
if BAR doesn't exist
}
Is there any particular reason why that is a disjunction and not a
conjunction? I.e., for the tree construction part not to cause errors,
you need all of the nodes present, not one of them.
Thanks,
Martin
More information about the antlr-interest
mailing list