yaml 0.8.14 → 0.8.15.1
raw patch · 7 files changed
+51/−13 lines, 7 filesdep ~aesondep ~attoparsecPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: aeson, attoparsec
API changes (from Hackage documentation)
Files
- ChangeLog.md +8/−0
- Data/Yaml.hs +0/−2
- Data/Yaml/Builder.hs +9/−3
- Data/Yaml/Internal.hs +8/−5
- Data/Yaml/Pretty.hs +1/−1
- test/Data/YamlSpec.hs +23/−0
- yaml.cabal +2/−2
ChangeLog.md view
@@ -1,3 +1,11 @@+## 0.8.15.1++* Compile with aeson below 0.7 [#70](https://github.com/snoyberg/yaml/pull/70)++## 0.8.15++* Parse `Scientific` directly, avoiding loss in precision. [#68](https://github.com/snoyberg/yaml/pull/68)+ ## 0.8.14 * Pretty print improvements for exceptions [#67](https://github.com/snoyberg/yaml/pull/67)
Data/Yaml.hs view
@@ -68,8 +68,6 @@ import qualified Data.Conduit as C import qualified Data.Conduit.List as CL import qualified Data.Vector as V-import Data.Text (Text)-import qualified Data.Text as T import Data.Text.Encoding (encodeUtf8) import qualified Data.HashMap.Strict as M import qualified Data.HashSet as HashSet
Data/Yaml/Builder.hs view
@@ -23,10 +23,11 @@ import Text.Libyaml import Data.Yaml.Internal import Data.Text (Text)+#if MIN_VERSION_aeson(0, 7, 0) import Data.Scientific (Scientific) import Data.Aeson.Types (Value(..))+#endif import qualified Data.HashSet as HashSet-import qualified Data.Text as T import Data.Text.Encoding (encodeUtf8) import System.IO.Unsafe (unsafePerformIO) import Control.Arrow (second)@@ -38,7 +39,7 @@ import Data.Text.Lazy.Builder (toLazyText) import Data.Aeson.Encode (encodeToTextBuilder) #else-import qualified Data.ByteString.Char8 as S8+import Data.Attoparsec.Number #endif import Prelude hiding (null) @@ -88,8 +89,13 @@ | otherwise = EventScalar (encodeUtf8 s) StrTag PlainNoTag Nothing -- Use aeson's implementation which gets rid of annoying decimal points+#if MIN_VERSION_aeson(0, 7, 0) scientific :: Scientific -> YamlBuilder scientific n = YamlBuilder (EventScalar (TE.encodeUtf8 $ TL.toStrict $ toLazyText $ encodeToTextBuilder (Number n)) IntTag PlainNoTag Nothing :)+#else+scientific :: Number -> YamlBuilder+scientific n = YamlBuilder (EventScalar (S8.pack $ show n) IntTag PlainNoTag Nothing :)+#endif {-# DEPRECATED number "Use scientific" #-} #if MIN_VERSION_aeson(0,7,0)@@ -97,7 +103,7 @@ number = scientific #else number :: Number -> YamlBuilder-number n rest = YamlBuilder (EventScalar (S8.pack $ show n) IntTag PlainNoTag Nothing :)+number n = YamlBuilder (EventScalar (S8.pack $ show n) IntTag PlainNoTag Nothing :) #endif bool :: Bool -> YamlBuilder
Data/Yaml/Internal.hs view
@@ -19,7 +19,6 @@ import Text.Libyaml hiding (encode, decode, encodeFile, decodeFile) import Data.ByteString (ByteString) import qualified Data.Map as Map-import Data.Maybe (isNothing) import Control.Exception import Control.Exception.Enclosed import Control.Monad.Trans.State@@ -37,10 +36,11 @@ import Data.Text.Encoding.Error (lenientDecode) import qualified Data.HashMap.Strict as M import Data.Typeable-import Data.Text.Read #if MIN_VERSION_aeson(0, 7, 0)-import Data.Scientific (fromFloatDigits)+import qualified Data.Attoparsec.Text as Atto+import Data.Scientific (Scientific) #else+import Data.Text.Read import Data.Attoparsec.Number #endif import Control.Monad.Trans.Resource (ResourceT, runResourceT)@@ -162,8 +162,7 @@ | any (t `isLike`) ["y", "yes", "on", "true"] = Bool True | any (t `isLike`) ["n", "no", "off", "false"] = Bool False #if MIN_VERSION_aeson(0, 7, 0)- | Right (x, "") <- signed decimal t = Number $ fromIntegral (x :: Integer)- | Right (x, "") <- double t = Number $ fromFloatDigits x+ | Right x <- textToScientific t = Number x #else | Right (x, "") <- signed decimal t = Number $ I x | Right (x, "") <- double t = Number $ D x@@ -172,6 +171,10 @@ where x `isLike` ref = x `elem` [ref, T.toUpper ref, titleCased] where titleCased = toUpper (T.head ref) `T.cons` T.tail ref +#if MIN_VERSION_aeson(0, 7, 0)+textToScientific :: Text -> Either String Scientific+textToScientific = Atto.parseOnly (Atto.scientific <* Atto.endOfInput)+#endif parseO :: C.Sink Event Parse Value parseO = do
Data/Yaml/Pretty.hs view
@@ -48,7 +48,7 @@ go (Array a) = array (fmap go $ V.toList a) go Null = null go (String s) = string s- go (Number n) = number n+ go (Number n) = scientific n go (Bool b) = bool b -- | Configurable 'encode'.
test/Data/YamlSpec.hs view
@@ -148,7 +148,11 @@ it "serialization of +123 #64" $ do D.decode (D.encode ("+123" :: String)) `shouldBe` Just ("+123" :: String) +#if MIN_VERSION_aeson(0, 7, 0)+ it "preserves Scientific precision" casePreservesScientificPrecision+#endif + specialStrings :: [T.Text] specialStrings = [ "fo\"o"@@ -465,3 +469,22 @@ ]) where src = "---\na:\n &id5 value: 1.0\nb:\n *id5: 1.2"++#if MIN_VERSION_aeson(0, 7, 0)+-- | We cannot guarantee this before aeson started using 'Scientific'.+casePreservesScientificPrecision :: Assertion+casePreservesScientificPrecision = do+ D.decodeEither "x: 1e-100000" @?= Right (object+ [ "x" .= D.Number (read "1e-100000") ])+ -- Note that this ought to work also without 'Scientific', given+ -- that @read (show "9.78159610558926e-5") == 9.78159610558926e-5@.+ -- However, it didn't work (and still doesn't work with aeson < 0.7)+ -- for two reasons:+ --+ -- * We use 'Data.Text.Read.double', which is not as accurate as it+ -- can be;+ -- * Even if we used 'Data.Text.Read.rational' we would not get good+ -- results, because of <https://github.com/bos/text/issues/34>.+ D.decodeEither "x: 9.78159610558926e-5" @?= Right (object+ [ "x" .= D.Number (read "9.78159610558926e-5") ])+#endif
yaml.cabal view
@@ -1,5 +1,5 @@ name: yaml-version: 0.8.14+version: 0.8.15.1 license: BSD3 license-file: LICENSE author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov @@ -48,7 +48,7 @@ , unordered-containers , vector , text- , attoparsec+ , attoparsec >= 0.11.3.0 , scientific , filepath , directory