yaml 0.8.5.3 → 0.8.5.4
raw patch · 4 files changed
+18/−4 lines, 4 filesdep +scientific
Dependencies added: scientific
Files
- Data/Yaml.hs +13/−3
- test/json.yaml +1/−0
- test/main.hs +2/−0
- yaml.cabal +2/−1
Data/Yaml.hs view
@@ -84,9 +84,13 @@ import Data.Text.Encoding.Error (lenientDecode) import qualified Data.HashMap.Strict as M import Data.Typeable-import Data.Attoparsec.ByteString (parseOnly)-import Data.Aeson.Parser (value) import qualified Data.HashSet as HashSet+import Data.Text.Read+#if MIN_VERSION_aeson(0, 7, 0)+import Data.Scientific (fromFloatDigits)+#else+import Data.Attoparsec.Number+#endif encode :: ToJSON a => a -> ByteString encode obj = unsafePerformIO $@@ -210,7 +214,13 @@ | t `elem` ["null", "Null", "NULL", "~", ""] = Null | any (t `isLike`) ["y", "yes", "on", "true"] = Bool True | any (t `isLike`) ["n", "no", "off", "false"] = Bool False- | Right (Number n) <- parseOnly value (encodeUtf8 t) = Number n+#if MIN_VERSION_aeson(0, 7, 0)+ | Right (x, "") <- signed decimal t = Number $ fromIntegral (x :: Integer)+ | Right (x, "") <- double t = Number $ fromFloatDigits x+#else+ | Right (x, "") <- signed decimal t = Number $ I x+ | Right (x, "") <- double t = Number $ D x+#endif | otherwise = String t where x `isLike` ref = x `elem` [ref, T.toUpper ref, titleCased] where titleCased = toUpper (T.head ref) `T.cons` T.tail ref
test/json.yaml view
@@ -6,3 +6,4 @@ hash: key1: value1 key2: value2+extrastring: 1234-foo
test/main.hs view
@@ -34,6 +34,7 @@ , number :: Int , anArray :: Vector Text , hash :: HashMap Text Text+ , extrastring :: Text } deriving (Show, Eq) deriveJSON defaultOptions ''TestJSON@@ -119,6 +120,7 @@ , number = 2 , anArray = V.fromList ["a", "b"] , hash = HM.fromList [("key1", "value1"), ("key2", "value2")]+ , extrastring = "1234-foo" } describe "round-tripping of special scalars" $ do
yaml.cabal view
@@ -1,5 +1,5 @@ name: yaml-version: 0.8.5.3+version: 0.8.5.4 license: BSD3 license-file: LICENSE author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov @@ -49,6 +49,7 @@ , vector , text , attoparsec+ , scientific exposed-modules: Text.Libyaml Data.Yaml ghc-options: -Wall