on master help sign in
Fix number parsing
045e8ccMichael Snoyman
Data/Yaml.hs+13−3
@@ -84,9 +84,13 @@ import Data.Text.Encoding (encodeUtf8, decodeUtf8With)
84import Data.Text.Encoding.Error (lenientDecode)
84import Data.Text.Encoding.Error (lenientDecode)
85import qualified Data.HashMap.Strict as M
85import qualified Data.HashMap.Strict as M
86import Data.Typeable
86import Data.Typeable
87−import Data.Attoparsec.ByteString (parseOnly)
88−import Data.Aeson.Parser (value)
89import qualified Data.HashSet as HashSet
87import qualified Data.HashSet as HashSet
88+import Data.Text.Read
89+#if MIN_VERSION_aeson(0, 7, 0)
90+import Data.Scientific (fromFloatDigits)
91+#else
92+import Data.Attoparsec.Number
93+#endif
90
94
91encode :: ToJSON a => a -> ByteString
95encode :: ToJSON a => a -> ByteString
92encode obj = unsafePerformIO $
96encode obj = unsafePerformIO $
@@ -210,7 +214,13 @@ textToValue _ _ t
210 | t `elem` ["null", "Null", "NULL", "~", ""] = Null
214 | t `elem` ["null", "Null", "NULL", "~", ""] = Null
211 | any (t `isLike`) ["y", "yes", "on", "true"] = Bool True
215 | any (t `isLike`) ["y", "yes", "on", "true"] = Bool True
212 | any (t `isLike`) ["n", "no", "off", "false"] = Bool False
216 | any (t `isLike`) ["n", "no", "off", "false"] = Bool False
213− | Right (Number n) <- parseOnly value (encodeUtf8 t) = Number n
217+#if MIN_VERSION_aeson(0, 7, 0)
218+ | Right (x, "") <- signed decimal t = Number $ fromIntegral (x :: Integer)
219+ | Right (x, "") <- double t = Number $ fromFloatDigits x
220+#else
221+ | Right (x, "") <- signed decimal t = Number $ I x
222+ | Right (x, "") <- double t = Number $ D x
223+#endif
214 | otherwise = String t
224 | otherwise = String t
215 where x `isLike` ref = x `elem` [ref, T.toUpper ref, titleCased]
225 where x `isLike` ref = x `elem` [ref, T.toUpper ref, titleCased]
216 where titleCased = toUpper (T.head ref) `T.cons` T.tail ref
226 where titleCased = toUpper (T.head ref) `T.cons` T.tail ref
yaml.cabal+2−1
@@ -1,5 +1,5 @@
1name: yaml
1name: yaml
2−version: 0.8.5.3
2+version: 0.8.5.4
3license: BSD3
3license: BSD3
4license-file: LICENSE
4license-file: LICENSE
5author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov
5author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov
@@ -49,6 +49,7 @@ library
49 , vector
49 , vector
50 , text
50 , text
51 , attoparsec
51 , attoparsec
52+ , scientific
52 exposed-modules: Text.Libyaml
53 exposed-modules: Text.Libyaml
53 Data.Yaml
54 Data.Yaml
54 ghc-options: -Wall
55 ghc-options: -Wall