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

Copyright | © 2016–2021 Stack Builders
License | MIT
Maintainer | Mark Karpov <markkarpov92@gmail.org>
Stability | experimental
Portability | portable
Safe Haskell | None
Language | Haskell2010

Data.Csv.Parser.Megaparsec

Description

A CSV parser. The parser here is RFC 4180 compliant, with the following extensions:

- Non-escaped fields may contain any characters except double-quotes, commas (or generally delimiter characters), carriage returns, and newlines.
- Escaped fields may contain any characters, but double-quotes need to be escaped.

The parser provides better error messages than the parser that comes with Cassava library, while being compatible with the rest of the library.

Synopsis

- newtype ConversionError = ConversionError String
- decode :: FromRecord a => HasHeader -> FilePath -> ByteString -> Either (ParseErrorBundle ByteString ConversionError) (Vector a)
- decodeWith :: FromRecord a => DecodeOptions -> HasHeader -> FilePath -> ByteString -> Either (ParseErrorBundle ByteString ConversionError) (Vector a)
- decodeByName :: FromNamedRecord a => FilePath -> ByteString -> Either (ParseErrorBundle ByteString ConversionError) (Header, Vector a)
- decodeByNameWith :: FromNamedRecord a => DecodeOptions -> FilePath -> ByteString -> Either (ParseErrorBundle ByteString ConversionError) (Header, Vector a)

# Documentation

newtype ConversionError Source #

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

Constructors

ConversionError String |

#### Instances

Instances details

Data ConversionError Source # |

Instance details

Defined in Data.Csv.Parser.Megaparsec.Internals

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ConversionError -> c ConversionError Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c ConversionError Source #

toConstr :: ConversionError -> Constr Source #

dataTypeOf :: ConversionError -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c ConversionError) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ConversionError) Source #

gmapT :: (forall b. Data b => b -> b) -> ConversionError -> ConversionError Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ConversionError -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ConversionError -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> ConversionError -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> ConversionError -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> ConversionError -> m ConversionError Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ConversionError -> m ConversionError Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ConversionError -> m ConversionError Source #

Read ConversionError Source # |
Instance details Defined in Data.Csv.Parser.Megaparsec.Internals Methods readsPrec :: Int -> ReadS ConversionError Source # readList :: ReadS [ConversionError] Source # readPrec :: ReadPrec ConversionError Source # readListPrec :: ReadPrec [ConversionError] Source #
Show ConversionError Source # |
Instance details Defined in Data.Csv.Parser.Megaparsec.Internals Methods showsPrec :: Int -> ConversionError -> ShowS Source # show :: ConversionError -> String Source # showList :: [ConversionError] -> ShowS Source #
Eq ConversionError Source # |
Instance details Defined in Data.Csv.Parser.Megaparsec.Internals Methods (==) :: ConversionError -> ConversionError -> Bool Source # (/=) :: ConversionError -> ConversionError -> Bool Source #
Ord ConversionError Source # |

Instance details

Defined in Data.Csv.Parser.Megaparsec.Internals

Methods

compare :: ConversionError -> ConversionError -> Ordering Source #

(<) :: ConversionError -> ConversionError -> Bool Source #

(<=) :: ConversionError -> ConversionError -> Bool Source #

(>) :: ConversionError -> ConversionError -> Bool Source #

(>=) :: ConversionError -> ConversionError -> Bool Source #

max :: ConversionError -> ConversionError -> ConversionError Source #

min :: ConversionError -> ConversionError -> ConversionError Source #

ShowErrorComponent ConversionError Source # |
Instance details Defined in Data.Csv.Parser.Megaparsec.Internals Methods showErrorComponent :: ConversionError -> String Source # errorComponentLen :: ConversionError -> Int Source #

decode Source #

Arguments

:: FromRecord a |
=> HasHeader | Whether the data contains header that should be skipped
-> FilePath | File name (only for displaying in parse error messages, use empty string if you have none)
-> ByteString | CSV data
-> Either (ParseErrorBundle ByteString ConversionError) (Vector a) |

Deserialize CSV records form a lazy `ByteString`. If this fails due to incomplete or invalid input, `Left` is returned. Equivalent to `decodeWith` `defaultDecodeOptions`.

decodeWith Source #

Arguments

:: FromRecord a |
=> DecodeOptions | Decoding options
-> HasHeader | Whether the data contains header that should be skipped
-> FilePath | File name (only for displaying in parse error messages, use empty string if you have none)
-> ByteString | CSV data
-> Either (ParseErrorBundle ByteString ConversionError) (Vector a) |

Like `decode`, but lets you customize how the CSV data is parsed.

decodeByName Source #

Arguments

:: FromNamedRecord a |
=> FilePath | File name (only for displaying in parse error messages, use empty string if you have none)
-> ByteString | CSV data
-> Either (ParseErrorBundle ByteString ConversionError) (Header, Vector a) |

Deserialize CSV records from a lazy `ByteString`. If this fails due to incomplete or invalid input, `Left` is returned. The data is assumed to be preceded by a header. Equivalent to `decodeByNameWith` `defaultDecodeOptions`.

decodeByNameWith Source #

Arguments

:: FromNamedRecord a |
=> DecodeOptions | Decoding options
-> FilePath | File name (only for displaying in parse error messages, use empty string if you have none)
-> ByteString | CSV data
-> Either (ParseErrorBundle ByteString ConversionError) (Header, Vector a) |

Like `decodeByName`, but lets you customize how the CSV data is parsed.