cassava-megaparsec 0.1.0 → 1.0.0
raw patch · 6 files changed
+53/−91 lines, 6 filesdep ~cassavadep ~cassava-megaparsecdep ~hspec-megaparsecPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: cassava, cassava-megaparsec, hspec-megaparsec, megaparsec
API changes (from Hackage documentation)
- Data.Csv.Parser.Megaparsec: CecConversionError :: String -> Cec
- Data.Csv.Parser.Megaparsec: CecFail :: String -> Cec
- Data.Csv.Parser.Megaparsec: CecIndentation :: Ordering -> Pos -> Pos -> Cec
- Data.Csv.Parser.Megaparsec: data Cec
- Data.Csv.Parser.Megaparsec: instance Data.Data.Data Data.Csv.Parser.Megaparsec.Cec
- Data.Csv.Parser.Megaparsec: instance GHC.Classes.Eq Data.Csv.Parser.Megaparsec.Cec
- Data.Csv.Parser.Megaparsec: instance GHC.Classes.Ord Data.Csv.Parser.Megaparsec.Cec
- Data.Csv.Parser.Megaparsec: instance GHC.Read.Read Data.Csv.Parser.Megaparsec.Cec
- Data.Csv.Parser.Megaparsec: instance GHC.Show.Show Data.Csv.Parser.Megaparsec.Cec
- Data.Csv.Parser.Megaparsec: instance Text.Megaparsec.Error.ErrorComponent Data.Csv.Parser.Megaparsec.Cec
- Data.Csv.Parser.Megaparsec: instance Text.Megaparsec.Error.ShowErrorComponent Data.Csv.Parser.Megaparsec.Cec
+ Data.Csv.Parser.Megaparsec: ConversionError :: String -> ConversionError
+ Data.Csv.Parser.Megaparsec: data ConversionError
+ Data.Csv.Parser.Megaparsec: instance Data.Data.Data Data.Csv.Parser.Megaparsec.ConversionError
+ Data.Csv.Parser.Megaparsec: instance GHC.Classes.Eq Data.Csv.Parser.Megaparsec.ConversionError
+ Data.Csv.Parser.Megaparsec: instance GHC.Classes.Ord Data.Csv.Parser.Megaparsec.ConversionError
+ Data.Csv.Parser.Megaparsec: instance GHC.Read.Read Data.Csv.Parser.Megaparsec.ConversionError
+ Data.Csv.Parser.Megaparsec: instance GHC.Show.Show Data.Csv.Parser.Megaparsec.ConversionError
+ Data.Csv.Parser.Megaparsec: instance Text.Megaparsec.Error.ShowErrorComponent Data.Csv.Parser.Megaparsec.ConversionError
- Data.Csv.Parser.Megaparsec: decode :: FromRecord a => HasHeader -> FilePath -> ByteString -> Either (ParseError Char Cec) (Vector a)
+ Data.Csv.Parser.Megaparsec: decode :: FromRecord a => HasHeader -> FilePath -> ByteString -> Either (ParseError Word8 ConversionError) (Vector a)
- Data.Csv.Parser.Megaparsec: decodeByName :: FromNamedRecord a => FilePath -> ByteString -> Either (ParseError Char Cec) (Header, Vector a)
+ Data.Csv.Parser.Megaparsec: decodeByName :: FromNamedRecord a => FilePath -> ByteString -> Either (ParseError Word8 ConversionError) (Header, Vector a)
- Data.Csv.Parser.Megaparsec: decodeByNameWith :: FromNamedRecord a => DecodeOptions -> FilePath -> ByteString -> Either (ParseError Char Cec) (Header, Vector a)
+ Data.Csv.Parser.Megaparsec: decodeByNameWith :: FromNamedRecord a => DecodeOptions -> FilePath -> ByteString -> Either (ParseError Word8 ConversionError) (Header, Vector a)
- Data.Csv.Parser.Megaparsec: decodeWith :: FromRecord a => DecodeOptions -> HasHeader -> FilePath -> ByteString -> Either (ParseError Char Cec) (Vector a)
+ Data.Csv.Parser.Megaparsec: decodeWith :: FromRecord a => DecodeOptions -> HasHeader -> FilePath -> ByteString -> Either (ParseError Word8 ConversionError) (Vector a)
Files
- CHANGELOG.md +7/−0
- Data/Csv/Parser/Megaparsec.hs +31/−53
- LICENSE.md +1/−1
- README.md +1/−1
- cassava-megaparsec.cabal +12/−35
- tests/Spec.hs +1/−1
CHANGELOG.md view
@@ -1,3 +1,10 @@+## Cassava Megaparsec 1.0.0++* Works with Megaparsec 6.++* Instead of `Cec` we have `ConversionError` as custom component of error+ messages.+ ## Cassava Megaparsec 0.1.0 * Initial release.
Data/Csv/Parser/Megaparsec.hs view
@@ -1,6 +1,6 @@ -- | -- Module : Data.Csv.Parser.Megaparsec--- Copyright : © 2016 Stack Builders+-- Copyright : © 2016–2017 Stack Builders -- License : MIT -- -- Maintainer : Mark Karpov <markkarpov@openmailbox.org>@@ -22,10 +22,11 @@ {-# LANGUAGE BangPatterns #-} {-# LANGUAGE CPP #-} {-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} module Data.Csv.Parser.Megaparsec- ( Cec (..)+ ( ConversionError (..) , decode , decodeWith , decodeByName@@ -34,7 +35,6 @@ import Control.Monad import Data.ByteString (ByteString)-import Data.Char (chr) import Data.Csv hiding ( Parser , record@@ -49,15 +49,16 @@ import Data.Vector (Vector) import Data.Word (Word8) import Text.Megaparsec-import qualified Data.ByteString.Char8 as BC8-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+import Text.Megaparsec.Byte+import qualified Data.ByteString as B+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 ((*>), (<*), (<$))+import Control.Applicative infixl 4 <$!> @@ -75,31 +76,16 @@ -- | Custom error component for CSV parsing. It allows typed reporting of -- conversion errors. -data Cec- = CecFail String- | CecIndentation Ordering Pos Pos- | CecConversionError String+data ConversionError = ConversionError String deriving (Eq, Data, Typeable, Ord, Read, Show) -instance ShowErrorComponent Cec where- showErrorComponent (CecFail msg) = msg- showErrorComponent (CecIndentation ord ref actual) =- "incorrect indentation (got " ++ show (unPos actual) ++- ", should be " ++ p ++ show (unPos ref) ++ ")"- where p = case ord of- LT -> "less than "- EQ -> "equal to "- GT -> "greater than "- showErrorComponent (CecConversionError msg) =+instance ShowErrorComponent ConversionError where+ showErrorComponent (ConversionError msg) = "conversion error: " ++ msg -instance ErrorComponent Cec where- representFail = CecFail- representIndentation = CecIndentation---- | Parser type that uses “custom error component” 'Cec'.+-- | Parser type that uses “custom error component” 'ConversionError'. -type Parser = Parsec Cec BL.ByteString+type Parser = Parsec ConversionError BL.ByteString ---------------------------------------------------------------------------- -- Top level interface@@ -115,7 +101,7 @@ -- ^ File name (use empty string if you have none) -> BL.ByteString -- ^ CSV data- -> Either (ParseError Char Cec) (Vector a)+ -> Either (ParseError Word8 ConversionError) (Vector a) decode = decodeWith defaultDecodeOptions {-# INLINE decode #-} @@ -130,7 +116,7 @@ -- ^ File name (use empty string if you have none) -> BL.ByteString -- ^ CSV data- -> Either (ParseError Char Cec) (Vector a)+ -> Either (ParseError Word8 ConversionError) (Vector a) decodeWith = decodeWithC csv {-# INLINE decodeWith #-} @@ -142,7 +128,7 @@ decodeByName :: FromNamedRecord a => FilePath -- ^ File name (use empty string if you have none) -> BL.ByteString -- ^ CSV data- -> Either (ParseError Char Cec) (Header, Vector a)+ -> Either (ParseError Word8 ConversionError) (Header, Vector a) decodeByName = decodeByNameWith defaultDecodeOptions {-# INLINE decodeByName #-} @@ -152,7 +138,7 @@ => DecodeOptions -- ^ Decoding options -> FilePath -- ^ File name (use empty string if you have none) -> BL.ByteString -- ^ CSV data- -> Either (ParseError Char Cec) (Header, Vector a)+ -> Either (ParseError Word8 ConversionError) (Header, Vector a) decodeByNameWith opts = parse (csvWithHeader opts) {-# INLINE decodeByNameWith #-} @@ -170,7 +156,7 @@ -- ^ File name (use empty string if you have none) -> BL.ByteString -- ^ CSV data- -> Either (ParseError Char Cec) a+ -> Either (ParseError Word8 ConversionError) a decodeWithC p opts@DecodeOptions {..} hasHeader = parse parser where parser = case hasHeader of@@ -209,7 +195,7 @@ header :: Word8 -> Parser Header header del = V.fromList <$!> p <* eol where- p = sepBy1 (name del) (blindByte del) <?> "file header"+ p = sepBy1 (name del) (void $ char del) <?> "file header" {-# INLINE header #-} -- | Parse a header name. Header names have the same format as regular@@ -230,7 +216,7 @@ -> Parser a record del f = do notFollowedBy eof -- to prevent reading empty line at the end of file- r <- V.fromList <$!> (sepBy1 (field del) (blindByte del) <?> "a record")+ r <- V.fromList <$!> (sepBy1 (field del) (void $ char del) <?> "record") case C.runParser (f r) of Left msg -> conversionError msg Right x -> return x@@ -240,25 +226,25 @@ -- format. The returned value is unescaped. field :: Word8 -> Parser Field-field del = label "a field" (escapedField <|> unescapedField del)+field del = label "field" (escapedField <|> unescapedField del) {-# INLINE field #-} -- | Parse an escaped field. escapedField :: Parser ByteString escapedField =- BC8.pack <$!> between (char '"') (char '"') (many $ normalChar <|> escapedDq)+ B.pack <$!> between (char 34) (char 34) (many $ normalChar <|> escapedDq) where- normalChar = noneOf "\"" <?> "unescaped character"- escapedDq = label "escaped double-quote" ('"' <$ string "\"\"")+ normalChar = notChar 34 <?> "unescaped character"+ escapedDq = label "escaped double-quote" (34 <$ string "\"\"") {-# INLINE escapedField #-} --- | Parse an unescaped field (up to first)+-- | Parse an unescaped field. unescapedField :: Word8 -> Parser ByteString-unescapedField del = BC8.pack <$!> many (noneOf es) -- anyChar (lookAhead $ oneOf es)+unescapedField del = BL.toStrict <$> takeWhileP (Just "unescaped character") f where- es = chr (fromIntegral del) : "\"\n\r"+ f x = x /= del && x /= 34 && x /= 10 && x /= 13 {-# INLINE unescapedField #-} ----------------------------------------------------------------------------@@ -267,9 +253,7 @@ -- | End parsing signaling a “conversion error”. conversionError :: String -> Parser a-conversionError msg = failure S.empty S.empty (S.singleton err)- where- err = CecConversionError msg+conversionError = fancyFailure . S.singleton . ErrorCustom . ConversionError {-# INLINE conversionError #-} -- | Convert a 'Record' to a 'NamedRecord' by attaching column names. The@@ -278,9 +262,3 @@ toNamedRecord :: Header -> Record -> NamedRecord toNamedRecord hdr v = H.fromList . V.toList $ V.zip hdr v {-# INLINE toNamedRecord #-}---- | Parse a byte of specified value and return unit.--blindByte :: Word8 -> Parser ()-blindByte = void . char . chr . fromIntegral-{-# INLINE blindByte #-}
LICENSE.md view
@@ -1,6 +1,6 @@ # MIT License -Copyright (c) 2016 Stack Builders+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
README.md view
@@ -60,6 +60,6 @@ ## License -Copyright © 2016 Stack Builders+Copyright © 2016–2017 Stack Builders Distributed under MIT license.
cassava-megaparsec.cabal view
@@ -1,46 +1,23 @@------ Cabal configuration for ‘cassava-megaparsec’ package.------ Copyright © 2016 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.- name: cassava-megaparsec-version: 0.1.0-cabal-version: >= 1.10+version: 1.0.0+cabal-version: >= 1.18+tested-with: GHC==7.8.4, GHC==7.10.3, GHC==8.0.2 license: MIT license-file: LICENSE.md author: Mark Karpov <markkarpov@openmailbox.org> maintainer: Mark Karpov <markkarpov@openmailbox.org>-homepage: https://github.com/mrkkrp/cassava-megaparsec-bug-reports: https://github.com/mrkkrp/cassava-megaparsec/issues+homepage: https://github.com/stackbuilders/cassava-megaparsec+bug-reports: https://github.com/stackbuilders/cassava-megaparsec/issues category: Text, Web, CSV, Parsing synopsis: Megaparsec parser of CSV files that plays nicely with Cassava build-type: Simple description: Megaparsec parser of CSV files that plays nicely with Cassava.-extra-source-files: CHANGELOG.md+extra-doc-files: CHANGELOG.md , README.md source-repository head type: git- location: https://github.com/stack-builders/cassava-megaparsec.git+ location: https://github.com/stackbuilders/cassava-megaparsec.git flag dev description: Turn on development settings.@@ -52,9 +29,9 @@ , bytestring >= 0.9 && < 0.11 , cassava >= 0.4.2 && < 0.5 , containers >= 0.5 && < 0.6- , megaparsec >= 5.0 && < 6.0+ , megaparsec >= 6.0 && < 7.0 , unordered-containers >= 0.2.7 && < 0.3- , vector >= 0.11 && < 0.12+ , vector >= 0.11 && < 0.13 exposed-modules: Data.Csv.Parser.Megaparsec if flag(dev) ghc-options: -Wall -Werror@@ -69,10 +46,10 @@ build-depends: base >= 4.7 && < 5.0 , bytestring >= 0.9 && < 0.11 , cassava >= 0.4.2 && < 0.5- , cassava-megaparsec >= 0.1+ , cassava-megaparsec , hspec >= 2.0 && < 3.0- , hspec-megaparsec >= 0.2 && < 0.3- , vector >= 0.11 && < 0.12+ , hspec-megaparsec >= 1.0 && < 2.0+ , vector >= 0.11 && < 0.13 if flag(dev) ghc-options: -Wall -Werror else
tests/Spec.hs view
@@ -1,7 +1,7 @@ -- -- Tests for the ‘cassava-megaparsec’ package. ----- Copyright © 2016 Stack Builders+-- 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