Skip to content

Commit

Permalink
Add a proper list combinator to produce JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
ndmitchell committed Feb 7, 2018
1 parent 1de487f commit 1af1723
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Idea.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ showIdeaJson idea@Idea{ideaSpan=srcSpan@SrcSpan{..}, ..} = dict
,("endColumn", show srcSpanEndColumn)
,("from", str ideaFrom)
,("to", maybe "null" str ideaTo)
,("note", "[" ++ intercalate "," (map (str . show) ideaNote) ++ "]")
,("note", list (map (str . show) ideaNote))
,("refactorings", str $ show ideaRefactoring)
]
where
Expand All @@ -62,6 +62,7 @@ showIdeaJson idea@Idea{ideaSpan=srcSpan@SrcSpan{..}, ..} = dict
f x | isControl x || not (isAscii x) = "\\u" ++ takeEnd 4 ("0000" ++ showHex (ord x) "")
f x = [x]
dict xs = "{" ++ intercalate "," [show k ++ ":" ++ v | (k,v) <- xs] ++ "}"
list xs = "[" ++ intercalate "," xs ++ "]"

showIdeasJson :: [Idea] -> String
showIdeasJson ideas = "[" ++ intercalate "\n," (map showIdeaJson ideas) ++ "]"
Expand Down

0 comments on commit 1af1723

Please sign in to comment.