@@ -15,12 +15,12 @@ import Data.List (sortOn)
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
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
117 line (txt "where")
117 line (txt "where")
118 inci (located grhssLocalBinds p_hsLocalBinds)
118 inci (located grhssLocalBinds p_hsLocalBinds)
120data GroupStyle
120data GroupStyle
121− = Pattern
121+ = Guard
122 | MultiIf
122 | MultiIf
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
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
239+ Missing NoExt -> True
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
253+ let isFirst = i == 0
254+ isLast = i == arity - 1
257+ unless (isFirst || isLast) space
259+ unless isFirst 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
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'
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'
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