@@ -1,4 +1,5 @@
11{-# LANGUAGE LambdaCase #-}
2+{-# LANGUAGE MultiWayIf #-}
23{-# LANGUAGE OverloadedStrings #-}
34{-# LANGUAGE RecordWildCards #-}
45{-# LANGUAGE TypeApplications #-}
@@ -21,12 +22,12 @@ import Data.Char (isPunctuation, isSymbol)
2122import Data.Data hiding (Infix, Prefix)
2223import Data.Functor ((<&>))
2324import Data.List (intersperse, sortOn)
24−import Data.List.NonEmpty ((<|), NonEmpty (..))
25+import Data.List.NonEmpty (NonEmpty (..), (<|))
2526import qualified Data.List.NonEmpty as NE
2627import Data.Text (Text)
2728import qualified Data.Text as Text
2829import GHC
29−import OccName (mkVarOcc)
30+import OccName (occNameString)
3031import Ormolu.Printer.Combinators
3132import Ormolu.Printer.Internal
3233import Ormolu.Printer.Meat.Common
@@ -60,7 +61,7 @@ data Placement
6061 -- should use it and avoid bumping one level
6162 -- of indentation
6263 Hanging
63− deriving (Eq)
64+ deriving (Eq, Show)
6465
6566p_valDecl :: HsBindLR GhcPs GhcPs -> R ()
6667p_valDecl = \case
@@ -179,25 +180,24 @@ p_match' placer render style isInfix strictness m_pats GRHSs {..} = do
179180 NoSrcStrict -> return ()
180181 SrcStrict -> txt "!"
181182 SrcLazy -> txt "~"
182− inci' <- case NE.nonEmpty m_pats of
183− Nothing -> id <$ case style of
184− Function name -> p_rdrName name
185− _ -> return ()
183+ indentBody <- case NE.nonEmpty m_pats of
184+ Nothing ->
185+ False <$ case style of
186+ Function name -> p_rdrName name
187+ _ -> return ()
186188 Just ne_pats -> do
187− let combinedSpans =
188− combineSrcSpans' $
189− getLoc <$> ne_pats
190− inci' =
191− if isOneLineSpan combinedSpans
192− then id
193− else inci
189+ let combinedSpans = case style of
190+ Function name -> combineSrcSpans (getLoc name) patSpans
191+ _ -> patSpans
192+ patSpans = combineSrcSpans' (getLoc <$> ne_pats)
193+ indentBody = not (isOneLineSpan combinedSpans)
194194 switchLayout [combinedSpans] $ do
195195 let stdCase = sep breakpoint (located' p_pat) m_pats
196196 case style of
197197 Function name ->
198198 p_infixDefHelper
199199 isInfix
200− inci'
200+ indentBody
201201 (p_rdrName name)
202202 (located' p_pat <$> m_pats)
203203 PatternBind -> stdCase
@@ -212,7 +212,7 @@ p_match' placer render style isInfix strictness m_pats GRHSs {..} = do
212212 when needsSpace space
213213 sitcc stdCase
214214 LambdaCase -> stdCase
215− return inci'
215+ return indentBody
216216 let -- Calculate position of end of patterns. This is useful when we decide
217217 -- about putting certain constructions in hanging positions.
218218 endOfPats = case NE.nonEmpty m_pats of
@@ -224,15 +224,8 @@ p_match' placer render style isInfix strictness m_pats GRHSs {..} = do
224224 Case -> True
225225 LambdaCase -> True
226226 _ -> False
227− let hasGuards = withGuards grhssGRHSs
228− unless (length grhssGRHSs > 1) $
229− case style of
230− Function _ | hasGuards -> return ()
231− Function _ -> space >> txt "="
232− PatternBind -> space >> txt "="
233− s | isCase s && hasGuards -> return ()
234− _ -> space >> txt "->"
235− let grhssSpan =
227+ hasGuards = withGuards grhssGRHSs
228+ grhssSpan =
236229 combineSrcSpans' $
237230 getGRHSSpan . unLoc <$> NE.fromList grhssGRHSs
238231 patGrhssSpan =
@@ -260,7 +253,14 @@ p_match' placer render style isInfix strictness m_pats GRHSs {..} = do
260253 txt "where"
261254 unless whereIsEmpty breakpoint
262255 inci $ located grhssLocalBinds p_hsLocalBinds
263− inci' $ do
256+ inciIf indentBody $ do
257+ unless (length grhssGRHSs > 1) $
258+ case style of
259+ Function _ | hasGuards -> return ()
260+ Function _ -> space >> inci equals
261+ PatternBind -> space >> inci equals
262+ s | isCase s && hasGuards -> return ()
263+ _ -> space >> txt "->"
264264 switchLayout [patGrhssSpan] $
265265 placeHanging placement p_body
266266 inci p_where
@@ -284,11 +284,11 @@ p_grhs' placer render style (GRHS NoExtField guards body) =
284284 xs -> do
285285 txt "|"
286286 space
287− sitcc (sep (comma >> breakpoint) (sitcc . located' p_stmt) xs)
287+ sitcc (sep commaDel (sitcc . located' p_stmt) xs)
288288 space
289− txt $ case style of
290− EqualSign -> "="
291− RightArrow -> "->"
289+ inci $ case style of
290+ EqualSign -> equals
291+ RightArrow -> txt "->"
292292 placeHanging placement p_body
293293 where
294294 placement =
@@ -316,7 +316,7 @@ p_hsCmd = \case
316316 HsHigherOrderApp -> txt "-<<"
317317 placeHanging (exprPlacement (unLoc input)) $
318318 located input p_hsExpr
319− HsCmdArrForm NoExtField form Prefix _ cmds -> banana $ sitcc $ do
319+ HsCmdArrForm NoExtField form Prefix _ cmds -> banana $ do
320320 located form p_hsExpr
321321 unless (null cmds) $ do
322322 breakpoint
@@ -353,7 +353,14 @@ p_hsCmdTop = \case
353353 HsCmdTop NoExtField cmd -> located cmd p_hsCmd
354354 XCmdTop x -> noExtCon x
355355
356−withSpacing :: Data a => (a -> R ()) -> Located a -> R ()
356+-- | Render an expression preserving blank lines between such consecutive
357+-- expressions found in the original source code.
358+withSpacing ::
359+ -- | Rendering function
360+ (a -> R ()) ->
361+ -- | Entity to render
362+ Located a ->
363+ R ()
357364withSpacing f l = located l $ \x -> do
358365 case getLoc l of
359366 UnhelpfulSpan _ -> f x
@@ -464,37 +471,31 @@ gatherStmtBlock (XParStmtBlock x) = noExtCon x
464471p_hsLocalBinds :: HsLocalBindsLR GhcPs GhcPs -> R ()
465472p_hsLocalBinds = \case
466473 HsValBinds NoExtField (ValBinds NoExtField bag lsigs) -> do
467− let ssStart =
468− either
469− (srcSpanStart . getLoc)
470− (srcSpanStart . getLoc)
471− items =
472− (Left <$> bagToList bag) ++ (Right <$> lsigs)
473− p_item (Left x) = located x p_valDecl
474− p_item (Right x) = located x p_sigDecl
475474 -- When in a single-line layout, there is a chance that the inner
476475 -- elements will also contain semicolons and they will confuse the
477476 -- parser. so we request braces around every element except the last.
478477 br <- layoutToBraces <$> getLayout
479− sitcc $
480− sepSemi
481− ( \(p, i) ->
482− ( case p of
483− SinglePos -> id
484− FirstPos -> br
485− MiddlePos -> br
486− LastPos -> id
487− )
488− (p_item i)
489− )
490− (attachRelativePos $ sortOn ssStart items)
478+ let items =
479+ let injectLeft (L l x) = L l (Left x)
480+ injectRight (L l x) = L l (Right x)
481+ in (injectLeft <$> bagToList bag) ++ (injectRight <$> lsigs)
482+ positionToBracing = \case
483+ SinglePos -> id
484+ FirstPos -> br
485+ MiddlePos -> br
486+ LastPos -> id
487+ p_item' (p, item) =
488+ positionToBracing p $
489+ withSpacing (either p_valDecl p_sigDecl) item
490+ binds = sortOn (srcSpanStart . getLoc) items
491+ sitcc $ sepSemi p_item' (attachRelativePos binds)
491492 HsValBinds NoExtField _ -> notImplemented "HsValBinds"
492493 HsIPBinds NoExtField (IPBinds NoExtField xs) ->
493494 -- Second argument of IPBind is always Left before type-checking.
494495 let p_ipBind (IPBind NoExtField (Left name) expr) = do
495496 atom name
496497 space
497− txt "="
498+ equals
498499 breakpoint
499500 useBraces $ inci $ located expr p_hsExpr
500501 p_ipBind (IPBind NoExtField (Right _) _) =
@@ -513,19 +514,13 @@ p_hsRecField HsRecField {..} = do
513514 p_rdrName hsRecFieldLbl
514515 unless hsRecPun $ do
515516 space
516− txt "="
517+ equals
517518 let placement =
518519 if onTheSameLine (getLoc hsRecFieldLbl) (getLoc hsRecFieldArg)
519520 then exprPlacement (unLoc hsRecFieldArg)
520521 else Normal
521522 placeHanging placement (located hsRecFieldArg p_hsExpr)
522523
523−p_hsTupArg :: HsTupArg GhcPs -> R ()
524−p_hsTupArg = \case
525− Present NoExtField x -> located x p_hsExpr
526− Missing NoExtField -> pure ()
527− XTupArg x -> noExtCon x
528−
529524p_hsExpr :: HsExpr GhcPs -> R ()
530525p_hsExpr = p_hsExpr' N
531526
@@ -589,23 +584,21 @@ p_hsExpr' s = \case
589584 -- do-block or case expression it is not a good idea. It seems
590585 -- to be safe to always bump indentation when the function
591586 -- expression is parenthesised.
592− indent =
587+ doIndent =
593588 case func of
594− L _ (HsPar NoExtField _) -> inci
595− L _ (HsAppType NoExtField _ _) -> inci
596− L _ (HsMultiIf NoExtField _) -> inci
597− L spn _ ->
598− if isOneLineSpan spn
599− then inci
600− else id
601− ub <- getLayout <&> \case
602− SingleLine -> useBraces
603− MultiLine -> id
589+ L _ (HsPar NoExtField _) -> True
590+ L _ (HsAppType NoExtField _ _) -> True
591+ L _ (HsMultiIf NoExtField _) -> True
592+ L spn _ -> isOneLineSpan spn
593+ ub <-
594+ getLayout <&> \case
595+ SingleLine -> useBraces
596+ MultiLine -> id
604597 ub $ do
605598 located func (p_hsExpr' s)
606599 breakpoint
607− indent $ sep breakpoint (located' p_hsExpr) initp
608− indent $ do
600+ inciIf doIndent $ sep breakpoint (located' p_hsExpr) initp
601+ inciIf doIndent $ do
609602 unless (null initp) breakpoint
610603 located lastp p_hsExpr
611604 Hanging -> do
@@ -620,10 +613,15 @@ p_hsExpr' s = \case
620613 breakpoint
621614 inci $ do
622615 txt "@"
616+ -- Insert a space when the type is represented as a TH splice to avoid
617+ -- gluing @ and $ together.
618+ case unLoc (hswc_body a) of
619+ HsSpliceTy {} -> space
620+ _ -> return ()
623621 located (hswc_body a) p_hsType
624622 OpApp NoExtField x op y -> do
625623 let opTree = OpBranch (exprOpTree x) op (exprOpTree y)
626− p_exprOpTree True s (reassociateOpTree getOpName opTree)
624+ p_exprOpTree s (reassociateOpTree getOpName opTree)
627625 NegApp NoExtField e _ -> do
628626 txt "-"
629627 space
@@ -640,22 +638,27 @@ p_hsExpr' s = \case
640638 let isRecordDot' = isRecordDot (unLoc op) (getLoc x)
641639 unless (useRecordDot' && isRecordDot') breakpoint
642640 inci (located x p_hsExpr)
643− ExplicitTuple NoExtField args boxity -> do
641+ ExplicitTuple NoExtField args boxity ->
644642 let isSection = any (isMissing . unLoc) args
645643 isMissing = \case
646644 Missing NoExtField -> True
647645 _ -> False
648− let parens' =
646+ p_arg = \case
647+ Present NoExtField x -> located x p_hsExpr
648+ Missing NoExtField -> pure ()
649+ XTupArg x -> noExtCon x
650+ p_larg = sitcc . located' p_arg
651+ parens' =
649652 case boxity of
650653 Boxed -> parens
651654 Unboxed -> parensHash
652− if isSection
653− then
654− switchLayout [] . parens' s $
655− sep comma (located' p_hsTupArg) args
656− else
657− switchLayout (getLoc <$> args) . parens' s . sitcc $
658− sep (comma >> breakpoint) (sitcc . located' p_hsTupArg) args
655+ in if isSection
656+ then
657+ switchLayout [] . parens' s $
658+ sep comma p_larg args
659+ else
660+ switchLayout (getLoc <$> args) . parens' s $
661+ sep commaDel p_larg args
659662 ExplicitSum NoExtField tag arity e ->
660663 p_unboxedSum N tag arity (located e p_hsExpr)
661664 HsCase NoExtField e mgroup ->
@@ -663,8 +666,9 @@ p_hsExpr' s = \case
663666 HsIf NoExtField _ if' then' else' ->
664667 p_if exprPlacement p_hsExpr if' then' else'
665668 HsMultiIf NoExtField guards -> do
666− txt "if "
667− inci . inci . sitcc $ sep newline (located' (p_grhs RightArrow)) guards
669+ txt "if"
670+ breakpoint
671+ inci . inci $ sep newline (located' (p_grhs RightArrow)) guards
668672 HsLet NoExtField localBinds e ->
669673 p_let p_hsExpr localBinds e
670674 HsDo NoExtField ctx es -> do
@@ -676,15 +680,15 @@ p_hsExpr' s = \case
676680 sepSemi
677681 (ub . withSpacing (p_stmt' exprPlacement (p_hsExpr' S)))
678682 (unLoc es)
679− compBody = brackets N $ located es $ \xs -> do
683+ compBody = brackets N . located es $ \xs -> do
680684 let p_parBody =
681685 sep
682− (breakpoint >> txt "| ")
686+ (breakpoint >> txt "|" >> space)
683687 p_seqBody
684688 p_seqBody =
685689 sitcc
686690 . sep
687− (comma >> breakpoint)
691+ commaDel
688692 (located' (sitcc . p_stmt))
689693 stmts = init xs
690694 yield = last xs
@@ -705,8 +709,8 @@ p_hsExpr' s = \case
705709 ParStmtCtxt _ -> notImplemented "ParStmtCtxt"
706710 TransStmtCtxt _ -> notImplemented "TransStmtCtxt"
707711 ExplicitList _ _ xs ->
708− brackets s . sitcc $
709− sep (comma >> breakpoint) (sitcc . located' p_hsExpr) xs
712+ brackets s $
713+ sep commaDel (sitcc . located' p_hsExpr) xs
710714 RecordCon {..} -> do
711715 located rcon_con_name atom
712716 breakpoint
@@ -722,8 +726,8 @@ p_hsExpr' s = \case
722726 case rec_dotdot of
723727 Just {} -> [txt ".."]
724728 Nothing -> []
725− inci . braces N . sitcc $
726− sep (comma >> breakpoint) sitcc (fields <> dotdot)
729+ inci . braces N $
730+ sep commaDel sitcc (fields <> dotdot)
727731 RecordUpd {..} -> do
728732 located rupd_expr p_hsExpr
729733 useRecordDot' <- useRecordDot
@@ -741,9 +745,9 @@ p_hsExpr' s = \case
741745 Unambiguous _ n -> n
742746 XAmbiguousFieldOcc x -> noExtCon x
743747 }
744− inci . braces N . sitcc $
748+ inci . braces N $
745749 sep
746− (comma >> breakpoint)
750+ commaDel
747751 (sitcc . located' (p_hsRecField . updName))
748752 rupd_flds
749753 ExprWithTySig NoExtField x HsWC {hswc_body = HsIB {..}} -> sitcc $ do
@@ -756,22 +760,22 @@ p_hsExpr' s = \case
756760 ExprWithTySig NoExtField _ (XHsWildCardBndrs x) -> noExtCon x
757761 ArithSeq NoExtField _ x ->
758762 case x of
759− From from -> brackets s . sitcc $ do
763+ From from -> brackets s $ do
760764 located from p_hsExpr
761765 breakpoint
762766 txt ".."
763− FromThen from next -> brackets s . sitcc $ do
764− sitcc $ sep (comma >> breakpoint) (located' p_hsExpr) [from, next]
767+ FromThen from next -> brackets s $ do
768+ sep commaDel (located' p_hsExpr) [from, next]
765769 breakpoint
766770 txt ".."
767− FromTo from to -> brackets s . sitcc $ do
771+ FromTo from to -> brackets s $ do
768772 located from p_hsExpr
769773 breakpoint
770774 txt ".."
771775 space
772776 located to p_hsExpr
773− FromThenTo from next to -> brackets s . sitcc $ do
774− sitcc $ sep (comma >> breakpoint) (located' p_hsExpr) [from, next]
777+ FromThenTo from next to -> brackets s $ do
778+ sep commaDel (located' p_hsExpr) [from, next]
775779 breakpoint
776780 txt ".."
777781 space
@@ -821,7 +825,7 @@ p_patSynBind PSB {..} = do
821825 breakpoint
822826 located psb_def p_pat
823827 ImplicitBidirectional -> do
824− txt "="
828+ equals
825829 breakpoint
826830 located psb_def p_pat
827831 ExplicitBidirectional mgroup -> do
@@ -848,8 +852,8 @@ p_patSynBind PSB {..} = do
848852 inci $ do
849853 switchLayout (getLoc . recordPatSynPatVar <$> xs) $ do
850854 unless (null xs) breakpoint
851− braces N . sitcc $
852− sep (comma >> breakpoint) (p_rdrName . recordPatSynPatVar) xs
855+ braces N $
856+ sep commaDel (p_rdrName . recordPatSynPatVar) xs
853857 rhs
854858 InfixCon l r -> do
855859 switchLayout [getLoc l, getLoc r] $ do
@@ -903,10 +907,12 @@ p_if placer render if' then' else' = do
903907 breakpoint
904908 inci $ do
905909 txt "then"
910+ space
906911 located then' $ \x ->
907912 placeHanging (placer x) (render x)
908913 breakpoint
909914 txt "else"
915+ space
910916 located else' $ \x ->
911917 placeHanging (placer x) (render x)
912918
@@ -943,13 +949,13 @@ p_pat = \case
943949 txt "!"
944950 located pat p_pat
945951 ListPat NoExtField pats ->
946− brackets S . sitcc $ sep (comma >> breakpoint) (located' p_pat) pats
952+ brackets S $ sep commaDel (located' p_pat) pats
947953 TuplePat NoExtField pats boxing -> do
948− let f =
954+ let parens' =
949955 case boxing of
950956 Boxed -> parens S
951957 Unboxed -> parensHash S
952− f . sitcc $ sep (comma >> breakpoint) (sitcc . located' p_pat) pats
958+ parens' $ sep commaDel (sitcc . located' p_pat) pats
953959 SumPat NoExtField pat tag arity ->
954960 p_unboxedSum S tag arity (located pat p_pat)
955961 ConPatIn pat details ->
@@ -965,7 +971,7 @@ p_pat = \case
965971 let f = \case
966972 Nothing -> txt ".."
967973 Just x -> located x p_pat_hsRecField
968− inci . braces N . sitcc . sep (comma >> breakpoint) f $
974+ inci . braces N . sep commaDel f $
969975 case dotdot of
970976 Nothing -> Just <$> fields
971977 Just (L _ n) -> (Just <$> take n fields) ++ [Nothing]
@@ -1006,7 +1012,7 @@ p_pat_hsRecField HsRecField {..} = do
10061012 p_rdrName (rdrNameFieldOcc x)
10071013 unless hsRecPun $ do
10081014 space
1009− txt "="
1015+ equals
10101016 breakpoint
10111017 inci (located hsRecFieldArg p_pat)
10121018
@@ -1015,17 +1021,15 @@ p_unboxedSum s tag arity m = do
10151021 let before = tag - 1
10161022 after = arity - before - 1
10171023 args = replicate before Nothing <> [Just m] <> replicate after Nothing
1018− f (x, i) = do
1019− let isFirst = i == 0
1020− isLast = i == arity - 1
1024+ f x =
10211025 case x :: Maybe (R ()) of
10221026 Nothing ->
1023− unless (isFirst || isLast) space
1027+ space
10241028 Just m' -> do
1025− unless isFirst space
1029+ space
10261030 m'
1027− unless isLast space
1028− parensHash s $ sep (txt "|") f (zip args [0 ..])
1031+ space
1032+ parensHash s $ sep (txt "|") f args
10291033
10301034p_hsSplice :: HsSplice GhcPs -> R ()
10311035p_hsSplice = \case
@@ -1227,11 +1231,10 @@ exprPlacement = \case
12271231 HsCase NoExtField _ _ -> Hanging
12281232 HsDo NoExtField DoExpr _ -> Hanging
12291233 HsDo NoExtField MDoExpr _ -> Hanging
1230− -- If the rightmost expression in an operator chain is hanging, make the
1231− -- whole block hanging; so that we can use the common @f = foo $ do@
1232− -- style.
1233− OpApp NoExtField _ _ y -> exprPlacement (unLoc y)
1234− -- Same thing for function applications (usually with -XBlockArguments)
1234+ OpApp NoExtField _ op y ->
1235+ case (fmap getOpNameStr . getOpName . unLoc) op of
1236+ Just "$" -> exprPlacement (unLoc y)
1237+ _ -> Normal
12351238 HsApp NoExtField _ y -> exprPlacement (unLoc y)
12361239 HsProc NoExtField p _ ->
12371240 -- Indentation breaks if pattern is longer than one line and left
@@ -1257,15 +1260,16 @@ getOpName = \case
12571260 HsVar NoExtField (L _ a) -> Just a
12581261 _ -> Nothing
12591262
1263+getOpNameStr :: RdrName -> String
1264+getOpNameStr = occNameString . rdrNameOcc
1265+
12601266p_exprOpTree ::
1261− -- | Can use special handling of dollar?
1262− Bool ->
12631267 -- | Bracket style to use
12641268 BracketStyle ->
12651269 OpTree (LHsExpr GhcPs) (LHsExpr GhcPs) ->
12661270 R ()
1267−p_exprOpTree _ s (OpNode x) = located x (p_hsExpr' s)
1268−p_exprOpTree isDollarSpecial s (OpBranch x op y) = do
1271+p_exprOpTree s (OpNode x) = located x (p_hsExpr' s)
1272+p_exprOpTree s (OpBranch x op y) = do
12691273 -- If the beginning of the first argument and the second argument are on
12701274 -- the same line, and the second argument has a hanging form, use hanging
12711275 -- placement.
@@ -1287,44 +1291,54 @@ p_exprOpTree isDollarSpecial s (OpBranch x op y) = do
12871291 MultiLine -> case placement of
12881292 Hanging -> useBraces
12891293 Normal -> dontUseBraces
1290− gotDollar = case getOpName (unLoc op) of
1291− Just rname -> mkVarOcc "$" == rdrNameOcc rname
1292− _ -> False
1294+ opNameStr = (fmap getOpNameStr . getOpName . unLoc) op
1295+ gotDollar = opNameStr == Just "$"
1296+ gotColon = opNameStr == Just ":"
1297+ gotRecordDot = isRecordDot (unLoc op) (opTreeLoc y)
12931298 lhs =
12941299 switchLayout [opTreeLoc x] $
1295− p_exprOpTree (not gotDollar) s x
1296− let p_op = located op (opWrapper . p_hsExpr)
1297− p_y = switchLayout [opTreeLoc y] (p_exprOpTree True N y)
1300+ p_exprOpTree s x
1301+ p_op = located op (opWrapper . p_hsExpr)
1302+ p_y = switchLayout [opTreeLoc y] (p_exprOpTree N y)
12981303 isSection = case (opTreeLoc x, getLoc op) of
12991304 (RealSrcSpan treeSpan, RealSrcSpan opSpan) ->
13001305 srcSpanEndCol treeSpan /= srcSpanStartCol opSpan
13011306 _ -> False
1307+ isDoBlock = \case
1308+ OpNode (L _ HsDo {}) -> True
1309+ _ -> False
13021310 useRecordDot' <- useRecordDot
1303− let isRecordDot' = isRecordDot (unLoc op) (opTreeLoc y)
1304− if useRecordDot' && isRecordDot'
1305− then do
1306− lhs
1307− when isSection space
1308− p_op
1309− p_y
1310− else
1311− if isDollarSpecial
1312− && gotDollar
1313− && placement
1314− == Normal
1315− && isOneLineSpan (opTreeLoc x)
1316− then do
1317− useBraces lhs
1318− space
1319− p_op
1320− breakpoint
1321− inci p_y
1322− else do
1323− ub lhs
1324− placeHanging placement $ do
1325− p_op
1311+ if
1312+ | gotColon -> do
1313+ lhs
1314+ space
1315+ p_op
1316+ case placement of
1317+ Hanging -> do
13261318 space
13271319 p_y
1320+ Normal -> do
1321+ breakpoint
1322+ inciIf (isDoBlock y) p_y
1323+ | gotDollar
1324+ && isOneLineSpan (opTreeLoc x)
1325+ && placement == Normal -> do
1326+ useBraces lhs
1327+ space
1328+ p_op
1329+ breakpoint
1330+ inci p_y
1331+ | useRecordDot' && gotRecordDot -> do
1332+ lhs
1333+ when isSection space
1334+ p_op
1335+ p_y
1336+ | otherwise -> do
1337+ ub lhs
1338+ placeHanging placement $ do
1339+ p_op
1340+ space
1341+ p_y
13281342
13291343-- | Return 'True' if given expression is a record-dot operator expression.
13301344isRecordDot ::
@@ -1335,14 +1349,10 @@ isRecordDot ::
13351349 Bool
13361350isRecordDot op (RealSrcSpan ySpan) = case op of
13371351 HsVar NoExtField (L (RealSrcSpan opSpan) opName) ->
1338− isDot opName && (srcSpanEndCol opSpan == srcSpanStartCol ySpan)
1352+ (getOpNameStr opName == ".") && (srcSpanEndCol opSpan == srcSpanStartCol ySpan)
13391353 _ -> False
13401354isRecordDot _ _ = False
13411355
1342−-- | Check whether a given 'RdrName' is the dot operator.
1343−isDot :: RdrName -> Bool
1344−isDot name = rdrNameOcc name == mkVarOcc "."
1345−
13461356-- | Get annotations for the enclosing element.
13471357getEnclosingAnns :: R [AnnKeywordId]
13481358getEnclosingAnns = do