Megaparsec parser of CSV files that plays nicely with Cassava
|Version on this page:||0.1.0@rev:4|
|LTS Haskell 20.23:||2.0.4@rev:1|
|Stackage Nightly 2023-05-30:||2.0.4@rev:1|
|Latest on Hackage:||2.0.4@rev:1|
Module documentation for 0.1.0
The package provides alternative parser for the Cassava package written with Megaparsec so you can get better error messages at expense of some speed.
The package works seamlessly with Cassava by replacing the following functions:
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
This should be enough to start using the package, please consult Haddocks for detailed per-function documentation.
Copyright © 2016 Stack Builders
Distributed under MIT license.
Cassava Megaparsec 0.1.0
- Initial release.