on master help sign in
Parse a number using the new scientific parser

The old rational parser applied realToFrac (fromRational . toRational) to the Scientific number to construct a new Scientific number. This had the disadvantage that scientific numbers with big exponents like 1e1000000000 are converted from (Scientific 1 1000000000) to (Scientific (1*10^1000000000) 0). If the Integer coefficient of the latter is later evaluated it will allocate all memory. This is the first step needed to fix #198.

commit03e44ddba3faf3afd4e6c761f2de3de0414ef715 authorBas van Dijk <v.dijk.bas@gmail.com> dateWed 30 Apr 2014, 11:12 (12 years ago) parentfef021a
2 files changed+4−4
Data/Aeson/Parser/Internal.hs+3−3 aeson.cabal+1−1
Data/Aeson/Parser/Internal.hs+3−3
@@ -43,7 +43,7 @@ import Data.ByteString.Lazy.Builder
4343
4444import Control.Applicative ((*>), (<$>), (<*), liftA2, pure)
4545import Data.Aeson.Types (Result(..), Value(..))
46−import Data.Attoparsec.Char8 (Parser, char, endOfInput, rational,
46+import Data.Attoparsec.Char8 (Parser, char, endOfInput, scientific,
4747 skipSpace, string)
4848import Data.Bits ((.|.), shiftL)
4949import Data.ByteString (ByteString)
@@ -173,7 +173,7 @@ value = do
173173 C_t -> string "true" *> pure (Bool True)
174174 C_n -> string "null" *> pure Null
175175 _ | w >= 48 && w <= 57 || w == 45
176− -> Number <$> rational
176+ -> Number <$> scientific
177177 | otherwise -> fail "not a valid json value"
178178
179179-- | Strict version of 'value'. See also 'json''.
@@ -191,7 +191,7 @@ value' = do
191191 C_n -> string "null" *> pure Null
192192 _ | w >= 48 && w <= 57 || w == 45
193193 -> do
194− !n <- rational
194+ !n <- scientific
195195 return (Number n)
196196 | otherwise -> fail "not a valid json value"
197197
aeson.cabal+1−1
@@ -113,7 +113,7 @@ library
113113 Data.Aeson.Types.Generic
114114
115115 build-depends:
116− attoparsec >= 0.10.2.1,
116+ attoparsec >= 0.11.3.0,
117117 base == 4.*,
118118 containers,
119119 deepseq,