MIT licensed and maintained by Mark Karpov
This version can be pinned in stack with:cassava-megaparsec-2.1.1@sha256:8afa1f9313cf1ed4d0ab4e193387ce80a7c225cea672b04ab83cc5009c9fb8fd,2618

Module documentation for 2.1.1

Used by 1 package in nightly-2024-06-22(full list with versions):

Cassava Megaparsec

All Contributors

License MIT Hackage Stackage Nightly Stackage LTS Build Status

The package provides alternative parser for the Cassava package written with Megaparsec so you can get better error messages at expense of some speed.

Quick start

The package works seamlessly with Cassava by replacing the following functions:

  • decode
  • decodeWith
  • decodeByName
  • decodeByNameWith

The functions work just the same as Cassava’s equivalents, but also take name of file they parse (to include into error messages) and return typed high-quality error messages produced by Megaparsec.

The import section typically looks like this:

import Data.Csv hiding (decode, decodeWith, decodeByName, decodeByNameWith)
import Data.Csv.Parser.Megaparsec (decode, decodeWith, decodeByName, decodeByNameWith)

Next you call appropriate function and get either result of parsing identical to that of Cassava or error message. The error message is well-typed so you can examine it in Haskell code easily. Conversion error are considered parsing errors by the cassava-megaparsec package and are reported via custom error message component Cec supported by Megaparsec 5. Since Cassava’s conversion errors are plain strings, we have no choice but to represent them as strings too:

-- | Custom error component for CSV parsing. It allows typed reporting of
-- conversion errors.

data Cec
  = CecFail String
  | CecIndentation Ordering Pos Pos
  | CecConversionError String
  deriving (Eq, Data, Typeable, Ord, Read, Show)

To pretty print a error message use the parseErrorPretty function from Text.Megaparsec.

This should be enough to start using the package, please consult Haddocks for detailed per-function documentation.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!


MIT, see the LICENSE file.


Do you want to contribute to this project? Please take a look at our contributing guideline to know how you can help us build it.

Check out our libraries | Join our team


Cassava Megaparsec 2.1.0

  • Drop support for GHC 8.0 and below

Cassava Megaparsec 2.0.4

  • Allow bytestring-0.11

Cassava Megaparsec 2.0.3

  • Exposing Internals

Cassava Megaparsec 2.0.2

  • Add suppport for megaparsec-9.0.0

Cassava Megaparsec 2.0.1

  • Add suppport for megaparsec-8.0.0

Cassava Megaparsec 2.0.0

  • Works with Megaparsec 7.

Cassava Megaparsec 1.0.0

  • Works with Megaparsec 6.

  • Instead of Cec we have ConversionError as custom component of error messages.

Cassava Megaparsec 0.1.0

  • Initial release.