[antlr-interest] rewrite rule element cardinality

joestelmach at gmail.com joestelmach at gmail.com
Tue Feb 23 13:50:57 PST 2010


Thank you for the fast replies.

Terence - I'm not sure if this will help, but here's a portion of the generated parser for rewrite rule ^( GROUP c option )

while ( stream_option.hasNext()||stream_c.hasNext() ) {
  // Test.g:15:26: ^( GROUP c option )
  {
    Object root_1 = (Object)adaptor.nil();
    root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(GROUP, "GROUP"), root_1);

    adaptor.addChild(root_1, stream_c.nextTree());
    adaptor.addChild(root_1, stream_option.nextTree());
    adaptor.addChild(root_0, root_1);
  }
}

When debugging test input "c a b", this code is executed twice (as expected.)  On the first iteration, stream_c.nextTree().children = [FOO, BAR], and stream_option.nextTree().token = BAZ, but on the second iteration, stream_c.nextTree().children already has the BAZ token ([FOO, BAR, BAZ],) and stream_option.nextTree().token=BAZ.

Gavin - referencing the array of options from a label doesn't seem to change anything.  As for your possible workaround, is it valid to reference a parameter directly in a rewrite rule?  I was under the impression that you could only reference rule parameters within target code blocks.

- Joe


More information about the antlr-interest mailing list