@@ -30,8 +30,8 @@ p_valDecl' :: HsBindLR GhcPs GhcPs -> R ()
30p_valDecl' = \case
30p_valDecl' = \case
31 FunBind NoExt funId funMatches _ _ -> p_funBind funId funMatches
31 FunBind NoExt funId funMatches _ _ -> p_funBind funId funMatches
32 PatBind NoExt pat grhss _ -> p_match PatternBind [pat] grhss
32 PatBind NoExt pat grhss _ -> p_match PatternBind [pat] grhss
33− VarBind {} -> error "VarBinds are introduced by the type checker"
33+ VarBind {} -> notImplemented "VarBinds" -- introduced by the type checker
34− AbsBinds {} -> error "AbsBinds are introduced by the type checker"
34+ AbsBinds {} -> notImplemented "AbsBinds" -- introduced by the type checker
35 PatSynBind NoExt psb -> p_patSynBind psb
35 PatSynBind NoExt psb -> p_patSynBind psb
36 XHsBindsLR NoExt -> notImplemented "XHsBindsLR"
36 XHsBindsLR NoExt -> notImplemented "XHsBindsLR"
@@ -104,18 +104,23 @@ p_match style m_pats m_grhss = do
104 _ -> "->"
104 _ -> "->"
105 let combinedSpans = combineSrcSpans' $
105 let combinedSpans = combineSrcSpans' $
106 getGRHSSpan . unL <$> NE.fromList grhssGRHSs
106 getGRHSSpan . unL <$> NE.fromList grhssGRHSs
108+ if isPrefixBlock grhssGRHSs
112+ newlineSep (located' (p_grhs Guard)) grhssGRHSs
113+ unless (GHC.isEmptyLocalBindsPR (unL grhssLocalBinds)) $ do
116+ inci (located grhssLocalBinds p_hsLocalBinds)
107 case style of
117 case style of
108− Lambda -> breakpoint
119+ breakpoint'
109− _ -> return ()
120+ switchLayout combinedSpans p_body
110− switchLayout combinedSpans . inci $ do
121+ _ -> switchLayout combinedSpans . inci $ do
113− _ -> breakpoint
122+ breakpoint'
114− newlineSep (located' (p_grhs Guard)) grhssGRHSs
123+ p_body
115− unless (GHC.isEmptyLocalBindsPR (unL grhssLocalBinds)) $ do
118− inci (located grhssLocalBinds p_hsLocalBinds)
120data GroupStyle
125data GroupStyle
@@ -140,11 +145,19 @@ p_grhs _ (XGRHS NoExt) = notImplemented "XGRHS"
141p_stmt :: Stmt GhcPs (LHsExpr GhcPs) -> R ()
146p_stmt :: Stmt GhcPs (LHsExpr GhcPs) -> R ()
142p_stmt = \case
147p_stmt = \case
143− LastStmt {} -> notImplemented "do notation"
148+ LastStmt NoExt _ _ _ ->
144− BindStmt {} -> notImplemented "do notation"
149+ notImplemented "LastStmt" -- only available after renamer
150+ BindStmt NoExt l f _ _ -> do
155+ inci (located f p_hsExpr)
145− ApplicativeStmt {} -> notImplemented "applicative stmt"
156+ ApplicativeStmt {} -> notImplemented "ApplicativeStmt"
146 BodyStmt NoExt body _ _ -> located body p_hsExpr
157 BodyStmt NoExt body _ _ -> located body p_hsExpr
158+ LetStmt NoExt binds -> do
147− LetStmt NoExt binds -> located binds p_hsLocalBinds
160+ sitcc $ located binds p_hsLocalBinds
148 ParStmt {} -> notImplemented "ParStmt"
161 ParStmt {} -> notImplemented "ParStmt"
149 TransStmt {} -> notImplemented "TransStmt"
162 TransStmt {} -> notImplemented "TransStmt"
150 RecStmt {} -> notImplemented "RecStmt"
163 RecStmt {} -> notImplemented "RecStmt"
@@ -203,7 +216,7 @@ p_hsExpr = \case
203 HsLamCase NoExt mgroup -> do
216 HsLamCase NoExt mgroup -> do
204 txt "\\case"
217 txt "\\case"
206− inci (p_matchGroup LambdaCase mgroup)
219+ p_matchGroup LambdaCase mgroup
207 HsApp NoExt f x -> do
220 HsApp NoExt f x -> do
208 located f p_hsExpr
221 located f p_hsExpr
209 breakpoint
222 breakpoint
@@ -287,7 +300,13 @@ p_hsExpr = \case
287 breakpoint
300 breakpoint
288 txt "in "
301 txt "in "
289 sitcc (located e p_hsExpr)
302 sitcc (located e p_hsExpr)
303+ HsDo NoExt ctx es -> do
306+ MDoExpr -> txt "mdo"
290− HsDo {} -> notImplemented "HsDo"
307+ _ -> notImplemented "certain kinds of do notation"
309+ located es (newlineSep (located' p_stmt))
291 ExplicitList _ _ xs -> do
310 ExplicitList _ _ xs -> do
292 brackets $ velt (withSep comma (located' p_hsExpr) xs)
311 brackets $ velt (withSep comma (located' p_hsExpr) xs)
293 RecordCon {..} -> do
312 RecordCon {..} -> do
@@ -411,3 +430,17 @@ p_patSynDetails = \case
411getGRHSSpan :: GRHS GhcPs (LHsExpr GhcPs) -> SrcSpan
430getGRHSSpan :: GRHS GhcPs (LHsExpr GhcPs) -> SrcSpan
412getGRHSSpan (GRHS NoExt _ body) = getSpan body
431getGRHSSpan (GRHS NoExt _ body) = getSpan body
413getGRHSSpan (XGRHS NoExt) = notImplemented "XGRHS"
432getGRHSSpan (XGRHS NoExt) = notImplemented "XGRHS"
434+-- | Check the body is such a thing that prints a short prefix and then the
435+-- rest goes after a newline. In that case we can leave the prefix on
436+-- current line. Examples of such things are: lambdas, do-blocks, and lambda
439+isPrefixBlock :: [LGRHS GhcPs (LHsExpr GhcPs)] -> Bool
440+isPrefixBlock [(L _ (GRHS NoExt _ (L _ e)))] =
442+ HsLam NoExt _ -> True
443+ HsDo NoExt _ _ -> True
444+ HsLamCase NoExt _ -> True
446+isPrefixBlock _ = False