A few days ago I wrote my first BNF grammar after already having a parser which implemented it. One section specifies how one can search between two values:
::= 'BETWEEN' '[' value ',' value ']'
| 'BETWEEN' '[' value '=>' value ']'
| '[' value ',' value ']'
| '[' value '=>' value ']'
That's more or less equivalent to the following regex:
The HOP parser, of course, can handle this, but it doesn't handle it as gracefully as I would like, so I extended it.
absorb( optional( match( KEYWORD => 'BETWEEN' ) ) ),
match() is the new name of the old &_ function. absorb() means "match this but throw away the value." optional() means "0 or 1 of the following value."
All things told, this makes things much easier to read and allows us to skip many of the annoying transformations that were required to get rid of of unwanted values.