Bladeren bron

Added preliminary pretty-printing support for dotted lists, but without taking into account their effect on width

Getty Ritter 8 jaren geleden
bovenliggende
commit
4dd3ce8d4b
1 gewijzigde bestanden met toevoegingen van 6 en 3 verwijderingen
  1. 6 3
      Data/SCargot/Print.hs

+ 6 - 3
Data/SCargot/Print.hs

@@ -180,10 +180,13 @@ prettyPrintSExpr SExprPrinter { .. } = pHead 0
   where pHead _   SNil         = "()"
         pHead _   (SAtom a)    = atomPrinter a
         pHead ind (SCons x xs) = gather ind x xs id
-        gather _   _ (SAtom _)    _ = error "no dotted pretty printing yet!"
         gather ind h (SCons x xs) k = gather ind h xs (k . (x:))
-        gather ind h SNil         k = "(" <> hd <> body <> ")"
-          where hd   = indentSubsequent ind [pHead (ind+1) h]
+        gather ind h end          k = "(" <> hd <> body <> tail <> ")"
+          where tail = case end of
+                         SNil      -> ""
+                         SAtom a   -> " . " <> atomPrinter a
+                         SCons _ _ -> error "[unreachable]"
+                hd   = indentSubsequent ind [pHead (ind+1) h]
                 lst  = k []
                 flat = T.unwords (map (pHead (ind+1)) lst)
                 headWidth = T.length hd + 1