on master help sign in
Format unboxed sum pattern
be53b3egabriele.lana
data/examples/declaration/value/function/pattern/unboxed-sum-pattern-out.hsnew file+24
@@ -0,0 +1,24 @@
1+{-# LANGUAGE UnboxedSums #-}
2+
3+v = True
4+ where
5+ (# _x #) = (# True #)
6+
7+p = True
8+ where
9+ (# _x | #) = (# | True #)
10+
11+q = True
12+ where
13+ (# | _x | #) = (# | True | #)
14+
15+z = True
16+ where
17+ (# | | _x #) = (# | | True #)
18+
19+z_multiline = True
20+ where
21+ (# | | _x
22+ #) =
23+ (# | | True
24+ #)
data/examples/declaration/value/function/pattern/unboxed-sum-pattern.hsnew file+23
@@ -0,0 +1,23 @@
1+{-# LANGUAGE UnboxedSums #-}
2+
3+v = True
4+ where
5+ (# _x #) = (# True #)
6+
7+p = True
8+ where
9+ (# _x | #) = (# | True #)
10+
11+q = True
12+ where
13+ (# | _x | #) = (# | True | #)
14+
15+z = True
16+ where
17+ (# | | _x #) = (# | | True #)
18+
19+z_multiline = True
20+ where
21+ (# |
22+ | _x #) = (# |
23+ | True #)
src/Ormolu/Printer/Meat/Declaration/Value.hs+21−18
@@ -484,21 +484,8 @@ p_hsExpr = \case
484 sep comma (located' p_hsTupArg) args
484 sep comma (located' p_hsTupArg) args
485 else switchLayout (getLoc <$> args) . parens' . sitcc $
485 else switchLayout (getLoc <$> args) . parens' . sitcc $
486 sep (comma >> breakpoint) (sitcc . located' p_hsTupArg) args
486 sep (comma >> breakpoint) (sitcc . located' p_hsTupArg) args
487− ExplicitSum NoExt tag arity e -> do
487+ ExplicitSum NoExt tag arity e ->
488− let before = tag - 1
489− after = arity - before - 1
490− args = replicate before Nothing <> [Just e] <> replicate after Nothing
491− f (x,i) = do
492− let isFirst = i == 0
493− isLast = i == arity - 1
494− case x of
495− Nothing ->
496− unless (isFirst || isLast) space
497− Just l -> do
498− unless isFirst space
499− located l p_hsExpr
488+ p_unboxedSum tag arity (located e p_hsExpr)
500− unless isLast space
501− parensHash $ sep (txt "|") f (zip args [0..])
502 HsCase NoExt e mgroup -> do
489 HsCase NoExt e mgroup -> do
503 txt "case "
490 txt "case "
504 located e p_hsExpr
491 located e p_hsExpr
@@ -710,9 +697,8 @@ p_pat = \case
710 Boxed -> parens
697 Boxed -> parens
711 Unboxed -> parensHash
698 Unboxed -> parensHash
712 f . sitcc $ sep (comma >> breakpoint) (sitcc . located' p_pat) pats
699 f . sitcc $ sep (comma >> breakpoint) (sitcc . located' p_pat) pats
713− SumPat NoExt pat _ _ -> do
700+ SumPat NoExt pat tag arity ->
714− -- XXX I'm not sure about this one.
715− located pat p_pat
701+ p_unboxedSum tag arity (located pat p_pat)
716 ConPatIn pat details ->
702 ConPatIn pat details ->
717 case details of
703 case details of
718 PrefixCon xs -> sitcc $ do
704 PrefixCon xs -> sitcc $ do
@@ -765,6 +751,23 @@ p_pat_hsRecField HsRecField {..} = do
765 breakpoint
751 breakpoint
766 inci (located hsRecFieldArg p_pat)
752 inci (located hsRecFieldArg p_pat)
767
753
754+p_unboxedSum :: ConTag -> Arity -> R () -> R ()
755+p_unboxedSum tag arity m = do
756+ let before = tag - 1
757+ after = arity - before - 1
758+ args = replicate before Nothing <> [Just m] <> replicate after Nothing
759+ f (x,i) = do
760+ let isFirst = i == 0
761+ isLast = i == arity - 1
762+ case x :: Maybe (R ()) of
763+ Nothing ->
764+ unless (isFirst || isLast) space
765+ Just m' -> do
766+ unless isFirst space
767+ m'
768+ unless isLast space
769+ parensHash $ sep (txt "|") f (zip args [0..])
770+
768p_hsSplice :: HsSplice GhcPs -> R ()
771p_hsSplice :: HsSplice GhcPs -> R ()
769p_hsSplice = \case
772p_hsSplice = \case
770 HsTypedSplice NoExt deco _ expr -> p_hsSpliceTH True expr deco
773 HsTypedSplice NoExt deco _ expr -> p_hsSpliceTH True expr deco