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

git at git.haskell.org git at git.haskell.org
Mon Sep 23 07:59:24 CEST 2013


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

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

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

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

    Correctly pretty-print let and do expressions.


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

b5cab067af218920e8f6cfd13b90340f08266a50
 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 8222085..4cccc41 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