people have asked for a "match any of these but only once each" construct.  We 
only have * or + loops.  I need it myself now in antlr.  I have

prequelConstructs
        :       (       ^(o+=OPTIONS .*)
                |       ^(i+=IMPORT .*)
                |       ^(t+=TOKENS .*)
                )*
                {BasicSemanticChecks.checkNumPrequels(gtype, $o, $i, $t);}
        ;

and then i check the count in support code.  Ugly but gets a good message.  
Here is current output

error(20): U.g:10:0: repeated grammar prequel spec (option, token, or import); 
please merge
error(20): U.g:9:0: repeated grammar prequel spec (option, token, or import); 
please merge
error(48): U.g:3:10: illegal option foo
error(26): U.g:6:1: token names must start with an uppercase letter: f
error(48): U.g:10:10: illegal option x
error(48): U.g:13:10: illegal option blech
error(48): U.g:17:16: illegal option ick
error(48): U.g:19:16: illegal option x

from

parser grammar U;

options { foo=bar; k=*; backtrack=true;}

tokens {
        f='fkj';
        S = 'a';
}
tokens { A; }
options { x=y; }

a
options { blech=bar; greedy=true; }
        :       ID
        ;

b : ( options { ick=bar; greedy=true; } : ID )+ ;

c : ID<blue> ID<x=y> ;

Should I think about a (...)^[1] construct or something for v4?

Ter
_______________________________________________
antlr-dev mailing list
[email protected]
http://www.antlr.org/mailman/listinfo/antlr-dev

Reply via email to