robrix / Madness

Recursive Descent Into Madness
MIT License
291 stars 17 forks source link

Convenience for separator-delimited sequences #56

Closed robrix closed 8 years ago

robrix commented 9 years ago

It’s super easy to parse e.g. (element + terminator) sequences:

(x ++ %";")*

But it’s a bit obnoxious to parse separator-delimited ones:

x ++ (%"," ++ x)* --> { [ $0 ] + $1 }

That’s a common, useful pattern, so it should be convenient, e.g.:

join(%", ", x) // overloading `join` is semantically reasonable but a bit strange
x * %"," // not a big fan of overloading * like this, and I don’t want to add too many more operators
bencochran commented 8 years ago

sepBy and sepBy1 added in 94b7985092b370d65768c627593e75c89255a76d

(as I discovered after writing what turned out to be the same implementation… yay confirmation)

robrix commented 8 years ago

Whoops! Good catch.