cassava-megaparsec 1.0.0 → 2.0.0
raw patch · 6 files changed
+60/−89 lines, 6 filesdep −containersdep ~basedep ~hspec-megaparsecdep ~megaparsecPVP ok
version bump matches the API change (PVP)
Dependencies removed: containers
Dependency ranges changed: base, hspec-megaparsec, megaparsec
API changes (from Hackage documentation)
- Data.Csv.Parser.Megaparsec: data ConversionError
+ Data.Csv.Parser.Megaparsec: newtype ConversionError
- Data.Csv.Parser.Megaparsec: decode :: FromRecord a => HasHeader -> FilePath -> ByteString -> Either (ParseError Word8 ConversionError) (Vector a)
+ Data.Csv.Parser.Megaparsec: decode :: FromRecord a => HasHeader -> FilePath -> ByteString -> Either (ParseErrorBundle ByteString ConversionError) (Vector a)
- Data.Csv.Parser.Megaparsec: decodeByName :: FromNamedRecord a => FilePath -> ByteString -> Either (ParseError Word8 ConversionError) (Header, Vector a)
+ Data.Csv.Parser.Megaparsec: decodeByName :: FromNamedRecord a => FilePath -> ByteString -> Either (ParseErrorBundle ByteString ConversionError) (Header, Vector a)
- Data.Csv.Parser.Megaparsec: decodeByNameWith :: FromNamedRecord a => DecodeOptions -> FilePath -> ByteString -> Either (ParseError Word8 ConversionError) (Header, Vector a)
+ Data.Csv.Parser.Megaparsec: decodeByNameWith :: FromNamedRecord a => DecodeOptions -> FilePath -> ByteString -> Either (ParseErrorBundle ByteString ConversionError) (Header, Vector a)
- Data.Csv.Parser.Megaparsec: decodeWith :: FromRecord a => DecodeOptions -> HasHeader -> FilePath -> ByteString -> Either (ParseError Word8 ConversionError) (Vector a)
+ Data.Csv.Parser.Megaparsec: decodeWith :: FromRecord a => DecodeOptions -> HasHeader -> FilePath -> ByteString -> Either (ParseErrorBundle ByteString ConversionError) (Vector a)
Files
- CHANGELOG.md +4/−0
- Data/Csv/Parser/Megaparsec.hs +37/−51
- LICENSE.md +1/−1
- README.md +1/−1
- cassava-megaparsec.cabal +17/−12
- tests/Spec.hs +0/−24
CHANGELOG.md view
@@ -1,3 +1,7 @@+## Cassava Megaparsec 2.0.0++* Works with Megaparsec 7.+ ## Cassava Megaparsec 1.0.0 * Works with Megaparsec 6.
Data/Csv/Parser/Megaparsec.hs view
@@ -1,9 +1,9 @@ -- | -- Module : Data.Csv.Parser.Megaparsec--- Copyright : © 2016–2017 Stack Builders+-- Copyright : © 2016–2018 Stack Builders -- License : MIT ----- Maintainer : Mark Karpov <markkarpov@openmailbox.org>+-- Maintainer : Mark Karpov <markkarpov92@gmail.org> -- Stability : experimental -- Portability : portable --@@ -20,7 +20,6 @@ -- Cassava library, while being compatible with the rest of the library. {-# LANGUAGE BangPatterns #-}-{-# LANGUAGE CPP #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-}@@ -54,29 +53,15 @@ import qualified Data.ByteString.Lazy as BL import qualified Data.Csv as C import qualified Data.HashMap.Strict as H-import qualified Data.Set as S import qualified Data.Vector as V -#if !MIN_VERSION_base(4,8,0)-import Control.Applicative--infixl 4 <$!>--(<$!>) :: Monad m => (a -> b) -> m a -> m b-f <$!> m = do- x <- m- let z = f x- z `seq` return z-{-# INLINE (<$!>) #-}-#endif- ---------------------------------------------------------------------------- -- Custom error component and other types -- | Custom error component for CSV parsing. It allows typed reporting of -- conversion errors. -data ConversionError = ConversionError String+newtype ConversionError = ConversionError String deriving (Eq, Data, Typeable, Ord, Read, Show) instance ShowErrorComponent ConversionError where@@ -98,10 +83,11 @@ => HasHeader -- ^ Whether the data contains header that should be skipped -> FilePath- -- ^ File name (use empty string if you have none)+ -- ^ File name (only for displaying in parse error messages, use empty+ -- string if you have none) -> BL.ByteString -- ^ CSV data- -> Either (ParseError Word8 ConversionError) (Vector a)+ -> Either (ParseErrorBundle BL.ByteString ConversionError) (Vector a) decode = decodeWith defaultDecodeOptions {-# INLINE decode #-} @@ -113,10 +99,11 @@ -> HasHeader -- ^ Whether the data contains header that should be skipped -> FilePath- -- ^ File name (use empty string if you have none)+ -- ^ File name (only for displaying in parse error messages, use empty+ -- string if you have none) -> BL.ByteString -- ^ CSV data- -> Either (ParseError Word8 ConversionError) (Vector a)+ -> Either (ParseErrorBundle BL.ByteString ConversionError) (Vector a) decodeWith = decodeWithC csv {-# INLINE decodeWith #-} @@ -126,19 +113,26 @@ -- 'defaultDecodeOptions'. decodeByName :: FromNamedRecord a- => FilePath -- ^ File name (use empty string if you have none)- -> BL.ByteString -- ^ CSV data- -> Either (ParseError Word8 ConversionError) (Header, Vector a)+ => FilePath+ -- ^ File name (only for displaying in parse error messages, use empty+ -- string if you have none)+ -> BL.ByteString+ -- ^ CSV data+ -> Either (ParseErrorBundle BL.ByteString ConversionError) (Header, Vector a) decodeByName = decodeByNameWith defaultDecodeOptions {-# INLINE decodeByName #-} -- | Like 'decodeByName', but lets you customize how the CSV data is parsed. decodeByNameWith :: FromNamedRecord a- => DecodeOptions -- ^ Decoding options- -> FilePath -- ^ File name (use empty string if you have none)- -> BL.ByteString -- ^ CSV data- -> Either (ParseError Word8 ConversionError) (Header, Vector a)+ => DecodeOptions+ -- ^ Decoding options+ -> FilePath+ -- ^ File name (only for displaying in parse error messages, use empty+ -- string if you have none)+ -> BL.ByteString+ -- ^ CSV data+ -> Either (ParseErrorBundle BL.ByteString ConversionError) (Header, Vector a) decodeByNameWith opts = parse (csvWithHeader opts) {-# INLINE decodeByNameWith #-} @@ -153,10 +147,11 @@ -> HasHeader -- ^ Whether to expect a header in the input -> FilePath- -- ^ File name (use empty string if you have none)+ -- ^ File name (only for displaying in parse error messages, use empty+ -- string if you have none) -> BL.ByteString -- ^ CSV data- -> Either (ParseError Word8 ConversionError) a+ -> Either (ParseErrorBundle BL.ByteString ConversionError) a decodeWithC p opts@DecodeOptions {..} hasHeader = parse parser where parser = case hasHeader of@@ -172,7 +167,7 @@ csv :: FromRecord a => DecodeOptions -- ^ Decoding options -> Parser (Vector a) -- ^ The parser that parses collection of records-csv !DecodeOptions {..} = do+csv DecodeOptions {..} = do xs <- sepEndBy1 (record decDelimiter parseRecord) eol eof return $! V.fromList xs@@ -183,13 +178,20 @@ => DecodeOptions -- ^ Decoding options -> Parser (Header, Vector a) -- ^ The parser that parser collection of named records-csvWithHeader !DecodeOptions {..} = do+csvWithHeader DecodeOptions {..} = do !hdr <- header decDelimiter let f = parseNamedRecord . toNamedRecord hdr xs <- sepEndBy1 (record decDelimiter f) eol eof return $ let !v = V.fromList xs in (hdr, v) +-- | Convert a 'Record' to a 'NamedRecord' by attaching column names. The+-- 'Header' and 'Record' must be of the same length.++toNamedRecord :: Header -> Record -> NamedRecord+toNamedRecord hdr v = H.fromList . V.toList $ V.zip hdr v+{-# INLINE toNamedRecord #-}+ -- | Parse a header, including the terminating line separator. header :: Word8 -> Parser Header@@ -218,7 +220,7 @@ notFollowedBy eof -- to prevent reading empty line at the end of file r <- V.fromList <$!> (sepBy1 (field del) (void $ char del) <?> "record") case C.runParser (f r) of- Left msg -> conversionError msg+ Left msg -> customFailure (ConversionError msg) Right x -> return x {-# INLINE record #-} @@ -235,7 +237,7 @@ escapedField = B.pack <$!> between (char 34) (char 34) (many $ normalChar <|> escapedDq) where- normalChar = notChar 34 <?> "unescaped character"+ normalChar = anySingleBut 34 <?> "unescaped character" escapedDq = label "escaped double-quote" (34 <$ string "\"\"") {-# INLINE escapedField #-} @@ -246,19 +248,3 @@ where f x = x /= del && x /= 34 && x /= 10 && x /= 13 {-# INLINE unescapedField #-}--------------------------------------------------------------------------------- Helpers---- | End parsing signaling a “conversion error”.--conversionError :: String -> Parser a-conversionError = fancyFailure . S.singleton . ErrorCustom . ConversionError-{-# INLINE conversionError #-}---- | Convert a 'Record' to a 'NamedRecord' by attaching column names. The--- 'Header' and 'Record' must be of the same length.--toNamedRecord :: Header -> Record -> NamedRecord-toNamedRecord hdr v = H.fromList . V.toList $ V.zip hdr v-{-# INLINE toNamedRecord #-}
LICENSE.md view
@@ -1,6 +1,6 @@ # MIT License -Copyright © 2016–2017 Stack Builders+Copyright © 2016–2018 Stack Builders Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to
README.md view
@@ -60,6 +60,6 @@ ## License -Copyright © 2016–2017 Stack Builders+Copyright © 2016–2018 Stack Builders Distributed under MIT license.
cassava-megaparsec.cabal view
@@ -1,11 +1,11 @@ name: cassava-megaparsec-version: 1.0.0-cabal-version: >= 1.18-tested-with: GHC==7.8.4, GHC==7.10.3, GHC==8.0.2+version: 2.0.0+cabal-version: 1.18+tested-with: GHC==7.10.3, GHC==8.0.2, GHC==8.2.2, GHC==8.4.3, GHC==8.6.1 license: MIT license-file: LICENSE.md-author: Mark Karpov <markkarpov@openmailbox.org>-maintainer: Mark Karpov <markkarpov@openmailbox.org>+author: Mark Karpov <markkarpov92@gmail.org>+maintainer: Mark Karpov <markkarpov92@gmail.org> homepage: https://github.com/stackbuilders/cassava-megaparsec bug-reports: https://github.com/stackbuilders/cassava-megaparsec/issues category: Text, Web, CSV, Parsing@@ -25,11 +25,10 @@ default: False library- build-depends: base >= 4.7 && < 5.0+ build-depends: base >= 4.8 && < 5.0 , bytestring >= 0.9 && < 0.11- , cassava >= 0.4.2 && < 0.5- , containers >= 0.5 && < 0.6- , megaparsec >= 6.0 && < 7.0+ , cassava >= 0.4.2 && < 0.6+ , megaparsec >= 7.0 && < 8.0 , unordered-containers >= 0.2.7 && < 0.3 , vector >= 0.11 && < 0.13 exposed-modules: Data.Csv.Parser.Megaparsec@@ -37,18 +36,24 @@ ghc-options: -Wall -Werror else ghc-options: -O2 -Wall+ if flag(dev) && impl(ghc >= 8.0)+ ghc-options: -Wcompat+ -Wincomplete-record-updates+ -Wincomplete-uni-patterns+ -Wnoncanonical-monad-instances+ -Wnoncanonical-monadfail-instances default-language: Haskell2010 test-suite tests main-is: Spec.hs hs-source-dirs: tests type: exitcode-stdio-1.0- build-depends: base >= 4.7 && < 5.0+ build-depends: base >= 4.8 && < 5.0 , bytestring >= 0.9 && < 0.11- , cassava >= 0.4.2 && < 0.5+ , cassava >= 0.4.2 && < 0.6 , cassava-megaparsec , hspec >= 2.0 && < 3.0- , hspec-megaparsec >= 1.0 && < 2.0+ , hspec-megaparsec >= 2.0 && < 3.0 , vector >= 0.11 && < 0.13 if flag(dev) ghc-options: -Wall -Werror
tests/Spec.hs view
@@ -1,27 +1,3 @@------ Tests for the ‘cassava-megaparsec’ package.------ Copyright © 2016–2017 Stack Builders------ Permission is hereby granted, free of charge, to any person obtaining a--- copy of this software and associated documentation files (the--- "Software"), to deal in the Software without restriction, including--- without limitation the rights to use, copy, modify, merge, publish,--- distribute, sublicense, and/or sell copies of the Software, and to permit--- persons to whom the Software is furnished to do so, subject to the--- following conditions:------ The above copyright notice and this permission notice shall be included--- in all copies or substantial portions of the Software.------ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS--- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF--- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN--- NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,--- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR--- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE--- USE OR OTHER DEALINGS IN THE SOFTWARE.- {-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-}