@@ -7,16 +7,13 @@
7{-# LANGUAGE MultiParamTypeClasses #-}
7{-# LANGUAGE MultiParamTypeClasses #-}
8{-# LANGUAGE NoImplicitPrelude #-}
8{-# LANGUAGE NoImplicitPrelude #-}
9{-# LANGUAGE OverloadedStrings #-}
9{-# LANGUAGE OverloadedStrings #-}
10+{-# LANGUAGE PolyKinds #-}
10{-# LANGUAGE RecordWildCards #-}
11{-# LANGUAGE RecordWildCards #-}
11{-# LANGUAGE ScopedTypeVariables #-}
12{-# LANGUAGE ScopedTypeVariables #-}
12{-# LANGUAGE TypeOperators #-}
13{-# LANGUAGE TypeOperators #-}
13{-# LANGUAGE UndecidableInstances #-}
14{-# LANGUAGE UndecidableInstances #-}
14{-# LANGUAGE ViewPatterns #-}
15{-# LANGUAGE ViewPatterns #-}
16−#if __GLASGOW_HASKELL__ >= 706
17−{-# LANGUAGE PolyKinds #-}
20#include "incoherent-compat.h"
17#include "incoherent-compat.h"
21#include "overlapping-compat.h"
18#include "overlapping-compat.h"
@@ -120,9 +117,9 @@ import GHC.Generics
120import Numeric.Natural (Natural)
117import Numeric.Natural (Natural)
121import Text.ParserCombinators.ReadP (readP_to_S)
118import Text.ParserCombinators.ReadP (readP_to_S)
122import Unsafe.Coerce (unsafeCoerce)
119import Unsafe.Coerce (unsafeCoerce)
123−import qualified Data.Aeson.Compat as Compat
124import qualified Data.Aeson.Parser.Time as Time
120import qualified Data.Aeson.Parser.Time as Time
125import qualified Data.Attoparsec.ByteString.Char8 as A (endOfInput, parseOnly, scientific)
121import qualified Data.Attoparsec.ByteString.Char8 as A (endOfInput, parseOnly, scientific)
122+import qualified Data.ByteString.Lazy as L
126import qualified Data.DList as DList
123import qualified Data.DList as DList
127import qualified Data.HashMap.Strict as H
124import qualified Data.HashMap.Strict as H
128import qualified Data.HashSet as HashSet
125import qualified Data.HashSet as HashSet
@@ -157,18 +154,8 @@ import qualified Data.Primitive.UnliftedArray as PM
157import qualified Data.Primitive.PrimArray as PM
154import qualified Data.Primitive.PrimArray as PM
160−#ifndef HAS_COERCIBLE
161−#define HAS_COERCIBLE (__GLASGOW_HASKELL__ >= 707)
165import Data.Coerce (Coercible, coerce)
158import Data.Coerce (Coercible, coerce)
166−coerce' :: Coercible a b => a -> b
170−coerce' = unsafeCoerce
173parseIndexedJSON :: (Value -> Parser a) -> Int -> Value -> Parser a
160parseIndexedJSON :: (Value -> Parser a) -> Int -> Value -> Parser a
174parseIndexedJSON p idx value = p value <?> Index idx
161parseIndexedJSON p idx value = p value <?> Index idx
@@ -440,11 +427,7 @@ class FromJSONKey a where
440-- At the moment this type is intentionally not exported. 'FromJSONKeyFunction'
427-- At the moment this type is intentionally not exported. 'FromJSONKeyFunction'
441-- can be inspected, but cannot be constructed.
428-- can be inspected, but cannot be constructed.
442data CoerceText a where
429data CoerceText a where
444 CoerceText :: Coercible Text a => CoerceText a
430 CoerceText :: Coercible Text a => CoerceText a
446− CoerceText :: CoerceText a
449-- | This type is related to 'ToJSONKeyFunction'. If 'FromJSONKeyValue' is used in the
432-- | This type is related to 'ToJSONKeyFunction'. If 'FromJSONKeyValue' is used in the
450-- 'FromJSONKey' instance, then 'ToJSONKeyValue' should be used in the 'ToJSONKey'
433-- 'FromJSONKey' instance, then 'ToJSONKeyValue' should be used in the 'ToJSONKey'
@@ -464,7 +447,7 @@ data FromJSONKeyFunction a
465-- | Only law abiding up to interpretation
448-- | Only law abiding up to interpretation
466instance Functor FromJSONKeyFunction where
449instance Functor FromJSONKeyFunction where
467− fmap h (FromJSONKeyCoerce CoerceText) = FromJSONKeyText (h . coerce')
450+ fmap h (FromJSONKeyCoerce CoerceText) = FromJSONKeyText (h . coerce)
468 fmap h (FromJSONKeyText f) = FromJSONKeyText (h . f)
451 fmap h (FromJSONKeyText f) = FromJSONKeyText (h . f)
469 fmap h (FromJSONKeyTextParser f) = FromJSONKeyTextParser (fmap h . f)
452 fmap h (FromJSONKeyTextParser f) = FromJSONKeyTextParser (fmap h . f)
470 fmap h (FromJSONKeyValue f) = FromJSONKeyValue (fmap h . f)
453 fmap h (FromJSONKeyValue f) = FromJSONKeyValue (fmap h . f)
@@ -478,9 +461,7 @@ instance Functor FromJSONKeyFunction where
479-- On pre GHC 7.8 this is unconstrainted function.
462-- On pre GHC 7.8 this is unconstrainted function.
480fromJSONKeyCoerce ::
463fromJSONKeyCoerce ::
482 Coercible Text a =>
464 Coercible Text a =>
484 FromJSONKeyFunction a
465 FromJSONKeyFunction a
485fromJSONKeyCoerce = FromJSONKeyCoerce CoerceText
466fromJSONKeyCoerce = FromJSONKeyCoerce CoerceText
@@ -488,29 +469,18 @@ fromJSONKeyCoerce = FromJSONKeyCoerce CoerceText
489-- See note on 'fromJSONKeyCoerce'.
470-- See note on 'fromJSONKeyCoerce'.
490coerceFromJSONKeyFunction ::
471coerceFromJSONKeyFunction ::
492 Coercible a b =>
472 Coercible a b =>
494 FromJSONKeyFunction a -> FromJSONKeyFunction b
473 FromJSONKeyFunction a -> FromJSONKeyFunction b
496coerceFromJSONKeyFunction = coerce
474coerceFromJSONKeyFunction = coerce
498−coerceFromJSONKeyFunction (FromJSONKeyCoerce CoerceText) = FromJSONKeyCoerce CoerceText
499−coerceFromJSONKeyFunction (FromJSONKeyText f) = FromJSONKeyText (coerce' . f)
500−coerceFromJSONKeyFunction (FromJSONKeyTextParser f) = FromJSONKeyTextParser (fmap coerce' . f)
501−coerceFromJSONKeyFunction (FromJSONKeyValue f) = FromJSONKeyValue (fmap coerce' . f)
505 "FromJSONKeyCoerce: fmap id" forall (x :: FromJSONKeyFunction a).
477 "FromJSONKeyCoerce: fmap id" forall (x :: FromJSONKeyFunction a).
506 fmap id x = x
478 fmap id x = x
510 "FromJSONKeyCoerce: fmap coerce" forall x .
481 "FromJSONKeyCoerce: fmap coerce" forall x .
511 fmap coerce x = coerceFromJSONKeyFunction x
482 fmap coerce x = coerceFromJSONKeyFunction x
515-- | Same as 'fmap'. Provided for the consistency with 'ToJSONKeyFunction'.
485-- | Same as 'fmap'. Provided for the consistency with 'ToJSONKeyFunction'.
516mapFromJSONKeyFunction :: (a -> b) -> FromJSONKeyFunction a -> FromJSONKeyFunction b
486mapFromJSONKeyFunction :: (a -> b) -> FromJSONKeyFunction a -> FromJSONKeyFunction b
@@ -797,13 +767,13 @@ withBoundedScientific' f v = withBoundedScientific_ id f v
797-- | A variant of 'withBoundedScientific_' parameterized by a function to apply
767-- | A variant of 'withBoundedScientific_' parameterized by a function to apply
798-- to the 'Parser' in case of failure.
768-- to the 'Parser' in case of failure.
799withBoundedScientific_ :: (Parser a -> Parser a) -> (Scientific -> Parser a) -> Value -> Parser a
769withBoundedScientific_ :: (Parser a -> Parser a) -> (Scientific -> Parser a) -> Value -> Parser a
800−withBoundedScientific_ whenFail f v@(Number scientific) =
770+withBoundedScientific_ whenFail f (Number scientific) =
801− if exponent > 1024
771+ if exp10 > 1024
802 then whenFail (fail msg)
772 then whenFail (fail msg)
803 else f scientific
773 else f scientific
805− exponent = base10Exponent scientific
775+ exp10 = base10Exponent scientific
806− msg = "found a number with exponent " ++ show exponent ++ ", but it must not be greater than 1024"
776+ msg = "found a number with exponent " ++ show exp10 ++ ", but it must not be greater than 1024"
807withBoundedScientific_ whenFail _ v =
777withBoundedScientific_ whenFail _ v =
808 whenFail (typeMismatch "Number" v)
778 whenFail (typeMismatch "Number" v)
809{-# INLINE withBoundedScientific_ #-}
779{-# INLINE withBoundedScientific_ #-}
@@ -823,7 +793,7 @@ withBool name _ v = prependContext name (typeMismatch "Boolean" v)
823-- | Decode a nested JSON-encoded string.
793-- | Decode a nested JSON-encoded string.
824withEmbeddedJSON :: String -> (Value -> Parser a) -> Value -> Parser a
794withEmbeddedJSON :: String -> (Value -> Parser a) -> Value -> Parser a
825withEmbeddedJSON _ innerParser (String txt) =
795withEmbeddedJSON _ innerParser (String txt) =
826− either fail innerParser $ eitherDecode (Compat.fromStrict $ T.encodeUtf8 txt)
796+ either fail innerParser $ eitherDecode (L.fromStrict $ T.encodeUtf8 txt)
828 eitherDecode = eitherFormatError . eitherDecodeWith jsonEOF ifromJSON
798 eitherDecode = eitherFormatError . eitherDecodeWith jsonEOF ifromJSON
829 eitherFormatError = either (Left . uncurry formatError) Right
799 eitherFormatError = either (Left . uncurry formatError) Right
@@ -1991,7 +1961,6 @@ instance FromJSON DotNetTime where
1991-- primitive
1961-- primitive
1992-------------------------------------------------------------------------------
1962-------------------------------------------------------------------------------
1994−#if MIN_VERSION_base(4,7,0)
1995instance FromJSON a => FromJSON (PM.Array a) where
1964instance FromJSON a => FromJSON (PM.Array a) where
1996 -- note: we could do better than this if vector exposed the data
1965 -- note: we could do better than this if vector exposed the data
1997 -- constructor in Data.Vector.
1966 -- constructor in Data.Vector.
@@ -2009,7 +1978,6 @@ instance (PM.PrimUnlifted a,FromJSON a) => FromJSON (PM.UnliftedArray a) where
2009 parseJSON = fmap Exts.fromList . parseJSON
1978 parseJSON = fmap Exts.fromList . parseJSON
2014-------------------------------------------------------------------------------
1982-------------------------------------------------------------------------------