[antlr-interest] Antlr regex support for {min,max}

Eric Crampton ccesc at eonomine.com
Sun Oct 9 21:22:07 PDT 2005


Does Antlr provide a way to match a range of occurrences of a literal  
in a lexer? For example, in a modern egrep implementation, you can do:

   a[0-9]{2}c

which will match 'a' followed by exactly 2 digits followed by 'c'.

   a[0-9]{2,3}c

would match 'a' followed by 2 or 3 digits followed by 'c'. Any way to  
do that in Antlr? I know the second one could be written like so:

   a[0-9][0-9][0-9]?c

but the grammar I'm writing has a lot of occurrences of this and with  
more complicated Antlr expressions like ('0'..'9'). Repeating these  
everywhere makes the grammar very hard to follow and near as I can  
tell, Antlr doesn't provide the {min,max} construct.

Yeah, this is something pretty wacky I'm trying to parse. :-)  Might  
end up hand-coding it, but I'd rather avoid that.

Thanks,
--Eric





More information about the antlr-interest mailing list