Question

I was reading a lot about Haskell Parser Combinators and found a lot of topics like:

But all these topics compare Parser Combinators with Parser Generators.

I want to ask you which of Parser Combinator suits best the following conditions:

  1. I want to have good control about the errors (including error recovery) and messages for user
  2. I want to be able to fed the parser with small parts of text (not whole file at once)
  3. I want to be able to redesign nicely the grammar (I'm currently developing the grammar, so "nice waf of working" is important"
  4. The final parser should be fast (the performance is important, but not as much as points 1-3).

I've found out, that the most popular parser combinators are:

Was it helpful?

Solution

I would say definitely go with Parsec, heres why:

Attoparsec is designed to be quick to use, but lacks the strong support for error messages you get in Parsec, so that is a win for your first point.

My experience of using parser combinator libraries is that it is really easy to test individual parts of the parsers, either in GHCi or in tests, so the second point is satisfied by all of them really. Lastly, Attoparsec and Parsec are pretty darn fast.

Finally, Parsec has been around longest and has many useful and advanced features. This means that general maintainability is going to be easier, more examples are in Parsec and more people are familiar with it. uu-parsinglib is definitely worth the time to explore, but I would suggest that getting familiar with Parsec first is the better course for these reasons. (Alex is also the most recommended lexer to use with Parsec or otherwise, but I have not used it myself.)

OTHER TIPS

I will post my answer here in case somebody find this question. Current answer is quite outdated.

It's better to use megaparsec package as parser combinator library. It's a modern production-ready library. And its README.md contains excellent comparison with other parser combinators libraries:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top