@@ -308,20 +308,60 @@ p_stmt' pretty = \case
308 LetStmt NoExt binds -> do
308 LetStmt NoExt binds -> do
309 txt "let "
309 txt "let "
310 sitcc $ located binds p_hsLocalBinds
310 sitcc $ located binds p_hsLocalBinds
311− ParStmt NoExt stmts _ _ ->
311+ ParStmt {} ->
312− sequence_ $ intersperse breakpoint $
312+ -- NOTE 'ParStmt' should always be eliminated in 'gatherStmt' already,
313− withSep (txt "| ") p_parStmtBlock stmts
313+ -- such that it never occurs in 'p_stmt''. Consequently, handling it
314+ -- here would be redundant.
314− TransStmt {} -> notImplemented "TransStmt"
315+ notImplemented "ParStmt"
316+ TransStmt {..} -> do
317+ -- NOTE 'TransStmt' only needs to account for pretty printing itself,
318+ -- since pretty printing of relevant statements (e.g., in 'trS_stmts')
319+ -- is handled through 'gatherStmt'.
320+ case (trS_form, trS_by) of
321+ (ThenForm, Nothing) -> located trS_using $ \x -> do
325+ (ThenForm, Just e) -> do
326+ located trS_using $ \x -> do
331+ located e $ \x -> do
335+ (GroupForm, Nothing) -> located trS_using $ \x -> do
336+ txt "then group using"
339+ (GroupForm, Just e) -> do
340+ located e $ \x -> do
345+ located trS_using $ \x -> do
315 RecStmt {..} -> do
349 RecStmt {..} -> do
316 txt "rec "
350 txt "rec "
317 sitcc $ newlineSep (located' (p_stmt' pretty)) recS_stmts
351 sitcc $ newlineSep (located' (p_stmt' pretty)) recS_stmts
318 XStmtLR {} -> notImplemented "XStmtLR"
352 XStmtLR {} -> notImplemented "XStmtLR"
320−p_parStmtBlock :: ParStmtBlock GhcPs GhcPs -> R ()
354+gatherStmt :: ExprLStmt GhcPs -> [[ExprLStmt GhcPs]]
321−p_parStmtBlock = \case
355+gatherStmt (L _ (ParStmt NoExt block _ _)) =
322− ParStmtBlock NoExt stmts _ _ ->
356+ foldr ((<>) . gatherStmtBlock) [] block
323− velt $ withSep comma (located' (sitcc . p_stmt)) stmts
357+gatherStmt (L s stmt@TransStmt {..}) =
358+ foldr liftAppend [] ((gatherStmt <$> trS_stmts) <> pure [[L s stmt]])
359+gatherStmt stmt = [[stmt]]
361+gatherStmtBlock :: ParStmtBlock GhcPs GhcPs -> [[ExprLStmt GhcPs]]
362+gatherStmtBlock (ParStmtBlock _ stmts _ _) =
363+ foldr (liftAppend . gatherStmt) [] stmts
324− XParStmtBlock {} -> notImplemented "XParStmtBlock"
364+gatherStmtBlock XParStmtBlock {} = notImplemented "XParStmtBlock"
326p_hsLocalBinds :: HsLocalBindsLR GhcPs GhcPs -> R ()
366p_hsLocalBinds :: HsLocalBindsLR GhcPs GhcPs -> R ()
327p_hsLocalBinds = \case
367p_hsLocalBinds = \case
@@ -468,14 +508,21 @@ p_hsExpr = \case
469 inci $ located es (newlineSep (located' (sitcc . p_stmt)))
509 inci $ located es (newlineSep (located' (sitcc . p_stmt)))
470 compBody = brackets $ located es $ \xs -> do
510 compBody = brackets $ located es $ \xs -> do
513+ intersperse breakpoint .
514+ withSep (txt "| ") p_seqBody
517+ intersperse (vlayout (pure ()) newline) .
518+ withSep comma (located' (sitcc . p_stmt))
471− let stmts = init xs
519+ stmts = init xs
472 yield = last xs
520 yield = last xs
521+ lists = foldr (liftAppend . gatherStmt) [] stmts
473 located yield p_stmt
522 located yield p_stmt
474 breakpoint
523 breakpoint
476− case stmts of
525+ p_parBody lists
477− [stmt] | ParStmt {} <- unLoc stmt -> located stmt p_stmt
478− _ -> velt $ withSep comma (located' (sitcc . p_stmt)) stmts
479 case ctx of
526 case ctx of
480 DoExpr -> doBody "do"
527 DoExpr -> doBody "do"
481 MDoExpr -> doBody "mdo"
528 MDoExpr -> doBody "mdo"
@@ -757,6 +804,15 @@ p_hsBracket = \case
757----------------------------------------------------------------------------
804----------------------------------------------------------------------------
758-- Helpers
805-- Helpers
807+-- | Append each element in both lists with semigroups. If one list is shorter
808+-- than the other, return the rest of the longer list unchanged.
810+liftAppend :: Semigroup a => [a] -> [a] -> [a]
811+liftAppend [] [] = []
812+liftAppend [] (y : ys) = y : ys
813+liftAppend (x : xs) [] = x : xs
814+liftAppend (x : xs) (y : ys) = x <> y : liftAppend xs ys
760getGRHSSpan :: GRHS GhcPs (Located body) -> SrcSpan
816getGRHSSpan :: GRHS GhcPs (Located body) -> SrcSpan
761getGRHSSpan (GRHS NoExt _ body) = getLoc body
817getGRHSSpan (GRHS NoExt _ body) = getLoc body
762getGRHSSpan (XGRHS NoExt) = notImplemented "XGRHS"
818getGRHSSpan (XGRHS NoExt) = notImplemented "XGRHS"