Commit 215a0b84 authored by Michael Hanus's avatar Michael Hanus
Browse files

Pretty-printing strings improved

parent 8138e0db
...@@ -13,13 +13,23 @@ ppJValue JTrue = text "true" ...@@ -13,13 +13,23 @@ ppJValue JTrue = text "true"
ppJValue JFalse = text "false" ppJValue JFalse = text "false"
ppJValue JNull = text "null" ppJValue JNull = text "null"
ppJValue (JNumber f) = float f ppJValue (JNumber f) = float f
ppJValue (JString s) = text $ show s
ppJValue (JArray vs) = ppJArray vs ppJValue (JArray vs) = ppJArray vs
ppJValue (JObject ps) = ppJObject ps ppJValue (JObject ps) = ppJObject ps
ppJValue (JString s) = text $ '"' : concatMap ppJChar s ++ "\""
where
ppJChar c | c == '"' = "\\\""
| c == '\\' = "\\\\"
| c == '\b' = "\\b"
| c == '\f' = "\\f"
| c == '\n' = "\\n"
| c == '\r' = "\\r"
| c == '\t' = "\\t"
| otherwise = [c]
ppJArray :: [JValue] -> Doc ppJArray :: [JValue] -> Doc
ppJArray vs = listSpaced $ map ppJValue vs ppJArray vs = listSpaced $ map ppJValue vs
ppJObject :: [(String, JValue)] -> Doc ppJObject :: [(String, JValue)] -> Doc
ppJObject ps = (nest 2 $ lbrace $$ vsep (punctuate comma $ map ppKVP ps)) $$ rbrace ppJObject ps =
where ppKVP (k, v) = (text $ show k) <> colon <+> ppJValue v (nest 2 $ lbrace $$ vsep (punctuate comma $ map ppKVP ps)) $$ rbrace
where ppKVP (k, v) = (text $ show k) <> colon <+> ppJValue v
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment