packages feed

dhall-json 1.2.3 → 1.2.4

raw patch · 5 files changed

+75/−34 lines, 5 filesdep +vectordep −insert-ordered-containersdep ~bytestringdep ~dhallPVP ok

version bump matches the API change (PVP)

Dependencies added: vector

Dependencies removed: insert-ordered-containers

Dependency ranges changed: bytestring, dhall

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -1,3 +1,15 @@+1.2.4++* Build against `dhall-1.18.0`+    * See: https://github.com/dhall-lang/dhall-json/pull/61+    * See: https://github.com/dhall-lang/dhall-json/pull/63+    * See: https://github.com/dhall-lang/dhall-json/pull/67+* New `dhall-to-yaml` `--documents` flag for generating split documents+    * See: https://github.com/dhall-lang/dhall-json/pull/59+* Build against `yaml-0.10.2.0`+    * This improves the multi-line string literals in generated YAML+    * See: https://github.com/dhall-lang/dhall-json/pull/57+ 1.2.3  * Correctly handle nested association lists
dhall-json.cabal view
@@ -1,5 +1,5 @@ Name: dhall-json-Version: 1.2.3+Version: 1.2.4 Cabal-Version: >=1.8.0.2 Build-Type: Simple Tested-With: GHC == 7.10.2, GHC == 8.0.1@@ -35,8 +35,7 @@     Build-Depends:         base                      >= 4.8.0.0  && < 5   ,         aeson                     >= 1.0.0.0  && < 1.5 ,-        dhall                     >= 1.15.0   && < 1.18,-        insert-ordered-containers                < 1.14,+        dhall                     >= 1.18.0   && < 1.19,         optparse-applicative      >= 0.14.0.0 && < 0.15,         text                      >= 0.11.1.0 && < 1.3 ,         unordered-containers                     < 0.3@@ -67,6 +66,7 @@         dhall-json                             ,         optparse-applicative                   ,         yaml                 >= 0.5.0 && < 0.11,+        vector                                 ,         text     GHC-Options: -Wall @@ -77,6 +77,7 @@     Build-Depends:         base,         aeson             ,+        bytestring        ,         dhall             ,         dhall-json        ,         tasty       <  1.2,
dhall-to-yaml/Main.hs view
@@ -12,6 +12,7 @@ import qualified Control.Exception import qualified Data.ByteString import qualified Data.Text.IO+import qualified Data.Vector import qualified Data.Yaml import qualified Dhall import qualified Dhall.JSON@@ -23,6 +24,7 @@ data Options = Options     { explain    :: Bool     , omitNull   :: Bool+    , documents  :: Bool     , conversion :: Conversion     } @@ -30,6 +32,7 @@ parseOptions = Options.Applicative.helper <*> do     explain    <- parseExplain     omitNull   <- parseOmitNull+    documents  <- parseDocuments     conversion <- Dhall.JSON.parseConversion     return (Options {..})   where@@ -45,6 +48,12 @@             <>  Options.Applicative.help "Omit record fields that are null"             ) +    parseDocuments =+        Options.Applicative.switch+            (   Options.Applicative.long "documents"+            <>  Options.Applicative.help "If given a Dhall list, output a document for every element"+            )+ parserInfo :: ParserInfo Options parserInfo =     Options.Applicative.info@@ -68,7 +77,14 @@          json <- omittingNull <$> explaining (Dhall.JSON.codeToValue conversion "(stdin)" stdin) -        Data.ByteString.putStr $ Data.Yaml.encode json +        let yaml = case (documents, json) of+              (True, Data.Yaml.Array elems)+                -> Data.ByteString.intercalate "\n---\n"+                   $ fmap Data.Yaml.encode+                   $ Data.Vector.toList elems+              _ -> Data.Yaml.encode json++        Data.ByteString.putStr yaml  handle :: IO a -> IO a handle = Control.Exception.handle handler
src/Dhall/JSON.hs view
@@ -174,24 +174,23 @@ import Control.Applicative (empty, (<|>)) import Control.Monad (guard) import Control.Exception (Exception, throwIO)-import Data.Aeson (Value(..))-import Data.HashMap.Strict.InsOrd (InsOrdHashMap)-import Data.Monoid ((<>))+import Data.Aeson (Value(..), ToJSON(..))+import Data.Monoid ((<>), mempty) import Data.Text (Text) import Data.Typeable (Typeable) import Dhall.Core (Expr) import Dhall.TypeCheck (X)+import Dhall.Map (Map) import Options.Applicative (Parser) -import qualified Data.Aeson import qualified Data.Foldable import qualified Data.HashMap.Strict-import qualified Data.HashMap.Strict.InsOrd import qualified Data.List import qualified Data.Ord import qualified Data.Text import qualified Dhall.Core import qualified Dhall.Import+import qualified Dhall.Map import qualified Dhall.Parser import qualified Dhall.TypeCheck import qualified Options.Applicative@@ -237,18 +236,23 @@ dhallToJSON e0 = loop (Dhall.Core.normalize e0)   where     loop e = case e of -        Dhall.Core.BoolLit a -> return (Data.Aeson.toJSON a)-        Dhall.Core.NaturalLit a -> return (Data.Aeson.toJSON a)-        Dhall.Core.IntegerLit a -> return (Data.Aeson.toJSON a)-        Dhall.Core.DoubleLit a -> return (Data.Aeson.toJSON a)+        Dhall.Core.BoolLit a -> return (toJSON a)+        Dhall.Core.NaturalLit a -> return (toJSON a)+        Dhall.Core.IntegerLit a -> return (toJSON a)+        Dhall.Core.DoubleLit a -> return (toJSON a)         Dhall.Core.TextLit (Dhall.Core.Chunks [] a) -> do-            return (Data.Aeson.toJSON a)+            return (toJSON a)         Dhall.Core.ListLit _ a -> do             a' <- traverse loop a-            return (Data.Aeson.toJSON a')+            return (toJSON a')         Dhall.Core.OptionalLit _ a -> do             a' <- traverse loop a-            return (Data.Aeson.toJSON a')+            return (toJSON a')+        Dhall.Core.Some a -> do+            a' <- loop a+            return (toJSON a')+        Dhall.Core.App Dhall.Core.None _ -> do+            return Data.Aeson.Null         Dhall.Core.RecordLit a ->             case toOrderedList a of                 [   (   "contents"@@ -270,16 +274,16 @@                     contents' <- loop contents                      let taggedValue =-                            Data.HashMap.Strict.InsOrd.fromList+                            Dhall.Map.fromList                                 [   (   field-                                    ,   Data.Aeson.toJSON alternativeName+                                    ,   toJSON alternativeName                                     )                                 ,   (   nestedField                                     ,   contents'                                     )                                 ] -                    return (Data.Aeson.toJSON taggedValue)+                    return (Data.Aeson.toJSON ( Dhall.Map.toMap taggedValue ))                  [   (   "contents"                     ,   Dhall.Core.UnionLit@@ -299,7 +303,7 @@                     )                  ] -> do                     let contents' =-                            Data.HashMap.Strict.InsOrd.insert+                            Dhall.Map.insert                                 field                                 (Dhall.Core.TextLit                                     (Dhall.Core.Chunks@@ -312,15 +316,14 @@                     loop (Dhall.Core.RecordLit contents')                 _ -> do                     a' <- traverse loop a-                    return (Data.Aeson.toJSON a')+                    return (Data.Aeson.toJSON (Dhall.Map.toMap a'))         Dhall.Core.UnionLit _ b _ -> loop b         _ -> Left (Unsupported e) -toOrderedList :: Ord k => InsOrdHashMap k v -> [(k, v)]+toOrderedList :: Ord k => Map k v -> [(k, v)] toOrderedList =         Data.List.sortBy (Data.Ord.comparing fst)-    .   Data.HashMap.Strict.toList-    .   Data.HashMap.Strict.InsOrd.toHashMap+    .   Dhall.Map.toList  -- | Omit record fields that are @null@ omitNull :: Value -> Value@@ -519,10 +522,10 @@              toKeyValue :: Expr s X -> Maybe (Text, Expr s X)             toKeyValue (Dhall.Core.RecordLit m) = do-                guard (Data.HashMap.Strict.InsOrd.size m == 2)+                guard (Data.Foldable.length m == 2) -                key   <- Data.HashMap.Strict.InsOrd.lookup mapKey   m-                value <- Data.HashMap.Strict.InsOrd.lookup mapValue m+                key   <- Dhall.Map.lookup mapKey   m+                value <- Dhall.Map.lookup mapValue m                  keyText <- case key of                     Dhall.Core.TextLit (Dhall.Core.Chunks [] keyText) ->@@ -540,10 +543,10 @@                     [] ->                         case a of                             Just (Dhall.Core.Record m) -> do-                                guard (Data.HashMap.Strict.InsOrd.size m == 2)-                                guard (Data.HashMap.Strict.InsOrd.member mapKey   m)-                                guard (Data.HashMap.Strict.InsOrd.member mapValue m)-                                return (Dhall.Core.RecordLit Data.HashMap.Strict.InsOrd.empty)+                                guard (Data.Foldable.length m == 2)+                                guard (Dhall.Map.member mapKey   m)+                                guard (Dhall.Map.member mapValue m)+                                return (Dhall.Core.RecordLit mempty)                             _ -> do                                 empty @@ -551,7 +554,7 @@                         keyValues <- traverse toKeyValue elements                          let recordLiteral =-                                Data.HashMap.Strict.InsOrd.fromList keyValues+                                Dhall.Map.fromList keyValues                          return (Dhall.Core.RecordLit recordLiteral) @@ -593,6 +596,14 @@           where             a' =      loop a             b' = fmap loop b++        Dhall.Core.Some a ->+            Dhall.Core.Some a'+          where+            a' = loop a++        Dhall.Core.None ->+            Dhall.Core.None          Dhall.Core.OptionalFold ->             Dhall.Core.OptionalFold
tasty/Main.hs view
@@ -8,6 +8,7 @@  import qualified Control.Exception import qualified Data.Aeson+import qualified Data.ByteString.Lazy import qualified Data.Text.IO import qualified Dhall.Import import qualified Dhall.JSON@@ -49,9 +50,9 @@             Left  exception   -> Control.Exception.throwIO exception             Right actualValue -> return actualValue -        result <- Data.Aeson.eitherDecodeFileStrict "./tasty/data/issue48.json"+        bytes <- Data.ByteString.Lazy.readFile "./tasty/data/issue48.json" -        expectedValue <- case result of+        expectedValue <- case Data.Aeson.eitherDecode bytes of             Left  string        -> fail string             Right expectedValue -> return expectedValue