[antlr-interest] specific number of repetitions

Johannes Luber jaluber at gmx.de
Sun Mar 11 09:44:21 PDT 2007


Brian Lewis wrote:
> I want to parse something that looks like
> 4:abcd5:12345
> 
> so I want to code something like
> field:
>   n=integer ':' ('a'..'z' | '0'..'9'){n}
> 
> to read exactly n characters after the :. I don't know how to do it,
> though. Is there a way?
> 

I don't know a way, where one can directly specify the number of
repetitions (I believe that there is none), but you can do something
like that:

Alphanum:
   ('a'..'z' | '0'..'9');

field:
	Alphanum ':' Alphanum Alphanum Alphanum Alphanum Alphanum ':' Alphanum
Alphanum Alphanum Alphanum Alphanum
;

I supppose that using extra rules for each part makes assinging a label
easier.

Best regards,
Johannes Luber


More information about the antlr-interest mailing list