fix indentation of nested objects

This commit is contained in:
Michele Guerini Rocco 2019-11-10 11:06:44 +01:00
parent 2b0551ca07
commit 7305b4f3c9
Signed by: rnhmjoj
GPG Key ID: BFBAF4C975F76450

View File

@ -9,19 +9,19 @@ import Data.List (intercalate)
import qualified Data.Vector as V import qualified Data.Vector as V
import qualified Data.HashMap.Strict as H import qualified Data.HashMap.Strict as H
-- | Get the JSON value of a key -- | Gets the JSON value of a key
(|.) :: Object -> Text -> Value (|.) :: Object -> Text -> Value
obj |. key = case parse (.: key) obj of obj |. key = case parse (.: key) obj of
Success val -> val Success val -> val
Error err -> toJSON err Error err -> toJSON err
-- | Get the 'String' value of a key -- | Gets the 'String' value of a key
(|:) :: Object -> Text -> String (|:) :: Object -> Text -> String
obj |: key = repr (obj |. key) obj |: key = repr (obj |. key)
-- | Create a String representation of a 'Value' -- | Creates a 'String' representation of a 'Value'
repr :: Value -> String repr :: Value -> String
repr obj = repr' obj 0 where repr obj = repr' obj 0 where
repr' val lev = repr' val lev =
@ -33,7 +33,7 @@ repr obj = repr' obj 0 where
Bool x -> show x Bool x -> show x
Null -> "null" Null -> "null"
mapl f v = V.toList (V.map f v) mapl f v = V.toList (V.map f v)
newline n = if n == 1 then id else drop 1 newline n = if n /= 0 then id else drop 1
indent l = '\n' : (concat . replicate l) " " indent l = '\n' : (concat . replicate l) " "
dump o l k = concat [indent l, unpack k, ": ", repr' (o |. k) (l+1)] dump o l k = concat [indent l, unpack k, ": ", repr' (o |. k) (l+1)]