[commit: packages/template-haskell] wip/th-new: Correctly pretty-print let and do expressions. (1b6e8bd)

git at git.haskell.org git
Fri Oct 4 21:51:21 UTC 2013


Repository : ssh://git at git.haskell.org/template-haskell

On branch  : wip/th-new
Link       : http://git.haskell.org/packages/template-haskell.git/commitdiff/1b6e8bd4d5c63ef63efd41c12a8864b42ffec79d

>---------------------------------------------------------------

commit 1b6e8bd4d5c63ef63efd41c12a8864b42ffec79d
Author: Geoffrey Mainland <mainland at apeiron.net>
Date:   Mon Jun 3 14:44:24 2013 +0100

    Correctly pretty-print let and do expressions.


>---------------------------------------------------------------

1b6e8bd4d5c63ef63efd41c12a8864b42ffec79d
 Language/Haskell/TH/Ppr.hs |   16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/Language/Haskell/TH/Ppr.hs b/Language/Haskell/TH/Ppr.hs
index ce9fe15..9bec103 100644
--- a/Language/Haskell/TH/Ppr.hs
+++ b/Language/Haskell/TH/Ppr.hs
@@ -136,12 +136,22 @@ pprExp i (MultiIfE alts)
         []            -> [text "if {}"]
         (alt : alts') -> text "if" <+> pprGuarded arrow alt
                          : map (nest 3 . pprGuarded arrow) alts'
-pprExp i (LetE ds e) = parensIf (i > noPrec) $ text "let" <+> ppr ds
-                                            $$ text " in" <+> ppr e
+pprExp i (LetE ds_ e) = parensIf (i > noPrec) $ text "let" <+> pprDecs ds_
+                                             $$ text " in" <+> ppr e
+  where
+    pprDecs []  = empty
+    pprDecs [d] = ppr d
+    pprDecs ds  = braces $ sep $ punctuate semi $ map ppr ds
+
 pprExp i (CaseE e ms)
  = parensIf (i > noPrec) $ text "case" <+> ppr e <+> text "of"
                         $$ nest nestDepth (ppr ms)
-pprExp i (DoE ss) = parensIf (i > noPrec) $ text "do" <+> ppr ss
+pprExp i (DoE ss_) = parensIf (i > noPrec) $ text "do" <+> pprStms ss_
+  where
+    pprStms []  = empty
+    pprStms [s] = ppr s
+    pprStms ss  = braces $ sep $ punctuate semi $ map ppr ss
+    
 pprExp _ (CompE []) = text "<<Empty CompExp>>"
 -- This will probably break with fixity declarations - would need a ';'
 pprExp _ (CompE ss) = text "[" <> ppr s




More information about the ghc-commits mailing list