packages feed

json-stream 0.3.0.4 → 0.3.1.0

raw patch · 3 files changed

+23/−6 lines, 3 filesdep ~basePVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base

API changes (from Hackage documentation)

+ Data.JsonStream.Parser: mapWithFailure :: (a -> Either String b) -> Parser a -> Parser b

Files

Data/JsonStream/CLexer.hs view
@@ -224,7 +224,7 @@  -- | Estimate number of elements in a chunk estResultLimit :: BS.ByteString -> CInt-estResultLimit dta = fromIntegral $ 20 + BS.length dta `div` 5+estResultLimit dta = fromIntegral $ 20 + BS.length dta `quot` 5  getNextResult :: TempData -> TokenResult getNextResult tmp@(TempData {..})
Data/JsonStream/Parser.hs view
@@ -67,6 +67,7 @@   , filterI   , takeI   , toList+  , mapWithFailure     -- * SAX-like parsers   , arrayFound   , objectFound@@ -239,12 +240,12 @@     parseAndAppend (MoreData (Parser np, ntp)) = MoreData (Parser (parseAndAppend . np), ntp)     parseAndAppend (Done ctx ntp) = Yield end (Done ctx ntp) --- | Generate start/end values when an array is found, in between run a parser.+-- | Generate start/end values when an object is found, in between run a parser. -- The inner parser is not run if an array is not found. objectFound :: a -> a -> Parser a -> Parser a objectFound = elemFound ObjectBegin --- | Generate start/end values when an object is found, in between run a parser.+-- | Generate start/end values when an array is found, in between run a parser. -- The inner parser is not run if an array is not found. -- -- > >>> let test = "[[1,2,3],true,[],false,{\"key\":1}]" :: ByteString@@ -541,6 +542,22 @@     loop (Yield v np)       | cond v = Yield v (loop np)       | otherwise = loop np++-- | A back-door for lifting of possibly failing actions.+-- If an action fails with Left value, convert it into failure+-- of parsing+mapWithFailure :: (a -> Either String b) -> Parser a -> Parser b+mapWithFailure mapping =+  updateParser+  where+    updateParser (Parser run) = Parser $ updateParseResult . run+    updateParseResult x = case x of+      MoreData (parser, continuation) -> MoreData (updateParser parser, continuation)+      Failed message -> Failed message+      Done a b -> Done a b+      Yield value parseResult -> case mapping value of+        Left message -> Failed message+        Right value' -> Yield value' (updateParseResult parseResult)  --- Convenience operators 
json-stream.cabal view
@@ -1,5 +1,5 @@ name:                json-stream-version:             0.3.0.4+version:             0.3.1.0 synopsis:            Incremental applicative JSON parser description:         Easy to use JSON parser fully supporting incremental parsing.                      Parsing grammar in applicative form.@@ -33,7 +33,7 @@   c-sources:           c_lib/lexer.c   includes:            c_lib/lexer.h   include-dirs:        c_lib-  build-depends:         base >=4.7 && <4.8+  build-depends:         base >=4.7 && <4.9                        , bytestring                        , text                        , aeson@@ -51,7 +51,7 @@   type:                exitcode-stdio-1.0   hs-source-dirs:      test, .   default-language:    Haskell2010-  build-depends:         base >=4.7 && <4.8+  build-depends:         base >=4.7 && <4.9                        , bytestring                        , text                        , aeson