Skip to content

Commit

Permalink
dhall-json: Don't use scientific notation for large integers (dhall-l…
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriella439 authored Jan 1, 2022
1 parent 77c5fe2 commit 7519ab9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dhall-json/dhall-json.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Library
Build-Depends:
base >= 4.11.0.0 && < 5 ,
aeson >= 1.4.6.0 && < 2.1 ,
aeson-pretty < 0.9 ,
aeson-pretty >= 0.8.0 && < 0.9 ,
aeson-yaml >= 1.1.0 && < 1.2 ,
bytestring < 0.12,
containers >= 0.5.9 && < 0.7 ,
Expand Down
26 changes: 16 additions & 10 deletions dhall-json/dhall-to-json/Main.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeApplications #-}

module Main where

Expand All @@ -12,14 +13,15 @@ import Options.Applicative (Parser, ParserInfo)

import qualified Control.Exception
import qualified Data.Aeson
import qualified Data.Aeson.Encode.Pretty
import qualified Data.Aeson.Text
import qualified Data.Aeson.Encode.Pretty as Pretty
import qualified Data.ByteString.Lazy
import qualified Data.Text.IO as Text.IO
import qualified Data.Text.IO as Text.IO
import qualified Dhall
import qualified Dhall.JSON
import qualified GHC.IO.Encoding
import qualified Options.Applicative as Options
import qualified Paths_dhall_json as Meta
import qualified Options.Applicative as Options
import qualified Paths_dhall_json as Meta
import qualified System.Exit
import qualified System.IO

Expand Down Expand Up @@ -123,14 +125,18 @@ main = do

Options {..} ->
handle $ do
let config = Data.Aeson.Encode.Pretty.Config
{ Data.Aeson.Encode.Pretty.confIndent = Data.Aeson.Encode.Pretty.Spaces 2
, Data.Aeson.Encode.Pretty.confCompare = compare
, Data.Aeson.Encode.Pretty.confNumFormat = Data.Aeson.Encode.Pretty.Generic
, Data.Aeson.Encode.Pretty.confTrailingNewline = False }
let custom scientific =
Data.Aeson.Text.encodeToTextBuilder (Data.Aeson.Number scientific)

let config = Pretty.Config
{ Pretty.confIndent = Pretty.Spaces 2
, Pretty.confCompare = compare
, Pretty.confNumFormat = Pretty.Custom custom
, Pretty.confTrailingNewline = False
}
let encode =
if pretty
then Data.Aeson.Encode.Pretty.encodePretty' config
then Pretty.encodePretty' config
else Data.Aeson.encode

let explaining = if explain then Dhall.detailed else id
Expand Down

0 comments on commit 7519ab9

Please sign in to comment.