The cassava-megaparsec package

[ Tags: csv, library, mit, parsing, text, web ] [ Propose Tags ]

Megaparsec parser of CSV files that plays nicely with Cassava.


[Skip to Readme]

Properties

Versions 0.1.0, 1.0.0
Change log CHANGELOG.md
Dependencies base (>=4.7 && <5.0), bytestring (>=0.9 && <0.11), cassava (>=0.4.2 && <0.6), containers (==0.5.*), megaparsec (>=6.0 && <7.0), unordered-containers (>=0.2.7 && <0.3), vector (>=0.11 && <0.13) [details]
License MIT
Author Mark Karpov <markkarpov@openmailbox.org>
Maintainer Mark Karpov <markkarpov@openmailbox.org>
Category Text, Web, CSV, Parsing
Home page https://github.com/stackbuilders/cassava-megaparsec
Bug tracker https://github.com/stackbuilders/cassava-megaparsec/issues
Source repo head: git clone https://github.com/stackbuilders/cassava-megaparsec.git
Uploaded Thu Jul 27 13:49:04 UTC 2017 by mrkkrp
Updated Fri Jan 12 05:41:03 UTC 2018 by mrkkrp to revision 1   [What is this?]
Distributions NixOS:1.0.0
Downloads 1017 total (41 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-07-27 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Flags

NameDescriptionDefaultType
dev

Turn on development settings.

DisabledManual

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

For package maintainers and hackage trustees


Readme for cassava-megaparsec-1.0.0

[back to package description]

Cassava Megaparsec

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.

License

Copyright © 2016–2017 Stack Builders

Distributed under MIT license.