gdritter repos s-cargot / 4dd3ce8
Added preliminary pretty-printing support for dotted lists, but without taking into account their effect on width Getty Ritter 7 years ago
1 changed file(s) with 6 addition(s) and 3 deletion(s). Collapse all Expand all
180180 where pHead _ SNil = "()"
181181 pHead _ (SAtom a) = atomPrinter a
182182 pHead ind (SCons x xs) = gather ind x xs id
183 gather _ _ (SAtom _) _ = error "no dotted pretty printing yet!"
184183 gather ind h (SCons x xs) k = gather ind h xs (k . (x:))
185 gather ind h SNil k = "(" <> hd <> body <> ")"
186 where hd = indentSubsequent ind [pHead (ind+1) h]
184 gather ind h end k = "(" <> hd <> body <> tail <> ")"
185 where tail = case end of
186 SNil -> ""
187 SAtom a -> " . " <> atomPrinter a
188 SCons _ _ -> error "[unreachable]"
189 hd = indentSubsequent ind [pHead (ind+1) h]
187190 lst = k []
188191 flat = T.unwords (map (pHead (ind+1)) lst)
189192 headWidth = T.length hd + 1