@@ -85,9 +85,9 @@ p_matchGroup'
85 -> MatchGroup GhcPs (Located body)
85 -> MatchGroup GhcPs (Located body)
87p_matchGroup' placer pretty style MG {..} =
87p_matchGroup' placer pretty style MG {..} =
88− locatedVia Nothing mg_alts $
89− newlineSep (located' (\m@Match {..} ->
88+ sep newline (located' (\m@Match {..} ->
90− p_match' placer pretty style (isInfixMatch m) (matchStrictness m) m_pats m_grhss))
89+ p_match' placer pretty style (isInfixMatch m) (matchStrictness m) m_pats m_grhss))
91p_matchGroup' _ _ _ (XMatchGroup NoExt) = notImplemented "XMatchGroup"
91p_matchGroup' _ _ _ (XMatchGroup NoExt) = notImplemented "XMatchGroup"
93matchStrictness :: Match id body -> SrcStrictness
93matchStrictness :: Match id body -> SrcStrictness
@@ -137,8 +137,8 @@ p_match' placer pretty style isInfix strictness m_pats m_grhss = do
137 inci' = if isOneLineSpan combinedSpans
137 inci' = if isOneLineSpan combinedSpans
139 else inci
139 else inci
140− switchLayout combinedSpans $ do
140+ switchLayout [combinedSpans] $ do
141− let stdCase = velt' (located' p_pat <$> m_pats)
141+ let stdCase = sep breakpoint (located' p_pat) m_pats
142 case style of
142 case style of
143 Function name ->
143 Function name ->
144 p_infixDefHelper
144 p_infixDefHelper
@@ -201,12 +201,12 @@ p_match' placer pretty style isInfix strictness m_pats m_grhss = do
201 if isCase style && hasGuards
201 if isCase style && hasGuards
202 then RightArrow
202 then RightArrow
203 else EqualSign
203 else EqualSign
204− newlineSep (located' (p_grhs' pretty groupStyle)) grhssGRHSs
204+ sep newline (located' (p_grhs' pretty groupStyle)) grhssGRHSs
205 let whereLocation = combineSrcSpans patGrhssSpan $ getLoc grhssLocalBinds
205 let whereLocation = combineSrcSpans patGrhssSpan $ getLoc grhssLocalBinds
206 whereIsEmpty = GHC.isEmptyLocalBindsPR (unLoc grhssLocalBinds)
206 whereIsEmpty = GHC.isEmptyLocalBindsPR (unLoc grhssLocalBinds)
207 unless (GHC.eqEmptyLocalBinds (unLoc grhssLocalBinds))
207 unless (GHC.eqEmptyLocalBinds (unLoc grhssLocalBinds))
208 . inciLocalBinds
208 . inciLocalBinds
209− . switchLayout whereLocation $ do
209+ . switchLayout [whereLocation] $ do
210 if whereIsEmpty then newline else breakpoint
210 if whereIsEmpty then newline else breakpoint
211 txt "where"
211 txt "where"
212 unless whereIsEmpty $ do
212 unless whereIsEmpty $ do
@@ -214,8 +214,8 @@ p_match' placer pretty style isInfix strictness m_pats m_grhss = do
214 inci (located grhssLocalBinds p_hsLocalBinds)
214 inci (located grhssLocalBinds p_hsLocalBinds)
215 case style of
215 case style of
216 Lambda -> placeHanging placement $
216 Lambda -> placeHanging placement $
217− switchLayout patGrhssSpan p_body
217+ switchLayout [patGrhssSpan] p_body
218− _ -> switchLayout patGrhssSpan $
218+ _ -> switchLayout [patGrhssSpan] $
219 placeHanging placement p_body
219 placeHanging placement p_body
221p_grhs :: GroupStyle -> GRHS GhcPs (LHsExpr GhcPs) -> R ()
221p_grhs :: GroupStyle -> GRHS GhcPs (LHsExpr GhcPs) -> R ()
@@ -232,7 +232,7 @@ p_grhs' pretty style (GRHS NoExt guards body) =
232 [] -> p_body
232 [] -> p_body
235− velt $ withSep comma (located' p_stmt) xs
235+ sitcc (sep (comma >> breakpoint) (sitcc . located' p_stmt) xs)
237 txt $ case style of
237 txt $ case style of
238 EqualSign -> "="
238 EqualSign -> "="
@@ -298,7 +298,7 @@ p_hsCmd = \case
298 HsCmdDo NoExt es -> do
298 HsCmdDo NoExt es -> do
301− inci (located es (newlineSep (located' (sitcc . p_stmt' p_hsCmd))))
301+ inci (located es (sitcc . sep newline (located' (sitcc . p_stmt' p_hsCmd))))
302 HsCmdWrap {} -> notImplemented "HsCmdWrap"
302 HsCmdWrap {} -> notImplemented "HsCmdWrap"
303 XCmd {} -> notImplemented "XCmd"
303 XCmd {} -> notImplemented "XCmd"
@@ -368,7 +368,7 @@ p_stmt' pretty = \case
368 inci (p_hsExpr x)
368 inci (p_hsExpr x)
369 RecStmt {..} -> do
369 RecStmt {..} -> do
370 txt "rec "
370 txt "rec "
371− sitcc $ newlineSep (located' (p_stmt' pretty)) recS_stmts
371+ sitcc $ sep newline (located' (p_stmt' pretty)) recS_stmts
372 XStmtLR {} -> notImplemented "XStmtLR"
372 XStmtLR {} -> notImplemented "XStmtLR"
374gatherStmt :: ExprLStmt GhcPs -> [[ExprLStmt GhcPs]]
374gatherStmt :: ExprLStmt GhcPs -> [[ExprLStmt GhcPs]]
@@ -393,7 +393,7 @@ p_hsLocalBinds = \case
393 (Left <$> bagToList bag) ++ (Right <$> lsigs)
393 (Left <$> bagToList bag) ++ (Right <$> lsigs)
394 p_item (Left x) = located x p_valDecl'
394 p_item (Left x) = located x p_valDecl'
395 p_item (Right x) = located x p_sigDecl'
395 p_item (Right x) = located x p_sigDecl'
396− newlineSep (sitcc . p_item) (sortOn ssStart items)
396+ sitcc $ sep newline (sitcc . p_item) (sortOn ssStart items)
397 HsValBinds NoExt _ -> notImplemented "HsValBinds"
397 HsValBinds NoExt _ -> notImplemented "HsValBinds"
398 HsIPBinds NoExt _ -> notImplemented "HsIPBinds"
398 HsIPBinds NoExt _ -> notImplemented "HsIPBinds"
399 EmptyLocalBinds NoExt -> return ()
399 EmptyLocalBinds NoExt -> return ()
@@ -439,7 +439,7 @@ p_hsExpr = \case
439 txt "\\case"
439 txt "\\case"
441 inci (p_matchGroup LambdaCase mgroup)
441 inci (p_matchGroup LambdaCase mgroup)
442− HsApp NoExt f x -> do
442+ HsApp NoExt f x -> sitcc $ do
443 located f p_hsExpr
443 located f p_hsExpr
444 breakpoint
444 breakpoint
445 inci (located x p_hsExpr)
445 inci (located x p_hsExpr)
@@ -479,9 +479,11 @@ p_hsExpr = \case
479 case boxity of
479 case boxity of
480 Boxed -> parens
480 Boxed -> parens
481 Unboxed -> parensHash
481 Unboxed -> parensHash
482− parens' $ if isSection
482+ if isSection
483+ then switchLayout [] . parens' $
483− then sequence_ (withSep (txt ",") (located' p_hsTupArg) args)
484+ sep comma (located' p_hsTupArg) args
485+ else switchLayout (getLoc <$> args) . parens' . sitcc $
484− else velt (withSep comma (located' p_hsTupArg) args)
486+ sep (comma >> breakpoint) (sitcc . located' p_hsTupArg) args
485 ExplicitSum NoExt tag arity e -> do
487 ExplicitSum NoExt tag arity e -> do
486 let before = tag - 1
488 let before = tag - 1
487 after = arity - before - 1
489 after = arity - before - 1
@@ -496,7 +498,7 @@ p_hsExpr = \case
496 unless isFirst space
498 unless isFirst space
497 located l p_hsExpr
499 located l p_hsExpr
498 unless isLast space
500 unless isLast space
499− parensHash $ sequence_ (withSep (txt "|") f (zip args [0..]))
501+ parensHash $ sep (txt "|") f (zip args [0..])
500 HsCase NoExt e mgroup -> do
502 HsCase NoExt e mgroup -> do
501 txt "case "
503 txt "case "
502 located e p_hsExpr
504 located e p_hsExpr
@@ -518,7 +520,7 @@ p_hsExpr = \case
518 inci (p_hsExpr x)
520 inci (p_hsExpr x)
519 HsMultiIf NoExt guards -> do
521 HsMultiIf NoExt guards -> do
520 txt "if "
522 txt "if "
521− sitcc $ newlineSep (located' (p_grhs RightArrow)) guards
523+ sitcc $ sep newline (located' (p_grhs RightArrow)) guards
522 HsLet NoExt localBinds e -> do
524 HsLet NoExt localBinds e -> do
523 txt "let "
525 txt "let "
524 sitcc (located localBinds p_hsLocalBinds)
526 sitcc (located localBinds p_hsLocalBinds)
@@ -529,16 +531,14 @@ p_hsExpr = \case
529 let doBody header = do
531 let doBody header = do
530 txt header
532 txt header
532− inci $ located es (newlineSep (located' (sitcc . p_stmt)))
534+ inci $ located es (sep newline (located' (sitcc . p_stmt)))
533− compBody = brackets $ located es $ \xs -> do
535+ compBody = brackets $ located es $ \xs -> do
534− let p_parBody =
536+ let p_parBody = sitcc . sep
536− intersperse breakpoint .
537+ (breakpoint >> txt "| ")
537− withSep (txt "| ") p_seqBody
538+ p_seqBody
538− p_seqBody =
539+ p_seqBody = sitcc . sep
539− sequence_ .
540+ (comma >> breakpoint)
540− intersperse (vlayout (pure ()) newline) .
541− withSep comma (located' (sitcc . p_stmt))
541+ (located' (sitcc . p_stmt))
542 stmts = init xs
542 stmts = init xs
543 yield = last xs
543 yield = last xs
544 lists = foldr (liftAppend . gatherStmt) [] stmts
544 lists = foldr (liftAppend . gatherStmt) [] stmts
@@ -557,7 +557,7 @@ p_hsExpr = \case
557 ParStmtCtxt _ -> notImplemented "ParStmtCtxt"
557 ParStmtCtxt _ -> notImplemented "ParStmtCtxt"
558 TransStmtCtxt _ -> notImplemented "TransStmtCtxt"
558 TransStmtCtxt _ -> notImplemented "TransStmtCtxt"
559 ExplicitList _ _ xs ->
559 ExplicitList _ _ xs ->
560− brackets $ velt (withSep comma (located' p_hsExpr) xs)
560+ brackets . sitcc $ sep (comma >> breakpoint) (sitcc . located' p_hsExpr) xs
561 RecordCon {..} -> do
561 RecordCon {..} -> do
562 located rcon_con_name atom
562 located rcon_con_name atom
563 breakpoint
563 breakpoint
@@ -567,11 +567,12 @@ p_hsExpr = \case
567 case rec_dotdot of
567 case rec_dotdot of
568 Just {} -> [txt ".."]
568 Just {} -> [txt ".."]
569 Nothing -> []
569 Nothing -> []
570− inci $ braces $ velt (withSep comma id (fields <> dotdot))
570+ inci . braces . sitcc $ sep (comma >> breakpoint) sitcc (fields <> dotdot)
571 RecordUpd {..} -> do
571 RecordUpd {..} -> do
572 located rupd_expr p_hsExpr
572 located rupd_expr p_hsExpr
573 breakpoint
573 breakpoint
574+ inci . braces . sitcc $
574− inci $ braces $ velt (withSep comma (located' p_hsRecField) rupd_flds)
575+ sep (comma >> breakpoint) (sitcc . located' p_hsRecField) rupd_flds
575 ExprWithTySig affix x -> sitcc $ do
576 ExprWithTySig affix x -> sitcc $ do
576 located x p_hsExpr
577 located x p_hsExpr
577 breakpoint
578 breakpoint
@@ -582,21 +583,21 @@ p_hsExpr = \case
582 located hsib_body p_hsType
583 located hsib_body p_hsType
583 ArithSeq NoExt _ x -> do
584 ArithSeq NoExt _ x -> do
584 case x of
585 case x of
585− From from -> brackets $ do
586+ From from -> brackets . sitcc $ do
586 located from p_hsExpr
587 located from p_hsExpr
587 breakpoint
588 breakpoint
589− FromThen from next -> brackets $ do
590+ FromThen from next -> brackets . sitcc $ do
590− velt (withSep comma (located' p_hsExpr) [from, next])
591+ sitcc $ sep (comma >> breakpoint) (located' p_hsExpr) [from, next]
591 breakpoint
592 breakpoint
593− FromTo from to -> brackets $ do
594+ FromTo from to -> brackets . sitcc $ do
594 located from p_hsExpr
595 located from p_hsExpr
595 breakpoint
596 breakpoint
596 txt ".. "
597 txt ".. "
597 located to p_hsExpr
598 located to p_hsExpr
598− FromThenTo from next to -> brackets $ do
599+ FromThenTo from next to -> brackets . sitcc $ do
599− velt (withSep comma (located' p_hsExpr) [from, next])
600+ sitcc $ sep (comma >> breakpoint) (located' p_hsExpr) [from, next]
600 breakpoint
601 breakpoint
601 txt ".. "
602 txt ".. "
602 located to p_hsExpr
603 located to p_hsExpr
@@ -680,9 +681,9 @@ p_patSynBind (XPatSynBind NoExt) = notImplemented "XPatSynBind"
680p_patSynDetails :: HsPatSynDetails (Located RdrName) -> R ()
681p_patSynDetails :: HsPatSynDetails (Located RdrName) -> R ()
681p_patSynDetails = \case
682p_patSynDetails = \case
682 PrefixCon xs ->
683 PrefixCon xs ->
683− velt' (p_rdrName <$> xs)
684+ sitcc $ sep breakpoint p_rdrName xs
684 RecCon xs ->
685 RecCon xs ->
685− velt' (p_rdrName . recordPatSynPatVar <$> xs)
686+ sitcc $ sep breakpoint (p_rdrName . recordPatSynPatVar) xs
686 InfixCon _ _ -> notImplemented "InfixCon"
687 InfixCon _ _ -> notImplemented "InfixCon"
688p_pat :: Pat GhcPs -> R ()
689p_pat :: Pat GhcPs -> R ()
@@ -702,13 +703,13 @@ p_pat = \case
703 located pat p_pat
704 located pat p_pat
704 ListPat NoExt pats -> do
705 ListPat NoExt pats -> do
705− brackets $ velt (withSep comma (located' p_pat) pats)
706+ brackets . sitcc $ sep (comma >> breakpoint) (located' p_pat) pats
706 TuplePat NoExt pats boxing -> do
707 TuplePat NoExt pats boxing -> do
708 case boxing of
709 case boxing of
709 Boxed -> parens
710 Boxed -> parens
710 Unboxed -> parensHash
711 Unboxed -> parensHash
711− f $ velt (withSep comma (located' p_pat) pats)
712+ f . sitcc $ sep (comma >> breakpoint) (sitcc . located' p_pat) pats
712 SumPat NoExt pat _ _ -> do
713 SumPat NoExt pat _ _ -> do
713 -- XXX I'm not sure about this one.
714 -- XXX I'm not sure about this one.
714 located pat p_pat
715 located pat p_pat
@@ -718,14 +719,14 @@ p_pat = \case
718 p_rdrName pat
719 p_rdrName pat
719 unless (null xs) $ do
720 unless (null xs) $ do
720 breakpoint
721 breakpoint
721− inci $ velt' (located' p_pat <$> xs)
722+ inci . sitcc $ sep breakpoint (sitcc . located' p_pat) xs
722 RecCon (HsRecFields fields dotdot) -> do
723 RecCon (HsRecFields fields dotdot) -> do
723 p_rdrName pat
724 p_rdrName pat
724 breakpoint
725 breakpoint
725 let f = \case
726 let f = \case
726 Nothing -> txt ".."
727 Nothing -> txt ".."
727 Just x -> located x p_pat_hsRecField
728 Just x -> located x p_pat_hsRecField
728− inci . braces . velt . withSep comma f $ case dotdot of
729+ inci . braces . sitcc . sep (comma >> breakpoint) f $ case dotdot of
729 Nothing -> Just <$> fields
730 Nothing -> Just <$> fields
730 Just n -> (Just <$> take n fields) ++ [Nothing]
731 Just n -> (Just <$> take n fields) ++ [Nothing]
731 InfixCon x y -> do
732 InfixCon x y -> do
@@ -899,7 +900,7 @@ exprPlacement = \case
899 RecordCon NoExt _ _ -> Hanging
900 RecordCon NoExt _ _ -> Hanging
900 HsProc NoExt (L s _) _ ->
901 HsProc NoExt (L s _) _ ->
901 -- Indentation breaks if pattern is longer than one line and left hanging.
902 -- Indentation breaks if pattern is longer than one line and left hanging.
902− -- Consequentally, once apply hanging when it is safe.
903+ -- Consequently, only apply hanging when it is safe.
903 if isOneLineSpan s
904 if isOneLineSpan s
904 then Hanging
905 then Hanging
905 else Normal
906 else Normal