-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Megaparsec parser of CSV files that plays nicely with Cassava.
@package cassava-megaparsec
@version 2.1.1


module Data.Csv.Parser.Megaparsec.Internals

-- | Custom error component for CSV parsing. It allows typed reporting of
--   conversion errors.
newtype ConversionError
ConversionError :: String -> ConversionError

-- | Parser type that uses “custom error component” <a>ConversionError</a>.
type Parser = Parsec ConversionError ByteString

-- | Parse a CSV file that does not include a header.
csv :: FromRecord a => DecodeOptions -> Parser (Vector a)

-- | Parse a CSV file that includes a header.
csvWithHeader :: FromNamedRecord a => DecodeOptions -> Parser (Header, Vector a)

-- | Decode CSV data using the provided parser, skipping a leading header
--   if necessary.
decodeWithC :: (DecodeOptions -> Parser a) -> DecodeOptions -> HasHeader -> FilePath -> ByteString -> Either (ParseErrorBundle ByteString ConversionError) a

-- | Convert a <a>Record</a> to a <a>NamedRecord</a> by attaching column
--   names. The <a>Header</a> and <a>Record</a> must be of the same length.
toNamedRecord :: Header -> Record -> NamedRecord

-- | Parse a header, including the terminating line separator.
header :: Word8 -> Parser Header

-- | Parse a header name. Header names have the same format as regular
--   <a>field</a>s.
name :: Word8 -> Parser Name

-- | 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.
record :: Word8 -> (Record -> Parser a) -> Parser a

-- | Parse a field. The field may be in either the escaped or non-escaped
--   format. The returned value is unescaped.
field :: Word8 -> Parser Field

-- | Parse an escaped field.
escapedField :: Parser ByteString

-- | Parse an unescaped field.
unescapedField :: Word8 -> Parser ByteString
instance GHC.Internal.Data.Data.Data Data.Csv.Parser.Megaparsec.Internals.ConversionError
instance GHC.Classes.Eq Data.Csv.Parser.Megaparsec.Internals.ConversionError
instance GHC.Classes.Ord Data.Csv.Parser.Megaparsec.Internals.ConversionError
instance GHC.Internal.Read.Read Data.Csv.Parser.Megaparsec.Internals.ConversionError
instance GHC.Internal.Show.Show Data.Csv.Parser.Megaparsec.Internals.ConversionError
instance Text.Megaparsec.Error.ShowErrorComponent Data.Csv.Parser.Megaparsec.Internals.ConversionError


-- | A CSV parser. The parser here is RFC 4180 compliant, with the
--   following extensions:
--   
--   <ul>
--   <li>Non-escaped fields may contain any characters except
--   double-quotes, commas (or generally delimiter characters), carriage
--   returns, and newlines.</li>
--   <li>Escaped fields may contain any characters, but double-quotes need
--   to be escaped.</li>
--   </ul>
--   
--   The parser provides better error messages than the parser that comes
--   with Cassava library, while being compatible with the rest of the
--   library.
module Data.Csv.Parser.Megaparsec

-- | Custom error component for CSV parsing. It allows typed reporting of
--   conversion errors.
newtype ConversionError
ConversionError :: String -> ConversionError

-- | Deserialize CSV records form a lazy <a>ByteString</a>. If this fails
--   due to incomplete or invalid input, <a>Left</a> is returned.
--   Equivalent to <a>decodeWith</a> <a>defaultDecodeOptions</a>.
decode :: FromRecord a => HasHeader -> FilePath -> ByteString -> Either (ParseErrorBundle ByteString ConversionError) (Vector a)

-- | Like <a>decode</a>, but lets you customize how the CSV data is parsed.
decodeWith :: FromRecord a => DecodeOptions -> HasHeader -> FilePath -> ByteString -> Either (ParseErrorBundle ByteString ConversionError) (Vector a)

-- | Deserialize CSV records from a lazy <a>ByteString</a>. If this fails
--   due to incomplete or invalid input, <a>Left</a> is returned. The data
--   is assumed to be preceded by a header. Equivalent to
--   <a>decodeByNameWith</a> <a>defaultDecodeOptions</a>.
decodeByName :: FromNamedRecord a => FilePath -> ByteString -> Either (ParseErrorBundle ByteString ConversionError) (Header, Vector a)

-- | Like <a>decodeByName</a>, but lets you customize how the CSV data is
--   parsed.
decodeByNameWith :: FromNamedRecord a => DecodeOptions -> FilePath -> ByteString -> Either (ParseErrorBundle ByteString ConversionError) (Header, Vector a)
