@@ -6,14 +6,14 @@ module Reporting.Render.Type
66 , apply
77 , tuple
88 , record
9− , recordSnippet
9+ , vrecordSnippet
10+ , vrecord
1011 , srcToDoc
1112 , canToDoc
1213 )
1314 where
1415
1516
16−import qualified Data.Map as Map
1717import qualified Data.Maybe as Maybe
1818
1919import qualified AST.Source as Src
@@ -101,13 +101,33 @@ entryToDoc (fieldName, fieldType) =
101101 D.hang 4 (D.sep [ fieldName <+> ":", fieldType ])
102102
103103
104−recordSnippet :: (Doc, Doc) -> [(Doc, Doc)] -> Doc
105−recordSnippet entry entries =
104+vrecordSnippet :: (Doc, Doc) -> [(Doc, Doc)] -> Doc
105+vrecordSnippet entry entries =
106106 let
107107 field = "{" <+> entryToDoc entry
108108 fields = zipWith (<+>) (repeat ",") (map entryToDoc entries ++ ["..."])
109109 in
110− D.sep [ D.cat (field:fields), "}" ]
110+ D.vcat (field : fields ++ ["}"])
111+
112+
113+vrecord :: [(Doc, Doc)] -> Maybe Doc -> Doc
114+vrecord entries maybeExt =
115+ case (map entryToDoc entries, maybeExt) of
116+ ([], Nothing) ->
117+ "{}"
118+
119+ (fields, Nothing) ->
120+ D.vcat $
121+ zipWith (<+>) ("{" : repeat ",") fields ++ ["}"]
122+
123+ (fields, Just ext) ->
124+ D.vcat
125+ [ D.hang 4 $ D.vcat $
126+ [ "{" <+> ext
127+ , D.cat (zipWith (<+>) ("|" : repeat ",") fields)
128+ ]
129+ , "}"
130+ ]
111131
112132
113133