[antlr-interest] Bounded Closures?

Randall R Schulz rschulz at sonic.net
Mon Jun 25 08:53:24 PDT 2007


Hi,

Am I correct in believing that the only way to notate bounded closure in
ANTLR is by repeated applications of the zero-or-one (a.k.a. optional)
closure notation?

E.g., I have this lexer fragment for handling Unicode escapes:

fragment
UnicodeEscape
  :
  ( '\\' ( 'u' | 'U' )
    ( HexDigit ( HexDigit ( HexDigit ( HexDigit ( HexDigit ( HexDigit ) ? ) ? ) ? ) ? ) ? ) ?
  )
  ;


I'd like to be able to using the usual regular expression notation for
bounded closure for this construct:

fragment
UnicodeEscape
  :
  ( '\\' ( 'u' | 'U' ) HexDigit { 0, 6 } )
  ;



Did I miss this somewhere, or is the verbose notation the only way to
get the effect I need?


Randall Schulz


More information about the antlr-interest mailing list