on master help sign in
Fix guards
commitb1299795166365970a15c6d73b7d9287737d9b0a authormrkkrp <mark.karpov@tweag.io> dateThu 23 May 2019, 12:18 (7 years ago) parent61f4960
3 files changed+37−8
data/examples/declaration/value/function/guards-out.hs+14 data/examples/declaration/value/function/guards.hs+12 src/Ormolu/Printer/Meat/Declaration/Value.hs+11−8
data/examples/declaration/value/function/guards-out.hsnew file+14
@@ -0,0 +1,14 @@
1+foo :: Int -> Int
2+foo x
3+ | x == 5 = 10
4+ | otherwise = 12
5+
6+bar :: Int -> Int
7+bar x
8+ | x == 5 =
9+ foo x
10+ + foo 10
11+ | x == 6 =
12+ foo x
13+ + foo 20
14+ | otherwise = foo 100
data/examples/declaration/value/function/guards.hsnew file+12
@@ -0,0 +1,12 @@
1+foo :: Int -> Int
2+foo x
3+ | x == 5 = 10
4+ | otherwise = 12
5+
6+bar :: Int -> Int
7+bar x
8+ | x == 5 = foo x
9+ + foo 10
10+ | x == 6 = foo x
11+ + foo 20
12+ | otherwise = foo 100
src/Ormolu/Printer/Meat/Declaration/Value.hs+11−8
@@ -80,10 +80,10 @@ p_match style Match {..} = do
8080 inci' (velt' (located' p_pat <$> m_pats))
8181 return inci'
8282 inci' $ do
83− space
8483 let GRHSs {..} = m_grhss
85− unless (length grhssGRHSs > 1) . txt $
86− case style of
84+ unless (length grhssGRHSs > 1) $ do
85+ space
86+ txt $ case style of
8787 Function _ -> "="
8888 _ -> "->"
8989 let combinedSpans = combineSrcSpans' $
@@ -101,9 +101,6 @@ p_match style Match {..} = do
101101 line (txt "where")
102102 inci (located grhssLocalBinds p_hsLocalBinds)
103103
104−getGRHSSpan :: GRHS GhcPs (LHsExpr GhcPs) -> SrcSpan
105−getGRHSSpan (GRHS _ body) = getSpan body
106−
107104p_grhs :: GRHS GhcPs (LHsExpr GhcPs) -> R ()
108105p_grhs (GRHS guards body) =
109106 case guards of
@@ -111,9 +108,9 @@ p_grhs (GRHS guards body) =
111108 xs -> do
112109 txt "| "
113110 velt $ withSep comma (located' p_stmt) xs
114− txt " ->"
111+ txt " ="
115112 breakpoint
116− p_body
113+ inci p_body
117114 where
118115 p_body = located body p_hsExpr
119116
@@ -237,3 +234,9 @@ p_hsExpr = \case
237234 EViewPat {} -> notImplemented "EViewPat"
238235 ELazyPat {} -> notImplemented "ELazyPat"
239236 HsWrap {} -> notImplemented "HsWrap"
237+
238+----------------------------------------------------------------------------
239+-- Helpers
240+
241+getGRHSSpan :: GRHS GhcPs (LHsExpr GhcPs) -> SrcSpan
242+getGRHSSpan (GRHS _ body) = getSpan body