cassava-megaparsec: Megaparsec parser of CSV files that plays nicely with Cassava

[ csv, library, mit, parsing, text, web ] [ Propose Tags ] [ Report a vulnerability ]

Megaparsec parser of CSV files that plays nicely with Cassava.


[Skip to Readme]

Flags

Manual Flags

NameDescriptionDefault
dev

Turn on development settings.

Disabled

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

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0, 1.0.0, 2.0.0, 2.0.1, 2.0.2, 2.0.3, 2.0.4, 2.1.0, 2.1.1
Change log CHANGELOG.md
Dependencies base (>=4.10 && <5.0), bytestring (>=0.9 && <0.13), cassava (>=0.4.2 && <0.6), megaparsec (>=7.0 && <10.0), unordered-containers (>=0.2.7 && <0.3), vector (>=0.11 && <0.14) [details]
Tested with ghc ==9.8.1, ghc ==9.6.3, ghc ==9.4.4, ghc ==9.2.5, ghc ==9.0.2, ghc ==8.10.7, ghc ==8.8.4, ghc ==8.6.5, ghc ==8.4.4, ghc ==8.2.2
License MIT
Author Mark Karpov <markkarpov92@gmail.org>
Maintainer Mark Karpov <markkarpov92@gmail.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 by wild_willy at 2024-02-28T22:05:52Z
Distributions Arch:2.1.1, Debian:2.0.1, Fedora:2.0.4, LTSHaskell:2.1.1, NixOS:2.0.4, Stackage:2.1.1, openSUSE:2.0.4
Reverse Dependencies 2 direct, 7 indirect [details]
Downloads 8591 total (96 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2024-02-28 [all 1 reports]

Readme for cassava-megaparsec-2.1.1

[back to package description]

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):

Mark Karpov
Mark Karpov

💻
William R. Arellano
William R. Arellano

💻
Cristhian Motoche
Cristhian Motoche

💻
Andrés Martínez
Andrés Martínez

💻
ˌbodʲɪˈɡrʲim
ˌbodʲɪˈɡrʲim

💻
Felix Yan
Felix Yan

💻
Jorge Guerra Landázuri
Jorge Guerra Landázuri

💻
Justin S. Leitgeb
Justin S. Leitgeb

💻

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

License

MIT, see the LICENSE file.

Contributing

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.


Stack Builders
Check out our libraries | Join our team