on master help sign in
Various adjustments
777524bmrkkrp
data/examples/declaration/value/function/arithmetic-sequences-out.hs+2−2
@@ -1,4 +1,4 @@
1−foo = [0 ..]
1+foo = [0..]
2
2
3bar x =
3bar x =
4 [ 0
4 [ 0
@@ -11,4 +11,4 @@ baz x =
11 .. x
11 .. x
12 ]
12 ]
13
13
14−barbaz x = [0, 1 ..]
14+barbaz x = [0, 1..]
data/examples/declaration/value/function/multi-way-if-out.hs+4−5
@@ -2,8 +2,7 @@
2foo x = if | x == 5 -> 5
2foo x = if | x == 5 -> 5
3
3
4bar x y =
4bar x y =
5− if
6− | x > y -> x
5+ if | x > y -> x
7− | x < y ->
6+ | x < y ->
8− y
7+ y
9− | otherwise -> x
8+ | otherwise -> x
data/examples/declaration/value/function/tuple-sections-out.hs+3−10
@@ -1,15 +1,8 @@
1{-# LANGUAGE TupleSections #-}
1{-# LANGUAGE TupleSections #-}
2−foo = (, 2)
2+foo = (,2)
3
3
4−bar = (, 5, )
4+bar = (,5,)
5
5
6baz =
6baz =
7− (
8− ,
9− , 5
7+ ( ,,5,6,7,,,
10− , 6
11− , 7
12− ,
13− ,
14− ,
15 )
8 )
data/examples/declaration/value/function/unboxed-sums-out.hs+4−11
@@ -1,15 +1,8 @@
1{-# LANGUAGE UnboxedSums #-}
1{-# LANGUAGE UnboxedSums #-}
2−foo = (# 1| #)
2+foo = (# 1 | #)
3
3
4−bar = (# | | 2| #)
4+bar = (# | | 2 | #)
5
5
6baz =
6baz =
7− (#
8− |
9− |
10− | 10
7+ (# | | | 10 | | | | |
11− |
12− |
13− |
14− |
15− | #)
8+ #)
data/examples/declaration/value/function/unboxed-tuples-out.hs+2−1
@@ -4,4 +4,5 @@ foo = (# 1, 2, 3 #)
4bar =
4bar =
5 (# 1
5 (# 1
6 , 2
6 , 2
7− , 3 #)
7+ , 3
8+ #)
src/Ormolu/Printer/Combinators.hs+4−3
@@ -239,9 +239,9 @@ brackets m = sitcc $ do
239
239
240bracketsPar :: R () -> R ()
240bracketsPar :: R () -> R ()
241bracketsPar m = sitcc $ do
241bracketsPar m = sitcc $ do
242− txt "[:"
242+ txt "[: "
243 m
243 m
244− txt ":]"
244+ txt " :]"
245
245
246-- | Surround given entity by parentheses @(@ and @)@.
246-- | Surround given entity by parentheses @(@ and @)@.
247
247
@@ -257,7 +257,8 @@ parensHash :: R () -> R ()
257parensHash m = sitcc $ do
257parensHash m = sitcc $ do
258 txt "(# "
258 txt "(# "
259 m
259 m
260+ breakpoint
260− txt " #)"
261+ txt "#)"
261
262
262-- | Surround given entity by optional space before and a newline after, iff
263-- | Surround given entity by optional space before and a newline after, iff
263-- current layout is multiline.
264-- current layout is multiline.
src/Ormolu/Printer/Meat/Declaration/Value.hs+33−19
@@ -15,12 +15,12 @@ import Data.List (sortOn)
15import GHC
15import GHC
16import Ormolu.Printer.Combinators
16import Ormolu.Printer.Combinators
17import Ormolu.Printer.Meat.Common
17import Ormolu.Printer.Meat.Common
18−import Ormolu.Printer.Meat.Type
19import Ormolu.Printer.Meat.Declaration.Pat
18import Ormolu.Printer.Meat.Declaration.Pat
20import Ormolu.Printer.Meat.Declaration.Signature
19import Ormolu.Printer.Meat.Declaration.Signature
20+import Ormolu.Printer.Meat.Type
21import Ormolu.Utils
21import Ormolu.Utils
22−import SrcLoc (isOneLineSpan)
23import Outputable (Outputable (..))
22import Outputable (Outputable (..))
23+import SrcLoc (isOneLineSpan)
24import qualified Data.List.NonEmpty as NE
24import qualified Data.List.NonEmpty as NE
25
25
26p_valDecl :: HsBindLR GhcPs GhcPs -> R ()
26p_valDecl :: HsBindLR GhcPs GhcPs -> R ()
@@ -111,14 +111,14 @@ p_match style m_pats m_grhss = do
111 case style of
111 case style of
112 Lambda -> return ()
112 Lambda -> return ()
113 _ -> breakpoint
113 _ -> breakpoint
114− newlineSep (located' (p_grhs Pattern)) grhssGRHSs
114+ newlineSep (located' (p_grhs Guard)) grhssGRHSs
115 unless (GHC.isEmptyLocalBindsPR (unL grhssLocalBinds)) $ do
115 unless (GHC.isEmptyLocalBindsPR (unL grhssLocalBinds)) $ do
116 newline
116 newline
117 line (txt "where")
117 line (txt "where")
118 inci (located grhssLocalBinds p_hsLocalBinds)
118 inci (located grhssLocalBinds p_hsLocalBinds)
119
119
120data GroupStyle
120data GroupStyle
121− = Pattern
121+ = Guard
122 | MultiIf
122 | MultiIf
123
123
124p_grhs :: GroupStyle -> GRHS GhcPs (LHsExpr GhcPs) -> R ()
124p_grhs :: GroupStyle -> GRHS GhcPs (LHsExpr GhcPs) -> R ()
@@ -130,7 +130,7 @@ p_grhs style (GRHS NoExt guards body) =
130 velt $ withSep comma (located' p_stmt) xs
130 velt $ withSep comma (located' p_stmt) xs
131 space
131 space
132 txt $ case style of
132 txt $ case style of
133− Pattern -> "="
133+ Guard -> "="
134 MultiIf -> "->"
134 MultiIf -> "->"
135 breakpoint
135 breakpoint
136 inci p_body
136 inci p_body
@@ -234,17 +234,32 @@ p_hsExpr = \case
234 breakpoint
234 breakpoint
235 inci (located x p_hsExpr)
235 inci (located x p_hsExpr)
236 ExplicitTuple NoExt args boxity -> do
236 ExplicitTuple NoExt args boxity -> do
237+ let isSection = any (isMissing . unL) args
238+ isMissing = \case
239+ Missing NoExt -> True
240+ _ -> False
237 let parens' =
241 let parens' =
238 case boxity of
242 case boxity of
239 Boxed -> parens
243 Boxed -> parens
240 Unboxed -> parensHash
244 Unboxed -> parensHash
245+ parens' $ if isSection
246+ then sequence_ (withSep (txt ",") (located' p_hsTupArg) args)
241− parens' $ velt (withSep comma (located' p_hsTupArg) args)
247+ else velt (withSep comma (located' p_hsTupArg) args)
242− ExplicitSum NoExt tag arity x -> do
248+ ExplicitSum NoExt tag arity e -> do
243 let before = tag - 1
249 let before = tag - 1
244 after = arity - before - 1
250 after = arity - before - 1
245− args = replicate before Nothing <> [Just x] <> replicate after Nothing
251+ args = replicate before Nothing <> [Just e] <> replicate after Nothing
252+ f (x,i) = do
253+ let isFirst = i == 0
254+ isLast = i == arity - 1
255+ case x of
256+ Nothing ->
257+ unless (isFirst || isLast) space
258+ Just l -> do
259+ unless isFirst space
260+ located l p_hsExpr
261+ unless isLast space
246− parensHash $
262+ parensHash $ sequence_ (withSep (txt "|") f (zip args [0..]))
247− velt (withSep (txt "| ") (maybe (pure ()) (located' p_hsExpr)) args)
248 HsCase NoExt e mgroup -> do
263 HsCase NoExt e mgroup -> do
249 txt "case "
264 txt "case "
250 located e p_hsExpr
265 located e p_hsExpr
@@ -265,10 +280,8 @@ p_hsExpr = \case
265 breakpoint
280 breakpoint
266 inci (p_hsExpr x)
281 inci (p_hsExpr x)
267 HsMultiIf NoExt guards -> do
282 HsMultiIf NoExt guards -> do
268− txt "if"
283+ txt "if "
269− inci $ forM_ guards $ \g -> do
270− breakpoint
271− located g (p_grhs MultiIf)
284+ sitcc $ newlineSep (located' (p_grhs MultiIf)) guards
272 HsLet NoExt localBinds e -> do
285 HsLet NoExt localBinds e -> do
273 txt "let "
286 txt "let "
274 sitcc (located localBinds p_hsLocalBinds)
287 sitcc (located localBinds p_hsLocalBinds)
@@ -300,24 +313,25 @@ p_hsExpr = \case
300 let HsWC {..} = affix
313 let HsWC {..} = affix
301 HsIB {..} = hswc_body
314 HsIB {..} = hswc_body
302 located hsib_body p_hsType
315 located hsib_body p_hsType
303− ArithSeq NoExt _ x ->
316+ ArithSeq NoExt _ x -> do
317+ let breakpoint' = vlayout (return ()) newline
304 case x of
318 case x of
305 From from -> brackets $ do
319 From from -> brackets $ do
306 located from p_hsExpr
320 located from p_hsExpr
307− breakpoint
321+ breakpoint'
308 txt ".."
322 txt ".."
309 FromThen from next -> brackets $ do
323 FromThen from next -> brackets $ do
310 velt (withSep comma (located' p_hsExpr) [from, next])
324 velt (withSep comma (located' p_hsExpr) [from, next])
311− breakpoint
325+ breakpoint'
312 txt ".."
326 txt ".."
313 FromTo from to -> brackets $ do
327 FromTo from to -> brackets $ do
314 located from p_hsExpr
328 located from p_hsExpr
315− breakpoint
329+ breakpoint'
316 txt ".. "
330 txt ".. "
317 located to p_hsExpr
331 located to p_hsExpr
318 FromThenTo from next to -> brackets $ do
332 FromThenTo from next to -> brackets $ do
319 velt (withSep comma (located' p_hsExpr) [from, next])
333 velt (withSep comma (located' p_hsExpr) [from, next])
320− breakpoint
334+ breakpoint'
321 txt ".. "
335 txt ".. "
322 located to p_hsExpr
336 located to p_hsExpr
323 HsSCC NoExt _ name x -> do
337 HsSCC NoExt _ name x -> do