| 1 |
|
| 2 |
|
| 3 |
ers |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
module Data.Csv.Parser.Megaparsec |
| 23 |
( ConversionError (..) |
| 24 |
, decode |
| 25 |
, decodeWith |
| 26 |
, decodeByName |
| 27 |
, decodeByNameWith) |
| 28 |
where |
| 29 |
|
| 30 |
import Data.Csv hiding |
| 31 |
( decode |
| 32 |
, decodeWith |
| 33 |
, decodeByName |
| 34 |
, decodeByNameWith ) |
| 35 |
import Data.Vector (Vector) |
| 36 |
import Text.Megaparsec |
| 37 |
import qualified Data.ByteString.Lazy as BL |
| 38 |
import Data.Csv.Parser.Megaparsec.Internals |
| 39 |
( ConversionError (..) |
| 40 |
, csv |
| 41 |
, csvWithHeader |
| 42 |
, decodeWithC) |
| 43 |
|
| 44 |
---------------------------------------------------------------------------- |
| 45 |
-- Top level interface |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
decode :: FromRecord a |
| 52 |
=> HasHeader |
| 53 |
|
| 54 |
-> FilePath |
| 55 |
|
| 56 |
-- string if you have none) |
| 57 |
-> BL.ByteString |
| 58 |
|
| 59 |
-> Either (ParseErrorBundle BL.ByteString ConversionError) (Vector a) |
| 60 |
decode = decodeWith defaultDecodeOptions |
| 61 |
{-# INLINE decode #-} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
decodeWith :: FromRecord a |
| 66 |
=> DecodeOptions |
| 67 |
|
| 68 |
-> HasHeader |
| 69 |
|
| 70 |
-> FilePath |
| 71 |
|
| 72 |
-- string if you have none) |
| 73 |
-> BL.ByteString |
| 74 |
|
| 75 |
-> Either (ParseErrorBundle BL.ByteString ConversionError) (Vector a) |
| 76 |
decodeWith = decodeWithC csv |
| 77 |
{-# INLINE decodeWith #-} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
decodeByName :: FromNamedRecord a |
| 85 |
=> FilePath |
| 86 |
|
| 87 |
-- string if you have none) |
| 88 |
-> BL.ByteString |
| 89 |
|
| 90 |
-> Either (ParseErrorBundle BL.ByteString ConversionError) (Header, Vector a) |
| 91 |
decodeByName = decodeByNameWith defaultDecodeOptions |
| 92 |
{-# INLINE decodeByName #-} |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
decodeByNameWith :: FromNamedRecord a |
| 97 |
=> DecodeOptions |
| 98 |
|
| 99 |
-> FilePath |
| 100 |
|
| 101 |
-- string if you have none) |
| 102 |
-> BL.ByteString |
| 103 |
|
| 104 |
-> Either (ParseErrorBundle BL.ByteString ConversionError) (Header, Vector a) |
| 105 |
decodeByNameWith opts = parse (csvWithHeader opts) |
| 106 |
{-# INLINE decodeByNameWith #-} |