Parser Combinators: How to Parse (nearly) Anything

Reference: Parser Combinators: How to Parse (nearly) Anything

This is the best video I've ever seen defining monadic parser combinators from the ground up. Nate Young explains his translation of Parsec into Clojure^1. I'm surprised he could show the code and explain it well in less than forty-five minutes.

As you may know, I have my own PEG parser combinator library called squarepeg. I began developing it as monadic, but decided that I didn't like having to write my own version of Haskell's do notation (let->> in his version), which felt awkward in Clojure. Instead, squarepeg lets you bind variables and refer to them later within each parser itself (instead of in the code that builds the parser). There were a few other differences, but in general, I think the two libraries are more similar than different.

One thing I think I will borrow from his library is counting the character position of the current parser to help report parsing errors. It's going on my TODO list.

I have more plans for squarepeg when I get a chance. They include limiting the laziness of the parser and being able to report better error messages.

Update The kindly Sergey Pariev clued me into the github repo of The Parsatron.

  1. Nate said his parser was available on Clojars under the name "The Parsitron", but I could not find it.