packages feed

dhall-json 1.7.10 → 1.7.11

raw patch · 5 files changed

+60/−15 lines, 5 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Dhall.JSON: codeToHeaderAndValue :: Conversion -> SpecialDoubleMode -> Maybe FilePath -> Text -> IO (Header, Value)
+ Dhall.JSON.Yaml: [preserveHeader] :: Options -> Bool
- Dhall.JSON.Yaml: Options :: Bool -> (Value -> Value) -> Bool -> Bool -> Conversion -> Maybe FilePath -> Maybe FilePath -> Bool -> Options
+ Dhall.JSON.Yaml: Options :: Bool -> (Value -> Value) -> Bool -> Bool -> Conversion -> Maybe FilePath -> Maybe FilePath -> Bool -> Bool -> Options

Files

CHANGELOG.md view
@@ -1,3 +1,9 @@+1.7.11++* [Add new `--preserve-header` option](https://github.com/dhall-lang/dhall-haskell/pull/2433)+* Builds against newer dependencies+  * [`aeson-2.1`](https://github.com/dhall-lang/dhall-haskell/pull/2424)+ 1.7.10  * [Don't use scientific notation for large integers](https://github.com/dhall-lang/dhall-haskell/pull/2352)
dhall-json.cabal view
@@ -1,5 +1,5 @@ Name: dhall-json-Version: 1.7.10+Version: 1.7.11 Cabal-Version: >=1.10 Build-Type: Simple License: BSD3@@ -38,7 +38,7 @@     Hs-Source-Dirs: src     Build-Depends:         base                      >= 4.11.0.0  && < 5   ,-        aeson                     >= 1.4.6.0   && < 2.1 ,+        aeson                     >= 1.4.6.0   && < 2.2 ,         aeson-pretty              >= 0.8.0     && < 0.9 ,         aeson-yaml                >= 1.1.0     && < 1.2 ,         bytestring                                < 0.12,
src/Dhall/DhallToYaml/Main.hs view
@@ -34,6 +34,7 @@             <*> optional parseFile             <*> optional parseOutput             <*> parseNoEdit+            <*> parsePreserveHeader             )     <|> parseVersion   where@@ -70,6 +71,12 @@         Options.switch            (   Options.long "generated-comment"            <>  Options.help "Include a comment header warning not to edit the generated file"+           )++    parsePreserveHeader =+        Options.switch+           (   Options.long "preserve-header"+           <>  Options.help "Translate any Dhall comment header to a YAML comment header"            )  parserInfo :: ParserInfo (Maybe Options)
src/Dhall/JSON.hs view
@@ -208,6 +208,7 @@     , SpecialDoubleMode(..)     , handleSpecialDoubles     , codeToValue+    , codeToHeaderAndValue      -- * Exceptions     , CompileError(..)@@ -224,6 +225,7 @@ import Dhall.Import        (SemanticCacheMode (..)) import Dhall.JSON.Util     (pattern FA, pattern V) import Dhall.Map           (Map)+import Dhall.Parser        (Header(..)) import Options.Applicative (Parser) import Prelude             hiding (getContents) import Prettyprinter       (Pretty)@@ -1187,8 +1189,28 @@   -> Text  -- ^ Input text.   -> IO Value codeToValue conversion specialDoubleMode mFilePath code = do-    parsedExpression <- Core.throws (Dhall.Parser.exprFromText (fromMaybe "(input)" mFilePath) code)+  fmap snd (codeToHeaderAndValue conversion specialDoubleMode mFilePath code) +{-| This is like `codeToValue`, except also returning a `Header` that is a+    valid YAML comment derived from the original Dhall code's `Header`+-}+codeToHeaderAndValue+  :: Conversion+  -> SpecialDoubleMode+  -> Maybe FilePath  -- ^ The source file path. If no path is given, imports+                     -- are resolved relative to the current directory.+  -> Text  -- ^ Input text.+  -> IO (Header, Value)+codeToHeaderAndValue conversion specialDoubleMode mFilePath code = do+    (Header header, parsedExpression) <- Core.throws (Dhall.Parser.exprAndHeaderFromText (fromMaybe "(input)" mFilePath) code)++    let adapt line =+            case Data.Text.stripPrefix "--" line of+                Just suffix -> "#" <> suffix+                Nothing     -> "#" <> line++    let yamlHeader = Data.Text.unlines (map adapt (Data.Text.lines header))+     let rootDirectory = case mFilePath of             Nothing -> "."             Just fp -> System.FilePath.takeDirectory fp@@ -1204,4 +1226,4 @@      case dhallToJSON specialDoubleExpression of       Left  err  -> Control.Exception.throwIO err-      Right json -> return json+      Right json -> return (Header yamlHeader, json)
src/Dhall/JSON/Yaml.hs view
@@ -19,25 +19,28 @@ import Data.ByteString     (ByteString) import Data.Text           (Text) import Dhall.JSON          (Conversion (..), SpecialDoubleMode (..))+import Dhall.Parser        (Header(..)) import Options.Applicative (Parser)  import qualified Data.Aeson import qualified Data.Aeson.Yaml import qualified Data.ByteString.Lazy+import qualified Data.Text.Encoding import qualified Data.Vector import qualified Dhall import qualified Dhall.JSON import qualified Options.Applicative  data Options = Options-    { explain    :: Bool-    , omission   :: Data.Aeson.Value -> Data.Aeson.Value-    , documents  :: Bool-    , quoted     :: Bool-    , conversion :: Conversion-    , file       :: Maybe FilePath-    , output     :: Maybe FilePath-    , noEdit     :: Bool+    { explain        :: Bool+    , omission       :: Data.Aeson.Value -> Data.Aeson.Value+    , documents      :: Bool+    , quoted         :: Bool+    , conversion     :: Conversion+    , file           :: Maybe FilePath+    , output         :: Maybe FilePath+    , noEdit         :: Bool+    , preserveHeader :: Bool     }  defaultOptions :: Options@@ -50,6 +53,7 @@           , file = Nothing           , output = Nothing           , noEdit = False+          , preserveHeader = False           }  parseDocuments :: Parser Bool@@ -84,12 +88,18 @@    let explaining = if explain then Dhall.detailed else id -  json <- omission <$> explaining (Dhall.JSON.codeToValue conversion UseYAMLEncoding mFilePath code)+  let adapt (header, value) = (header, omission value) +  (Header comment, json) <- adapt <$> explaining (Dhall.JSON.codeToHeaderAndValue conversion UseYAMLEncoding mFilePath code)++  let suffix+        | preserveHeader = Data.Text.Encoding.encodeUtf8 comment+        | otherwise      = mempty+   let header =           if noEdit-          then generatedCodeNotice-          else mempty+          then generatedCodeNotice <> suffix+          else suffix    return $ header <> jsonToYaml json documents quoted