summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabrielGonzalez <>2018-10-16 05:04:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2018-10-16 05:04:00 (GMT)
commitd9e28e12605e3f7b560f0db398dc670afb26d4b9 (patch)
tree3cfd69c9bd3fd07741135c5f7ea92145cb592c29
parentc5e65dd8a90bcedb84857caf483c5501b4666f7d (diff)
version 1.2.41.2.4
-rw-r--r--CHANGELOG.md12
-rw-r--r--dhall-json.cabal7
-rw-r--r--dhall-to-yaml/Main.hs18
-rw-r--r--src/Dhall/JSON.hs67
-rw-r--r--tasty/Main.hs5
5 files changed, 75 insertions, 34 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7531fe0..12ca1e9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/dhall-json.cabal b/dhall-json.cabal
index b064db7..7d642ad 100644
--- a/dhall-json.cabal
+++ b/dhall-json.cabal
@@ -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 @@ Library
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 @@ Executable dhall-to-yaml
dhall-json ,
optparse-applicative ,
yaml >= 0.5.0 && < 0.11,
+ vector ,
text
GHC-Options: -Wall
@@ -77,6 +77,7 @@ Test-Suite tasty
Build-Depends:
base,
aeson ,
+ bytestring ,
dhall ,
dhall-json ,
tasty < 1.2,
diff --git a/dhall-to-yaml/Main.hs b/dhall-to-yaml/Main.hs
index 56b7485..cec56be 100644
--- a/dhall-to-yaml/Main.hs
+++ b/dhall-to-yaml/Main.hs
@@ -12,6 +12,7 @@ import Options.Applicative (Parser, ParserInfo)
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 @@ import qualified System.IO
data Options = Options
{ explain :: Bool
, omitNull :: Bool
+ , documents :: Bool
, conversion :: Conversion
}
@@ -30,6 +32,7 @@ parseOptions :: Parser Options
parseOptions = Options.Applicative.helper <*> do
explain <- parseExplain
omitNull <- parseOmitNull
+ documents <- parseDocuments
conversion <- Dhall.JSON.parseConversion
return (Options {..})
where
@@ -45,6 +48,12 @@ parseOptions = Options.Applicative.helper <*> do
<> 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 @@ main = do
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
diff --git a/src/Dhall/JSON.hs b/src/Dhall/JSON.hs
index e043a57..cc5c487 100644
--- a/src/Dhall/JSON.hs
+++ b/src/Dhall/JSON.hs
@@ -174,24 +174,23 @@ module Dhall.JSON (
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 :: Expr s X -> Either CompileError Value
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 @@ dhallToJSON e0 = loop (Dhall.Core.normalize e0)
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 @@ dhallToJSON e0 = loop (Dhall.Core.normalize e0)
)
] -> do
let contents' =
- Data.HashMap.Strict.InsOrd.insert
+ Dhall.Map.insert
field
(Dhall.Core.TextLit
(Dhall.Core.Chunks
@@ -312,15 +316,14 @@ dhallToJSON e0 = loop (Dhall.Core.normalize e0)
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 @@ convertToHomogeneousMaps (Conversion {..}) e0 = loop (Dhall.Core.normalize e0)
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 @@ convertToHomogeneousMaps (Conversion {..}) e0 = loop (Dhall.Core.normalize e0)
[] ->
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 @@ convertToHomogeneousMaps (Conversion {..}) e0 = loop (Dhall.Core.normalize e0)
keyValues <- traverse toKeyValue elements
let recordLiteral =
- Data.HashMap.Strict.InsOrd.fromList keyValues
+ Dhall.Map.fromList keyValues
return (Dhall.Core.RecordLit recordLiteral)
@@ -594,6 +597,14 @@ convertToHomogeneousMaps (Conversion {..}) e0 = loop (Dhall.Core.normalize e0)
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
diff --git a/tasty/Main.hs b/tasty/Main.hs
index 3db9a07..cd2fb78 100644
--- a/tasty/Main.hs
+++ b/tasty/Main.hs
@@ -8,6 +8,7 @@ import Test.Tasty (TestTree)
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 @@ issue48 = Test.Tasty.HUnit.testCase "Issue #48" assertion
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