binary-parser 0.5.7.3 → 0.5.7.4
raw patch · 4 files changed
+27/−43 lines, 4 filesdep −QuickCheckdep −quickcheck-instancesPVP ok
version bump matches the API change (PVP)
Dependencies removed: QuickCheck, quickcheck-instances
API changes (from Hackage documentation)
Files
- binary-parser.cabal +15/−17
- library/BinaryParser.hs +5/−19
- library/BinaryParser/Prelude.hs +4/−6
- tests/Main.hs +3/−1
binary-parser.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: binary-parser-version: 0.5.7.3+version: 0.5.7.4 synopsis: An efficient but limited parser API specialised to bytestrings @@ -17,7 +17,7 @@ type: git location: git://github.com/nikita-volkov/binary-parser.git -common base-settings+common base default-language: Haskell2010 default-extensions: NoImplicitPrelude@@ -59,29 +59,27 @@ TypeOperators UnboxedTuples - build-depends:- , base >=4.12 && <5- , bytestring >=0.10 && <0.12- , mtl >=2 && <3- , text >=1 && <3- , transformers >=0.4 && <0.7- library- import: base-settings+ import: base hs-source-dirs: library other-modules: BinaryParser.Prelude exposed-modules: BinaryParser+ build-depends:+ , base >=4.12 && <5+ , bytestring >=0.10 && <0.12+ , mtl >=2 && <3+ , text >=1 && <3+ , transformers >=0.4 && <0.7 test-suite tests- import: base-settings+ import: base type: exitcode-stdio-1.0 hs-source-dirs: tests main-is: Main.hs build-depends:- , base-prelude >=1.6 && <2+ , base-prelude >=1.6 && <2 , binary-parser- , QuickCheck >=2.10 && <3- , quickcheck-instances ^>=0.3.22- , tasty >=1.2.3 && <2- , tasty-hunit ^>=0.10- , tasty-quickcheck ^>=0.10+ , bytestring >=0.10 && <0.12+ , tasty >=1.2.3 && <2+ , tasty-hunit ^>=0.10+ , tasty-quickcheck ^>=0.10
library/BinaryParser.hs view
@@ -29,9 +29,8 @@ where import BinaryParser.Prelude hiding (fold)-import qualified BinaryParser.Prelude as B import qualified Data.ByteString as ByteString-import qualified Data.ByteString.Internal as A+import qualified Data.ByteString.Internal as ByteString import qualified Data.ByteString.Unsafe as ByteString -- |@@ -79,19 +78,6 @@ -- | -- Consume a single byte, which satisfies the predicate.-{-# INLINE satisfyingByte #-}-satisfyingByte :: (Word8 -> Bool) -> BinaryParser Word8-satisfyingByte predicate =- BinaryParser $ \remainders ->- case ByteString.uncons remainders of- Nothing -> Left "End of input"- Just (head, tail) ->- if predicate head- then Right (head, tail)- else Left "Byte doesn't satisfy a predicate"---- |--- Consume a single byte, which satisfies the predicate. {-# INLINE matchingByte #-} matchingByte :: (Word8 -> Either Text a) -> BinaryParser a matchingByte matcher =@@ -197,15 +183,15 @@ -- | -- Storable value of the given amount of bytes. {-# INLINE storableOfSize #-}-storableOfSize :: Storable a => Int -> BinaryParser a+storableOfSize :: (Storable a) => Int -> BinaryParser a storableOfSize size =- BinaryParser $ \(A.PS payloadFP offset length) ->+ BinaryParser $ \(ByteString.PS payloadFP offset length) -> if length >= size then let result = unsafeDupablePerformIO $ withForeignPtr payloadFP $ \ptr -> peekByteOff (castPtr ptr) offset newRemainder =- A.PS payloadFP (offset + size) (length - size)+ ByteString.PS payloadFP (offset + size) (length - size) in Right (result, newRemainder) else Left "End of input" @@ -278,7 +264,7 @@ -- | -- Integral number encoded in ASCII. {-# INLINE asciiIntegral #-}-asciiIntegral :: Integral a => BinaryParser a+asciiIntegral :: (Integral a) => BinaryParser a asciiIntegral = do firstDigit <- matchingByte byteDigit
library/BinaryParser/Prelude.hs view
@@ -12,7 +12,7 @@ import Control.Exception as Exports import Control.Monad as Exports hiding (fail, forM, forM_, mapM, mapM_, msum, sequence, sequence_) import Control.Monad.Cont.Class as Exports-import Control.Monad.Error.Class as Exports hiding (Error (..))+import Control.Monad.Error.Class as Exports (MonadError (..)) import Control.Monad.Fail as Exports import Control.Monad.Fix as Exports hiding (fix) import Control.Monad.IO.Class as Exports@@ -43,7 +43,7 @@ import Data.IORef as Exports import Data.Int as Exports import Data.Ix as Exports-import Data.List as Exports hiding (all, and, any, concat, concatMap, elem, find, foldl, foldl', foldl1, foldr, foldr1, isSubsequenceOf, mapAccumL, mapAccumR, maximum, maximumBy, minimum, minimumBy, notElem, or, product, sortOn, sum, uncons)+import Data.List as Exports hiding (all, and, any, concat, concatMap, elem, find, foldl, foldl', foldl1, foldr, foldr1, isSubsequenceOf, mapAccumL, mapAccumR, maximum, maximumBy, minimum, minimumBy, notElem, or, product, sortOn, sum, uncons, unzip) import Data.List.NonEmpty as Exports (NonEmpty (..)) import Data.Maybe as Exports import Data.Monoid as Exports hiding (First (..), Last (..), (<>))@@ -78,18 +78,16 @@ import System.Mem as Exports import System.Mem.StableName as Exports import System.Timeout as Exports-import Text.ParserCombinators.ReadP as Exports (ReadP, ReadS, readP_to_S, readS_to_P)-import Text.ParserCombinators.ReadPrec as Exports (ReadPrec, readP_to_Prec, readPrec_to_P, readPrec_to_S, readS_to_Prec) import Text.Printf as Exports (hPrintf, printf) import Text.Read as Exports (Read (..), readEither, readMaybe) import Unsafe.Coerce as Exports-import Prelude as Exports hiding (all, and, any, concat, concatMap, elem, fail, foldl, foldl1, foldr, foldr1, id, mapM, mapM_, maximum, minimum, notElem, or, product, sequence, sequence_, sum, (.))+import Prelude as Exports hiding (all, and, any, concat, concatMap, elem, fail, foldl, foldl1, foldr, foldr1, id, mapM, mapM_, maximum, minimum, notElem, or, product, sequence, sequence_, sum, unzip, (.)) {-# INLINE mapLeft #-} mapLeft :: (a -> b) -> Either a x -> Either b x mapLeft f = either (Left . f) Right -joinMap :: Monad m => (a -> m b) -> m a -> m b+joinMap :: (Monad m) => (a -> m b) -> m a -> m b joinMap f = join . liftM f
tests/Main.hs view
@@ -5,11 +5,11 @@ import qualified Data.ByteString as A import qualified Data.ByteString.Builder as C import qualified Data.ByteString.Lazy as D-import Test.QuickCheck.Instances import Test.Tasty import Test.Tasty.HUnit import Test.Tasty.QuickCheck +main :: IO () main = defaultMain $ testGroup "All tests" $@@ -26,6 +26,7 @@ in expectedResultTest "Monadic composition" parser (1, 2) "\NUL\SOH\NUL\STX" ] +builderIsomporhismProperty :: (Arbitrary a, Show a, Eq a) => TestName -> B.BinaryParser a -> (a -> C.Builder) -> TestTree builderIsomporhismProperty details parser valueToBuilder = testProperty name $ \value -> B.run parser (D.toStrict (C.toLazyByteString (valueToBuilder value)))@@ -34,6 +35,7 @@ name = "builderIsomporhismProperty: " <> details +expectedResultTest :: (Eq b, Show b) => TestName -> B.BinaryParser b -> b -> A.ByteString -> TestTree expectedResultTest details parser expectedValue input = testCase name $ do assertEqual "" (Right expectedValue) (B.run parser input)