@@ -178,26 +178,28 @@ parseRealFloat _ Null = pure (0/0)
178parseRealFloat expected v = typeMismatch expected v
178parseRealFloat expected v = typeMismatch expected v
179{-# INLINE parseRealFloat #-}
179{-# INLINE parseRealFloat #-}
181−truncateIntegral :: forall a. Integral a => String -> Scientific -> Parser a
181+parseIntegralFromScientific :: forall a. Integral a => String -> Scientific -> Parser a
182−truncateIntegral expected s =
182+parseIntegralFromScientific expected s =
183 case Scientific.floatingOrInteger s :: Either Double a of
183 case Scientific.floatingOrInteger s :: Either Double a of
184 Right x -> pure x
184 Right x -> pure x
185 Left _ -> fail $ "Floating number specified for " ++ expected ++ ": " ++ show s
185 Left _ -> fail $ "Floating number specified for " ++ expected ++ ": " ++ show s
186−{-# INLINE truncateIntegral #-}
186+{-# INLINE parseIntegralFromScientific #-}
188parseIntegral :: Integral a => String -> Value -> Parser a
188parseIntegral :: Integral a => String -> Value -> Parser a
189+parseIntegral expected =
189−parseIntegral expected = withScientific expected $ truncateIntegral expected
190+ withScientific expected $ parseIntegralFromScientific expected
190{-# INLINE parseIntegral #-}
191{-# INLINE parseIntegral #-}
192−truncateBoundedIntegral :: (Bounded a, Integral a) => String -> Scientific -> Parser a
193+parseBoundedIntegralFromScientific :: (Bounded a, Integral a) => String -> Scientific -> Parser a
193−truncateBoundedIntegral expected s = maybe
194+parseBoundedIntegralFromScientific expected s = maybe
194 (fail $ expected ++ " is either floating or will cause over or underflow: " ++ show s)
195 (fail $ expected ++ " is either floating or will cause over or underflow: " ++ show s)
196 (Scientific.toBoundedInteger s)
197 (Scientific.toBoundedInteger s)
197−{-# INLINE truncateBoundedIntegral #-}
198+{-# INLINE parseBoundedIntegralFromScientific #-}
199parseBoundedIntegral :: (Bounded a, Integral a) => String -> Value -> Parser a
200parseBoundedIntegral :: (Bounded a, Integral a) => String -> Value -> Parser a
200−parseBoundedIntegral expected = withScientific expected $ truncateBoundedIntegral expected
201+parseBoundedIntegral expected =
202+ withScientific expected $ parseBoundedIntegralFromScientific expected
201{-# INLINE parseBoundedIntegral #-}
203{-# INLINE parseBoundedIntegral #-}
203parseScientificText :: Text -> Parser Scientific
205parseScientificText :: Text -> Parser Scientific
@@ -208,12 +210,12 @@ parseScientificText
209parseIntegralText :: Integral a => String -> Text -> Parser a
211parseIntegralText :: Integral a => String -> Text -> Parser a
210parseIntegralText expected t =
212parseIntegralText expected t =
211− parseScientificText t >>= truncateIntegral expected
213+ parseScientificText t >>= parseIntegralFromScientific expected
212{-# INLINE parseIntegralText #-}
214{-# INLINE parseIntegralText #-}
214parseBoundedIntegralText :: (Bounded a, Integral a) => String -> Text -> Parser a
216parseBoundedIntegralText :: (Bounded a, Integral a) => String -> Text -> Parser a
215parseBoundedIntegralText expected t =
217parseBoundedIntegralText expected t =
216− parseScientificText t >>= truncateBoundedIntegral expected
218+ parseScientificText t >>= parseBoundedIntegralFromScientific expected
218parseOptionalFieldWith :: (Value -> Parser (Maybe a))
220parseOptionalFieldWith :: (Value -> Parser (Maybe a))
219 -> Object -> Text -> Parser (Maybe a)
221 -> Object -> Text -> Parser (Maybe a)