J-F-Liu / pom

PEG parser combinators using operator overloading without macros.
MIT License
496 stars 30 forks source link

Add example parsing ISO 8601 duration #24

Closed JoshMcguigan closed 5 years ago

JoshMcguigan commented 5 years ago

Inspired by this comparison of Nom, Combine, and Pest, I wrote an example parser for the ISO 8601 duration format using pom.

I'd welcome any feedback you have to improve this parser. In particular, I don't like the map statement required to flatten the tuples after chaining multiple parsers with + in the date_part and time_part functions.

Generally, I really enjoy working with pom. Thanks for your work on it!

J-F-Liu commented 5 years ago

Thanks, this is a very good example. I find no better alternative to flatten tuples.

JoshMcguigan commented 5 years ago

Thanks for the merge.

On the topic of flattening the tuples, this combine example demonstrates what I think is a nice approach to combining parsers which avoids the need to flatten tuples all together. It also handles the +, -, and * use cases without having to remember which one is which.

If you have any interest / could provide guidance on bringing something like this to pom, I'd be happy to work on it.