diff options
author | Elton <eltonp3103@gmail.com> | 2022-01-16 13:28:03 -0500 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-02-01 12:28:49 -0500 |
commit | fdda93b03e9be56122dd8445e7ee0f1d0f933a19 (patch) | |
tree | 40ce0148efd213a9c5bb5cf64ed86cc8eba4e03c /libraries | |
parent | 60ac73002fc6fb717f1838a2bb3cee6535ff77c9 (diff) | |
download | haskell-fdda93b03e9be56122dd8445e7ee0f1d0f933a19.tar.gz |
Use braces in TH LambdaCase and where clauses
This patch ensures that the pretty printer formats LambdaCase and where
clauses using braces (instead of layout) to remain consistent with the
formatting of other statements (like `do` and `case`)
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/template-haskell/Language/Haskell/TH/Ppr.hs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/libraries/template-haskell/Language/Haskell/TH/Ppr.hs b/libraries/template-haskell/Language/Haskell/TH/Ppr.hs index 42d32487c8..d9ae558c15 100644 --- a/libraries/template-haskell/Language/Haskell/TH/Ppr.hs +++ b/libraries/template-haskell/Language/Haskell/TH/Ppr.hs @@ -155,7 +155,7 @@ pprExp i (LamE [] e) = pprExp i e -- #13856 pprExp i (LamE ps e) = parensIf (i > noPrec) $ char '\\' <> hsep (map (pprPat appPrec) ps) <+> text "->" <+> ppr e pprExp i (LamCaseE ms) = parensIf (i > noPrec) - $ text "\\case" $$ nest nestDepth (ppr ms) + $ text "\\case" $$ braces (semiSep ms) pprExp i (TupE es) | [Just e] <- es = pprExp i (ConE (tupleDataName 1) `AppE` e) @@ -938,7 +938,7 @@ instance Ppr Range where ------------------------------ where_clause :: [Dec] -> Doc where_clause [] = empty -where_clause ds = nest nestDepth $ text "where" <+> vcat (map (ppr_dec False) ds) +where_clause ds = nest nestDepth $ text "where" <+> braces (semiSepWith (ppr_dec False) ds) showtextl :: Show a => a -> Doc showtextl = text . map toLower . show @@ -960,6 +960,11 @@ instance Ppr Loc where , text "-" , parens $ int end_ln <> comma <> int end_col ] +-- Takes a separator and a pretty-printing function and prints a list of things +-- separated by the separator followed by space. +sepWith :: Doc -> (a -> Doc) -> [a] -> Doc +sepWith sepDoc pprFun = sep . punctuate sepDoc . map pprFun + -- Takes a list of printable things and prints them separated by commas followed -- by space. commaSep :: Ppr a => [a] -> Doc @@ -968,13 +973,18 @@ commaSep = commaSepWith ppr -- Takes a list of things and prints them with the given pretty-printing -- function, separated by commas followed by space. commaSepWith :: (a -> Doc) -> [a] -> Doc -commaSepWith pprFun = sep . punctuate comma . map pprFun +commaSepWith pprFun = sepWith comma pprFun -- Takes a list of printable things and prints them separated by semicolons -- followed by space. semiSep :: Ppr a => [a] -> Doc semiSep = sep . punctuate semi . map ppr +-- Takes a list of things and prints them with the given pretty-printing +-- function, separated by semicolons followed by space. +semiSepWith :: (a -> Doc) -> [a] -> Doc +semiSepWith pprFun = sepWith semi pprFun + -- Prints out the series of vertical bars that wraps an expression or pattern -- used in an unboxed sum. unboxedSumBars :: Doc -> SumAlt -> SumArity -> Doc |