On Wed, 2011-02-16 at 15:21 -0700, Alan Post wrote:
> EBNF has an operator that allows a match to be done at least n times
> and at most m times.  Have any of you added something like this to
> your parsers?

I used the bracket syntax from regexes:

A{M,N}

Where M and N are integers and either is optional.

If N is omitted, it defaults to infinity.
If M is omitted, it defaults to zero.
If only one integer is present and the comma is omitted, it matches an
exact number of times, i.e. A{M} is equivalent to A{M,M}.

Before any further processing is done these are decomposed into some
combination of explicit repetitions of the subexpression, followed by
optional repetitions, followed by *-operator if N was omitted, e.g.

A{2,3} becomes A A A?
A{2,} becomes A A A*
A{2} becomes A A
A{,} becomes A*


_______________________________________________
PEG mailing list
PEG@lists.csail.mit.edu
https://lists.csail.mit.edu/mailman/listinfo/peg

Reply via email to