[antlr-interest] How to parse Several Option in one group in dífferent order

Richard Clark rdclark at gmail.com
Thu Aug 2 20:33:17 PDT 2007


On 8/1/07, Martin Kortmann <email at kortmann.de> wrote:

> This option can occur in any order, but only zero or
> one times.
[snip]
> How can i made this rule easier? Does i have to track
> this by hand?

Yes, you have to track this by hand. You could do something like this:

header returns [Set options}
@init { $options = new HashSet(); }
 : ( ( t=project | t =no_version)
     { if ($options.contains($t.text) ...
        /* Signal an error, probably w/ an exception */
       else $options.add($t.text)
     }
    )*
    ;

 ...Richard


More information about the antlr-interest mailing list