sliekens / Txt

A text parsing framework for .NET.
MIT License
2 stars 4 forks source link

Grammar extension: '#rule' lists #7

Closed sliekens closed 9 years ago

sliekens commented 9 years ago

Some syntax specifications make use of a special #rule notation that denotes comma-separate lists.

Example grammar:

             digits   =   #DIGIT
at-least-one-digits   =   1#DIGIT
 at-most-ten-digits   =   #10DIGIT
  one-to-ten-digits   =   1#10DIGIT

Possible matches:

""
"1, 2, 3"
"4, 5, 6, 7"
"8, 9"
"1, 2, 3, 4, 5, 6, 7, 8, 9"

Some specifications take this even further by allowing empty list items, or multiple white spaces.

"   "
"1,,, 2, 3"
"4,   5, , 6, 7 ,"
"8   ,   9"
"1,  2,3,4, 5 , 6,, 7,  8  ,,9"

I think support for CSV would be nice to have, even though it is not part of ABNF.

sliekens commented 9 years ago

One problem with these CSV rules is that the lower and upper bounds have to be hard-coded. ABNF is just not flexible enough.