Idiomatic Parcoom (educational parser combinators library)

I really enjoy using parser combinators libraries, such as Angstrom. I use it in my Rpmfile library, and it’s very clean and expressive. My love for these started with an Tsoding’s old stream about a dead simple parser combinator library called Parcoom. This streak was the clearest explanation of the topic that I’ve ever seen. Since then, a lot of time has passed, but I decided to rewrite Parcoom’s original OCaml code in a more idiomatic implementation while preserving the original concept.

The result of my work you can find at GitHub - dx3mod/parcoom: Parser combinators library.

# #require "parcoom";;

# let open Parcoom in
  parse (char 'h' <*> any_char) "hello";;
- : _ * (char * char, _) result = ("llo", Ok ('h', 'e'))
2 Likes

Parser combinators are cool because they blend the classical separation of lexing and parsing. This makes them well suited to parse binary formants - which is difficult with a Lex/Yacc approach. But they also come at a cost: potentially a lot of backtracking and ambiguity. How does your library deal with this and do you have any performance numbers? Angstrom claims to be high performance but I have not seen a performance comparison.

1 Like