on master help sign in
Refactor printing of tuples and tuple sections
033bb16Mark Karpov
src/Ormolu/Printer/Meat/Declaration/Value.hs+14−15
@@ -520,12 +520,6 @@ p_hsRecField HsRecField {..} = do
520 else Normal
520 else Normal
521 placeHanging placement (located hsRecFieldArg p_hsExpr)
521 placeHanging placement (located hsRecFieldArg p_hsExpr)
522
522
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−
529p_hsExpr :: HsExpr GhcPs -> R ()
523p_hsExpr :: HsExpr GhcPs -> R ()
530p_hsExpr = p_hsExpr' N
524p_hsExpr = p_hsExpr' N
531
525
@@ -638,22 +632,27 @@ p_hsExpr' s = \case
638 let isRecordDot' = isRecordDot (unLoc op) (getLoc x)
632 let isRecordDot' = isRecordDot (unLoc op) (getLoc x)
639 unless (useRecordDot' && isRecordDot') breakpoint
633 unless (useRecordDot' && isRecordDot') breakpoint
640 inci (located x p_hsExpr)
634 inci (located x p_hsExpr)
641− ExplicitTuple NoExtField args boxity -> do
635+ ExplicitTuple NoExtField args boxity ->
642 let isSection = any (isMissing . unLoc) args
636 let isSection = any (isMissing . unLoc) args
643 isMissing = \case
637 isMissing = \case
644 Missing NoExtField -> True
638 Missing NoExtField -> True
645 _ -> False
639 _ -> False
640+ p_arg = \case
641+ Present NoExtField x -> located x p_hsExpr
642+ Missing NoExtField -> pure ()
643+ XTupArg x -> noExtCon x
644+ p_larg = sitcc . located' p_arg
646− let parens' =
645+ parens' =
647 case boxity of
646 case boxity of
648 Boxed -> parens
647 Boxed -> parens
649 Unboxed -> parensHash
648 Unboxed -> parensHash
650− if isSection
649+ in if isSection
651− then
650+ then
652− switchLayout [] . parens' s $
651+ switchLayout [] . parens' s $
653− sep comma (located' p_hsTupArg) args
652+ sep comma p_larg args
654− else
653+ else
655− switchLayout (getLoc <$> args) . parens' s $
654+ switchLayout (getLoc <$> args) . parens' s $
656− sep commaDel (sitcc . located' p_hsTupArg) args
655+ sep commaDel p_larg args
657 ExplicitSum NoExtField tag arity e ->
656 ExplicitSum NoExtField tag arity e ->
658 p_unboxedSum N tag arity (located e p_hsExpr)
657 p_unboxedSum N tag arity (located e p_hsExpr)
659 HsCase NoExtField e mgroup ->
658 HsCase NoExtField e mgroup ->