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

Copyright | © 2016–2021 Stack Builders
License | MIT
Safe Haskell | None
Language | Haskell2010

Data.Csv.Parser.Megaparsec.Internals

Description

Synopsis

- newtype ConversionError = ConversionError String
- type Parser = Parsec ConversionError ByteString
- csv :: FromRecord a => DecodeOptions -> Parser (Vector a)
- csvWithHeader :: FromNamedRecord a => DecodeOptions -> Parser (Header, Vector a)
- decodeWithC :: (DecodeOptions -> Parser a) -> DecodeOptions -> HasHeader -> FilePath -> ByteString -> Either (ParseErrorBundle ByteString ConversionError) a
- toNamedRecord :: Header -> Record -> NamedRecord
- header :: Word8 -> Parser Header
- name :: Word8 -> Parser Name
- record :: Word8 -> (Record -> Parser a) -> Parser a
- field :: Word8 -> Parser Field
- escapedField :: Parser ByteString
- unescapedField :: Word8 -> Parser ByteString

# 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 #

type Parser = Parsec ConversionError ByteString Source #

Parser type that uses “custom error component” `ConversionError`.

csv Source #

Arguments

:: FromRecord a |
=> DecodeOptions | Decoding options
-> Parser (Vector a) | The parser that parses collection of records

Parse a CSV file that does not include a header.

csvWithHeader Source #

Arguments

:: FromNamedRecord a |
=> DecodeOptions | Decoding options
-> Parser (Header, Vector a) | The parser that parser collection of named records

Parse a CSV file that includes a header.

decodeWithC Source #

Arguments

:: (DecodeOptions -> Parser a) | Parsing function parametrized by `DecodeOptions`
-> DecodeOptions | Decoding options
-> HasHeader | Whether to expect a header in the input
-> FilePath | File name (only for displaying in parse error messages, use empty string if you have none)
-> ByteString | CSV data
-> Either (ParseErrorBundle ByteString ConversionError) a |

Decode CSV data using the provided parser, skipping a leading header if necessary.

toNamedRecord :: Header -> Record -> NamedRecord Source #

Convert a `Record` to a `NamedRecord` by attaching column names. The `Header` and `Record` must be of the same length.

header :: Word8 -> Parser Header Source #

Parse a header, including the terminating line separator.

name :: Word8 -> Parser Name Source #

Parse a header name. Header names have the same format as regular `field`s.

record Source #

Arguments

:: Word8 | Field delimiter
-> (Record -> Parser a) | How to “parse” record to get the data of interest
-> Parser a |

Parse a record, not including the terminating line separator. The terminating line separate is not included as the last record in a CSV file is allowed to not have a terminating line separator.

field :: Word8 -> Parser Field Source #

Parse a field. The field may be in either the escaped or non-escaped format. The returned value is unescaped.

escapedField :: Parser ByteString Source #

Parse an escaped field.

unescapedField :: Word8 -> Parser ByteString Source #

Parse an unescaped field.