2010/3/12 Marcin Rzeźnicki <[email protected]>

> Hi
> I've got an awkward question. How can I return an array from rule?
> "rule_name returns [Object[] sth] " obviously does not work because syntax
> checker thinks that closing bracket of Object[] closes returns. I could not
> find anywhere how to escape it. Thx for any 
> help.<http://www.antlr.org/mailman/options/antlr-interest/your-email-address>
>

This message from 2007 indicates it is not possible to have nested brackets
inside "rule return statements":
http://www.antlr.org/pipermail/antlr-interest/2007-March/019712.html
and AFAIK, this still is not possible.

You will have to do something like:

@parser::members {

  class Wrapper {

    String[] array;

    Wrapper(String[] a) {
      array = a;
    }
  }

}

parse
  :  rule {String s = $rule.wrapper.array[2];}
  ;

rule returns [Wrapper wrapper]
  :  ... {$wrapper = new Wrapper(new String[]{"a", "b", "c"});}
  ;


Regards,

Bart.

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.

Reply via email to