Choosing a Haskell parser

You have several good options.

For lightweight parsing of String types:

  • parsec
  • polyparse

For packed bytestring parsing, e.g. of HTTP headers.

  • attoparsec

For actual binary data most people use either:

  • binary — for lazy binary parsing
  • cereal — for strict binary parsing

The main question to ask yourself is what is the underlying string type?

  • String?
  • bytestring (strict)?
  • bytestring (lazy)?
  • unicode text

That decision largely determines which parser toolset you’ll use.

The second question to ask is: do I already have a grammar for the data type? If so, I can just use happy

  • The Happy parser generator

And obviously for custom data types there are a variety of good existing parsers:

  • XML
    • haxml
    • xml-light
    • hxt
    • hexpat
  • CSV
    • bytestring-csv
    • csv
  • JSON
    • json
  • rss/atom
    • feed

Leave a Comment

tech