json-togo 0.1.0.0 → 0.1.0.1
raw patch · 2 files changed
+12/−5 lines, 2 filesdep ~attoparsec-trans
Dependency ranges changed: attoparsec-trans
Files
- json-togo.cabal +2/−2
- src/Data/JSON/ToGo/Parser.hs +10/−3
json-togo.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: json-togo-version: 0.1.0.0+version: 0.1.0.1 synopsis: Effectful parsing of JSON documents -- description: homepage: https://github.com/srijs/haskell-json-togo@@ -28,7 +28,7 @@ scientific >=0.3 && <0.4, aeson >=0.8 && <0.10, attoparsec >=0.12 && <0.14,- attoparsec-trans >=0.1 && <0.2,+ attoparsec-trans >=0.1.0.3 && <0.2, vector >=0.10 && <0.11, unordered-containers >=0.2 && <0.3 hs-source-dirs: src
src/Data/JSON/ToGo/Parser.hs view
@@ -4,9 +4,11 @@ import Prelude hiding (sequence) +import Data.Aeson (FromJSON, parseJSON) import Data.Aeson.Parser (jstring, value)-import Data.Aeson.Types (Value)-import Data.Attoparsec.ByteString.Char8 (skipSpace, char, string, scientific, parse)+import Data.Aeson.Types (Value, parseEither)+import Data.Attoparsec.ByteString.Char8 (skipSpace, char, string, scientific)+import qualified Data.Attoparsec.ByteString.Char8 as Atto import Data.ByteString (ByteString) import Data.Monoid (Monoid, mempty, (<>)) import Data.Scientific (Scientific)@@ -18,7 +20,7 @@ type ParserM = ParserT ByteString -rP p = liftP . parse $ skipSpace >> p+rP p = liftP . Atto.parse $ skipSpace >> p parray :: (Monad m, Monoid r) => (Int -> ParserM m r) -> ParserM m r parray f = rP (char '[') >> go 0 mempty@@ -63,3 +65,8 @@ pvalue :: Monad m => ParserM m Value pvalue = rP value++parse :: (Monad m, FromJSON a) => ParserM m a+parse = fmap (parseEither parseJSON) pvalue >>= unwrap+ where unwrap (Left s) = fail s+ unwrap (Right r) = return r