on master help sign in
Bump lower bound for aeson + drop code for aeson <=0.7.0
4beaa8bMatej Kollar
Data/Yaml.hs−8
@@ -71,14 +71,10 @@ import qualified Data.Vector as V
71import Data.Text.Encoding (encodeUtf8)
71import Data.Text.Encoding (encodeUtf8)
72import qualified Data.HashMap.Strict as M
72import qualified Data.HashMap.Strict as M
73import qualified Data.HashSet as HashSet
73import qualified Data.HashSet as HashSet
74−#if MIN_VERSION_aeson(0, 7, 0)
75import qualified Data.Text.Encoding as TE
74import qualified Data.Text.Encoding as TE
76import qualified Data.Text.Lazy as TL
75import qualified Data.Text.Lazy as TL
77import Data.Text.Lazy.Builder (toLazyText)
76import Data.Text.Lazy.Builder (toLazyText)
78import Data.Aeson.Encode (encodeToTextBuilder)
77import Data.Aeson.Encode (encodeToTextBuilder)
79−#else
80−import qualified Data.ByteString.Char8 as S8
81−#endif
82import Control.Monad.Trans.Resource (runResourceT)
78import Control.Monad.Trans.Resource (runResourceT)
83
79
84import Data.Yaml.Internal
80import Data.Yaml.Internal
@@ -130,12 +126,8 @@ objToEvents' (String s) rest =
130objToEvents' Null rest = EventScalar "null" NullTag PlainNoTag Nothing : rest
126objToEvents' Null rest = EventScalar "null" NullTag PlainNoTag Nothing : rest
131objToEvents' (Bool True) rest = EventScalar "true" BoolTag PlainNoTag Nothing : rest
127objToEvents' (Bool True) rest = EventScalar "true" BoolTag PlainNoTag Nothing : rest
132objToEvents' (Bool False) rest = EventScalar "false" BoolTag PlainNoTag Nothing : rest
128objToEvents' (Bool False) rest = EventScalar "false" BoolTag PlainNoTag Nothing : rest
133−#if MIN_VERSION_aeson(0,7,0)
134-- Use aeson's implementation which gets rid of annoying decimal points
129-- Use aeson's implementation which gets rid of annoying decimal points
135objToEvents' n@Number{} rest = EventScalar (TE.encodeUtf8 $ TL.toStrict $ toLazyText $ encodeToTextBuilder n) IntTag PlainNoTag Nothing : rest
130objToEvents' n@Number{} rest = EventScalar (TE.encodeUtf8 $ TL.toStrict $ toLazyText $ encodeToTextBuilder n) IntTag PlainNoTag Nothing : rest
136−#else
137−objToEvents' (Number n) rest = EventScalar (S8.pack $ show n) IntTag PlainNoTag Nothing : rest
138−#endif
139
131
140pairToEvents :: Pair -> [Y.Event] -> [Y.Event]
132pairToEvents :: Pair -> [Y.Event] -> [Y.Event]
141pairToEvents (k, v) rest =
133pairToEvents (k, v) rest =
Data/Yaml/Builder.hs−16
@@ -23,24 +23,18 @@ import Data.ByteString (ByteString)
23import Text.Libyaml
23import Text.Libyaml
24import Data.Yaml.Internal
24import Data.Yaml.Internal
25import Data.Text (Text)
25import Data.Text (Text)
26−#if MIN_VERSION_aeson(0, 7, 0)
27import Data.Scientific (Scientific)
26import Data.Scientific (Scientific)
28import Data.Aeson.Types (Value(..))
27import Data.Aeson.Types (Value(..))
29−#endif
30import qualified Data.HashSet as HashSet
28import qualified Data.HashSet as HashSet
31import Data.Text.Encoding (encodeUtf8)
29import Data.Text.Encoding (encodeUtf8)
32import System.IO.Unsafe (unsafePerformIO)
30import System.IO.Unsafe (unsafePerformIO)
33import Control.Arrow (second)
31import Control.Arrow (second)
34import qualified Data.ByteString.Char8 as S8
32import qualified Data.ByteString.Char8 as S8
35import Control.Monad.Trans.Resource (runResourceT)
33import Control.Monad.Trans.Resource (runResourceT)
36−#if MIN_VERSION_aeson(0, 7, 0)
37import qualified Data.Text.Encoding as TE
34import qualified Data.Text.Encoding as TE
38import qualified Data.Text.Lazy as TL
35import qualified Data.Text.Lazy as TL
39import Data.Text.Lazy.Builder (toLazyText)
36import Data.Text.Lazy.Builder (toLazyText)
40import Data.Aeson.Encode (encodeToTextBuilder)
37import Data.Aeson.Encode (encodeToTextBuilder)
41−#else
42−import Data.Attoparsec.Number
43−#endif
44import Prelude hiding (null)
38import Prelude hiding (null)
45
39
46(.=) :: ToYaml a => Text -> a -> (Text, YamlBuilder)
40(.=) :: ToYaml a => Text -> a -> (Text, YamlBuilder)
@@ -89,22 +83,12 @@ string s =
89 | otherwise = EventScalar (encodeUtf8 s) StrTag PlainNoTag Nothing
83 | otherwise = EventScalar (encodeUtf8 s) StrTag PlainNoTag Nothing
90
84
91-- Use aeson's implementation which gets rid of annoying decimal points
85-- Use aeson's implementation which gets rid of annoying decimal points
92−#if MIN_VERSION_aeson(0, 7, 0)
93scientific :: Scientific -> YamlBuilder
86scientific :: Scientific -> YamlBuilder
94scientific n = YamlBuilder (EventScalar (TE.encodeUtf8 $ TL.toStrict $ toLazyText $ encodeToTextBuilder (Number n)) IntTag PlainNoTag Nothing :)
87scientific n = YamlBuilder (EventScalar (TE.encodeUtf8 $ TL.toStrict $ toLazyText $ encodeToTextBuilder (Number n)) IntTag PlainNoTag Nothing :)
95−#else
96−scientific :: Number -> YamlBuilder
97−scientific n = YamlBuilder (EventScalar (S8.pack $ show n) IntTag PlainNoTag Nothing :)
98−#endif
99
88
100{-# DEPRECATED number "Use scientific" #-}
89{-# DEPRECATED number "Use scientific" #-}
101−#if MIN_VERSION_aeson(0,7,0)
102number :: Scientific -> YamlBuilder
90number :: Scientific -> YamlBuilder
103number = scientific
91number = scientific
104−#else
105−number :: Number -> YamlBuilder
106−number n = YamlBuilder (EventScalar (S8.pack $ show n) IntTag PlainNoTag Nothing :)
107−#endif
108
92
109bool :: Bool -> YamlBuilder
93bool :: Bool -> YamlBuilder
110bool True = YamlBuilder (EventScalar "true" BoolTag PlainNoTag Nothing :)
94bool True = YamlBuilder (EventScalar "true" BoolTag PlainNoTag Nothing :)
Data/Yaml/Internal.hs−12
@@ -38,13 +38,8 @@ import Data.Text.Encoding (decodeUtf8With)
38import Data.Text.Encoding.Error (lenientDecode)
38import Data.Text.Encoding.Error (lenientDecode)
39import qualified Data.HashMap.Strict as M
39import qualified Data.HashMap.Strict as M
40import Data.Typeable
40import Data.Typeable
41−#if MIN_VERSION_aeson(0, 7, 0)
42import qualified Data.Attoparsec.Text as Atto
41import qualified Data.Attoparsec.Text as Atto
43import Data.Scientific (Scientific)
42import Data.Scientific (Scientific)
44−#else
45−import Data.Text.Read
46−import Data.Attoparsec.Number
47−#endif
48import Control.Monad.Trans.Resource (ResourceT, runResourceT)
43import Control.Monad.Trans.Resource (ResourceT, runResourceT)
49import qualified Data.HashSet as HashSet
44import qualified Data.HashSet as HashSet
50
45
@@ -163,20 +158,13 @@ textToValue _ _ t
163 | t `elem` ["null", "Null", "NULL", "~", ""] = Null
158 | t `elem` ["null", "Null", "NULL", "~", ""] = Null
164 | any (t `isLike`) ["y", "yes", "on", "true"] = Bool True
159 | any (t `isLike`) ["y", "yes", "on", "true"] = Bool True
165 | any (t `isLike`) ["n", "no", "off", "false"] = Bool False
160 | any (t `isLike`) ["n", "no", "off", "false"] = Bool False
166−#if MIN_VERSION_aeson(0, 7, 0)
167 | Right x <- textToScientific t = Number x
161 | Right x <- textToScientific t = Number x
168−#else
169− | Right (x, "") <- signed decimal t = Number $ I x
170− | Right (x, "") <- double t = Number $ D x
171−#endif
172 | otherwise = String t
162 | otherwise = String t
173 where x `isLike` ref = x `elem` [ref, T.toUpper ref, titleCased]
163 where x `isLike` ref = x `elem` [ref, T.toUpper ref, titleCased]
174 where titleCased = toUpper (T.head ref) `T.cons` T.tail ref
164 where titleCased = toUpper (T.head ref) `T.cons` T.tail ref
175
165
176−#if MIN_VERSION_aeson(0, 7, 0)
177textToScientific :: Text -> Either String Scientific
166textToScientific :: Text -> Either String Scientific
178textToScientific = Atto.parseOnly (Atto.scientific <* Atto.endOfInput)
167textToScientific = Atto.parseOnly (Atto.scientific <* Atto.endOfInput)
179−#endif
180
168
181parseO :: C.Sink Event Parse Value
169parseO :: C.Sink Event Parse Value
182parseO = do
170parseO = do
test/Data/YamlSpec.hs−4
@@ -148,9 +148,7 @@ spec = do
148 it "serialization of +123 #64" $ do
148 it "serialization of +123 #64" $ do
149 D.decode (D.encode ("+123" :: String)) `shouldBe` Just ("+123" :: String)
149 D.decode (D.encode ("+123" :: String)) `shouldBe` Just ("+123" :: String)
150
150
151−#if MIN_VERSION_aeson(0, 7, 0)
152 it "preserves Scientific precision" casePreservesScientificPrecision
151 it "preserves Scientific precision" casePreservesScientificPrecision
153−#endif
154
152
155
153
156specialStrings :: [T.Text]
154specialStrings :: [T.Text]
@@ -470,7 +468,6 @@ caseIssue49 =
470 where
468 where
471 src = "---\na:\n &id5 value: 1.0\nb:\n *id5: 1.2"
469 src = "---\na:\n &id5 value: 1.0\nb:\n *id5: 1.2"
472
470
473−#if MIN_VERSION_aeson(0, 7, 0)
474-- | We cannot guarantee this before aeson started using 'Scientific'.
471-- | We cannot guarantee this before aeson started using 'Scientific'.
475casePreservesScientificPrecision :: Assertion
472casePreservesScientificPrecision :: Assertion
476casePreservesScientificPrecision = do
473casePreservesScientificPrecision = do
@@ -487,4 +484,3 @@ casePreservesScientificPrecision = do
487 -- results, because of <https://github.com/bos/text/issues/34>.
484 -- results, because of <https://github.com/bos/text/issues/34>.
488 D.decodeEither "x: 9.78159610558926e-5" @?= Right (object
485 D.decodeEither "x: 9.78159610558926e-5" @?= Right (object
489 [ "x" .= D.Number (read "9.78159610558926e-5") ])
486 [ "x" .= D.Number (read "9.78159610558926e-5") ])
490−#endif
yaml.cabal+4−4
@@ -43,7 +43,7 @@ library
43 , bytestring >= 0.9.1.4
43 , bytestring >= 0.9.1.4
44 , conduit >= 1.1.0 && < 1.3
44 , conduit >= 1.1.0 && < 1.3
45 , resourcet >= 0.3 && < 1.2
45 , resourcet >= 0.3 && < 1.2
46− , aeson >= 0.5
46+ , aeson >= 0.7
47 , containers
47 , containers
48 , unordered-containers
48 , unordered-containers
49 , vector
49 , vector
@@ -91,7 +91,7 @@ executable yaml2json
91 build-depends: base >= 4 && < 5
91 build-depends: base >= 4 && < 5
92 , yaml
92 , yaml
93 , bytestring >= 0.9.1.4
93 , bytestring >= 0.9.1.4
94− , aeson >= 0.5
94+ , aeson >= 0.7
95
95
96executable json2yaml
96executable json2yaml
97 if flag(no-exe)
97 if flag(no-exe)
@@ -104,7 +104,7 @@ executable json2yaml
104 build-depends: base >= 4 && < 5
104 build-depends: base >= 4 && < 5
105 , yaml
105 , yaml
106 , bytestring >= 0.9.1.4
106 , bytestring >= 0.9.1.4
107− , aeson >= 0.5
107+ , aeson >= 0.7
108
108
109
109
110test-suite spec
110test-suite spec
@@ -122,7 +122,7 @@ test-suite spec
122 , conduit
122 , conduit
123 , yaml
123 , yaml
124 , text
124 , text
125− , aeson
125+ , aeson >= 0.7
126 , unordered-containers
126 , unordered-containers
127 , vector
127 , vector
128 , resourcet
128 , resourcet