on master help sign in
Change parens style and how separated lists of items are printed
85d5f78mrkkrp
data/examples/declaration/annotation/annotation-out.hs+1−1
@@ -4,7 +4,7 @@
4 module
4 module
5 ( 5
5 ( 5
6 :: Int
6 :: Int
7− )
7+ )
8 #-}
8 #-}
9
9
10{-# ANN foo "hey" #-}
10{-# ANN foo "hey" #-}
data/examples/declaration/class/default-signatures-out.hs+3−3
@@ -20,9 +20,9 @@ class Bar a where
20
20
21 -- Pointless comment
21 -- Pointless comment
22 default bar
22 default bar
23− :: ( Read a
23+ :: ( Read a,
24− , Semigroup a
24+ Semigroup a
25− )
25+ )
26 => a
26 => a
27 -> a
27 -> a
28 -> a
28 -> a
data/examples/declaration/class/dependency-super-classes-out.hs+3−3
@@ -9,9 +9,9 @@ class (MonadReader r s, MonadWriter w m) => MonadState s m | m -> s where
9
9
10-- | 'MonadParsec'
10-- | 'MonadParsec'
11class
11class
12− ( Stream s -- Token streams
12+ ( Stream s, -- Token streams
13− , MonadPlus m -- Potential for failure
13+ MonadPlus m -- Potential for failure
14− )
14+ )
15 => MonadParsec e s m
15 => MonadParsec e s m
16 | m -> e s where
16 | m -> e s where
17
17
data/examples/declaration/class/functional-dependencies-out.hs+5−5
@@ -10,10 +10,10 @@ class Bar a b | a -> b, b -> a where
10-- | Something else.
10-- | Something else.
11class
11class
12 Baz a b c d
12 Baz a b c d
13− | a b -> c d -- Foo
13+ | a b -> c d, -- Foo
14− , b c -> a d -- Bar
14+ b c -> a d, -- Bar
15− , a c -> b d -- Baz
15+ a c -> b d, -- Baz
16− , a c d -> b
16+ a c d -> b,
17− , a b d -> a b c d where
17+ a b d -> a b c d where
18
18
19 baz :: a -> b
19 baz :: a -> b
data/examples/declaration/class/poly-kinded-classes-out.hs+1−1
@@ -6,4 +6,4 @@ class
6 Bar
6 Bar
7 ( a -- Variable
7 ( a -- Variable
8 :: * -- Star
8 :: * -- Star
9− )
9+ )
data/examples/declaration/class/single-parameters-out.hs+3−3
@@ -13,9 +13,9 @@ class Baz a where
13
13
14 -- | Baz
14 -- | Baz
15 baz
15 baz
16− :: ( a
16+ :: ( a,
17− , a -- ^ First argument
17+ a -- ^ First argument
18− )
18+ )
19 -> a -- ^ Second argument
19 -> a -- ^ Second argument
20 -> a -- ^ Return value
20 -> a -- ^ Return value
21
21
data/examples/declaration/class/super-classes-out.hs+4−4
@@ -7,8 +7,8 @@ class
7 => Baz a
7 => Baz a
8
8
9class
9class
10− ( Foo a -- Foo?
10+ ( Foo a, -- Foo?
11− , Bar a -- Bar?
11+ Bar a, -- Bar?
12− , Baz a -- Baz
12+ Baz a -- Baz
13− )
13+ )
14 => BarBar a
14 => BarBar a
data/examples/declaration/class/type-operators-out.hs+2−2
@@ -17,7 +17,7 @@ class
17class
17class
18 ( f :.
18 ( f :.
19 g
19 g
20− )
20+ )
21 a
21 a
22
22
23class a `Pair` b
23class a `Pair` b
@@ -31,5 +31,5 @@ class (f `Product` g) a
31class
31class
32 ( f `Sum`
32 ( f `Sum`
33 g
33 g
34− )
34+ )
35 a
35 a
data/examples/declaration/data/deriving-strategies-out.hs+3−3
@@ -2,9 +2,9 @@
2newtype Foo = Foo Int
2newtype Foo = Foo Int
3 deriving stock (Eq, Show, Generic)
3 deriving stock (Eq, Show, Generic)
4 deriving anyclass
4 deriving anyclass
5− ( ToJSON
5+ ( ToJSON,
6− , FromJSON
6+ FromJSON
7− )
7+ )
8 deriving newtype (Num)
8 deriving newtype (Num)
9 deriving (Monoid) via (Sum Int)
9 deriving (Monoid) via (Sum Int)
10 deriving
10 deriving
data/examples/declaration/data/gadt/multiple-declaration-out.hs+5−5
@@ -2,14 +2,14 @@ data GADT0 a where
2 GADT01, GADT02 :: Int -> GADT0 a
2 GADT01, GADT02 :: Int -> GADT0 a
3
3
4data GADT1 a where
4data GADT1 a where
5− GADT11
5+ GADT11,
6− , GADT12
6+ GADT12
7 :: Int
7 :: Int
8 -> GADT1 a
8 -> GADT1 a
9
9
10data GADT2 a where
10data GADT2 a where
11− GADT21
11+ GADT21,
12− , GADT21
12+ GADT21,
13− , GADT22
13+ GADT22
14 :: Int
14 :: Int
15 -> GADT2 a
15 -> GADT2 a
data/examples/declaration/data/gadt/record-out.hs+6−5
@@ -2,10 +2,11 @@
2data Foo where
2data Foo where
3 Foo :: {fooX :: Int} -> Foo
3 Foo :: {fooX :: Int} -> Foo
4 Bar
4 Bar
5− :: { fooY :: Int
5+ :: { fooY :: Int,
6− , fooBar, fooBaz :: Bool
6+ fooBar, fooBaz :: Bool,
7− , fooFoo
7+ fooFoo,
8− , barBar
8+ barBar,
9+ bazBaz
9 :: Int
10 :: Int
10− }
11+ }
11 -> Foo
12 -> Foo
data/examples/declaration/data/gadt/record.hs+2−1
@@ -5,5 +5,6 @@ data Foo where
5 Bar :: { fooY :: Int
5 Bar :: { fooY :: Int
6 , fooBar, fooBaz :: Bool
6 , fooBar, fooBaz :: Bool
7 , fooFoo
7 , fooFoo
8− , barBar :: Int
8+ , barBar
9+ , bazBaz :: Int
9 } -> Foo
10 } -> Foo
data/examples/declaration/data/multiline-names-out.hs+2−2
@@ -11,7 +11,7 @@ data (f :* g) a = f a :* g a
11data
11data
12 ( f :+
12 ( f :+
13 g
13 g
14− )
14+ )
15 a
15 a
16 = L (f a)
16 = L (f a)
17 | R (g a)
17 | R (g a)
@@ -23,7 +23,7 @@ data (f `Product` g) a = f a `Product` g a
23data
23data
24 ( f `Sum`
24 ( f `Sum`
25 g
25 g
26− )
26+ )
27 a
27 a
28 = L' (f a)
28 = L' (f a)
29 | R' (g a)
29 | R' (g a)
data/examples/declaration/data/record-out.hs+9−9
@@ -1,18 +1,18 @@
1-- | Something.
1-- | Something.
2data Foo
2data Foo
3 = Foo
3 = Foo
4− { fooX :: Int -- ^ X
4+ { fooX :: Int, -- ^ X
5− , fooY :: Int -- ^ Y
5+ fooY :: Int, -- ^ Y
6− , fooBar, fooBaz :: NonEmpty (Identity Bool) -- ^ BarBaz
6+ fooBar, fooBaz :: NonEmpty (Identity Bool), -- ^ BarBaz
7− , fooGag
7+ fooGag,
8− , fooGog
8+ fooGog
9 :: NonEmpty
9 :: NonEmpty
10 ( Indentity
10 ( Indentity
11 Bool
11 Bool
12− )
12+ ),
13 -- ^ GagGog
13 -- ^ GagGog
14− , fooFoo
14+ fooFoo,
15− , barBar
15+ barBar
16 :: Int -- ^ Huh!
16 :: Int -- ^ Huh!
17− }
17+ }
18 deriving (Eq, Show)
18 deriving (Eq, Show)
data/examples/declaration/default/default-out.hs+4−4
@@ -1,7 +1,7 @@
1default (Int, Foo, Bar)
1default (Int, Foo, Bar)
2
2
3default
3default
4− ( Int
4+ ( Int,
5− , Foo
5+ Foo,
6− , Bar
6+ Bar
7− )
7+ )
data/examples/declaration/instance/contexts-out.hs+24−21
@@ -3,38 +3,41 @@ instance Eq a => Eq [a] where
3 (==) _ _ = False
3 (==) _ _ = False
4
4
5instance
5instance
6− ( Ord a
6+ ( Ord a,
7− , Ord b
7+ Ord b
8− )
8+ )
9− => Ord (a, b) where
9+ => Ord (a, b)
10+ where
10
11
11 compare _ _ = GT
12 compare _ _ = GT
12
13
13instance
14instance
14 (Show a, Show b)
15 (Show a, Show b)
15 => Show
16 => Show
16− ( a
17+ ( a,
17− , b
18+ b
19+ )
18− ) where
20+ where
19
21
20 showsPrec _ _ = showString ""
22 showsPrec _ _ = showString ""
21
23
22instance
24instance
23− ( Read a -- Foo
25+ ( Read a, -- Foo
24− , Read b
26+ Read b,
25− , Read
27+ Read
26− ( c
28+ ( c,
27− , -- Bar
29+ -- Bar
28− d
30+ d
29− )
31+ )
30− )
32+ )
31 => Read
33 => Read
32− ( a
34+ ( a,
33− , -- Baz
35+ -- Baz
34− b
36+ b,
35− , ( c -- Quux
37+ ( c, -- Quux
36− , d
38+ d
39+ )
37 )
40 )
38− ) where
41+ where
39
42
40 readsPrec = undefined
43 readsPrec = undefined
data/examples/declaration/instance/data-family-instances-out.hs+7−7
@@ -7,17 +7,17 @@ data instance
7 Foo
7 Foo
8 [Int]
8 [Int]
9 = IntListFoo
9 = IntListFoo
10− ( Int
10+ ( Int,
11− , Int
11+ Int
12− )
12+ )
13− ( Double
13+ ( Double,
14− , Double
14+ Double
15− )
15+ )
16
16
17newtype instance Foo [Double]
17newtype instance Foo [Double]
18 = DoubleListFoo
18 = DoubleListFoo
19 { unDoubleListFoo :: Double
19 { unDoubleListFoo :: Double
20− }
20+ }
21
21
22data instance Bar Double a
22data instance Bar Double a
23 = DoubleBar
23 = DoubleBar
data/examples/declaration/instance/overlappable-instances-out.hs+2−1
@@ -13,6 +13,7 @@ instance {-# OVERLAPS #-} Eq Double where
13instance
13instance
14 {-# INCOHERENT #-}
14 {-# INCOHERENT #-}
15 Ord
15 Ord
16− Double where
16+ Double
17+ where
17
18
18 compare _ _ = GT
19 compare _ _ = GT
data/examples/declaration/instance/type-family-instances-out.hs+6−6
@@ -5,9 +5,9 @@ type instance Foo Int = Int
5type instance
5type instance
6 Foo
6 Foo
7 [Int] =
7 [Int] =
8− ( Int
8+ ( Int,
9− , Int
9+ Int
10− )
10+ )
11
11
12type instance Bar Int [Int] Double = (Int, Double)
12type instance Bar Int [Int] Double = (Int, Double)
13
13
@@ -16,6 +16,6 @@ type instance
16 [Int]
16 [Int]
17 [Int]
17 [Int]
18 Double =
18 Double =
19− ( Int
19+ ( Int,
20− , Double
20+ Double
21− )
21+ )
data/examples/declaration/rewrite-rule/type-signature-out.hs+1−1
@@ -10,7 +10,7 @@
10 :: forall b. (a -> b -> b)
10 :: forall b. (a -> b -> b)
11 -> b
11 -> b
12 -> b
12 -> b
13− ).
13+ ).
14 foldr k z (build g) =
14 foldr k z (build g) =
15 g k z
15 g k z
16 #-}
16 #-}
data/examples/declaration/signature/complete/complete-out.hs+3−3
@@ -3,8 +3,8 @@
3{-# COMPLETE A, B #-}
3{-# COMPLETE A, B #-}
4
4
5{-# COMPLETE
5{-# COMPLETE
6− A
6+ A,
7− , B
7+ B,
8− , C
8+ C
9 :: Foo
9 :: Foo
10 #-}
10 #-}
data/examples/declaration/signature/minimal/minimal-out.hs+4−4
@@ -5,10 +5,10 @@ class Foo a where
5 {-# MINIMAL
5 {-# MINIMAL
6 a
6 a
7 | ( b, c, d
7 | ( b, c, d
8− | e
8+ | e,
9− , f
9+ f
10− )
10+ )
11− | g
11+ | g
12 #-}
12 #-}
13
13
14 (==) :: a -> a -> Bool
14 (==) :: a -> a -> Bool
data/examples/declaration/signature/specialize/specialize-instance-out.hs+1−1
@@ -12,7 +12,7 @@ instance (Num r, V.Vector v r, Factored m r) => Num (VT v m r) where
12
12
13 {-# SPECIALIZE instance
13 {-# SPECIALIZE instance
14 ( Factored m Int => Num (VT U.Vector m Int)
14 ( Factored m Int => Num (VT U.Vector m Int)
15− )
15+ )
16 #-}
16 #-}
17
17
18 VT x + VT y = VT $ V.zipWith (+) x y
18 VT x + VT y = VT $ V.zipWith (+) x y
data/examples/declaration/signature/specialize/specialize-out.hs+3−3
@@ -11,14 +11,14 @@ baz :: Num a => a -> a
11baz = id
11baz = id
12{-# SPECIALIZE [~2] baz
12{-# SPECIALIZE [~2] baz
13 :: Int
13 :: Int
14− -> Int
14+ -> Int
15 #-}
15 #-}
16
16
17{-# SPECIALIZE fits13Bits :: Int -> Bool, Integer -> Bool #-}
17{-# SPECIALIZE fits13Bits :: Int -> Bool, Integer -> Bool #-}
18{-# SPECIALIZE fits13Bits
18{-# SPECIALIZE fits13Bits
19 :: Int
19 :: Int
20− -> Bool
20+ -> Bool,
21− , Integer -> Bool
21+ Integer -> Bool
22 #-}
22 #-}
23fits13Bits :: Integral a => a -> Bool
23fits13Bits :: Integral a => a -> Bool
24fits13Bits x = x >= -4096 && x < 4096
24fits13Bits x = x >= -4096 && x < 4096
data/examples/declaration/signature/type/arguments-out.hs+1−1
@@ -10,6 +10,6 @@ functionName
10 -> AnotherLongDataTypeName
10 -> AnotherLongDataTypeName
11 -> b
11 -> b
12 -> c
12 -> c
13− )
13+ )
14 -> (c -> d)
14 -> (c -> d)
15 -> (a, b, c, d)
15 -> (a, b, c, d)
data/examples/declaration/signature/type/context-multi-line-out.hs+4−4
@@ -1,8 +1,8 @@
1functionName
1functionName
2− :: ( C1
2+ :: ( C1,
3− , C2
3+ C2,
4− , C3
4+ C3
5− )
5+ )
6 => a
6 => a
7 -> b
7 -> b
8 -> c
8 -> c
data/examples/declaration/signature/type/long-multiline-applications-out.hs+1−1
@@ -10,6 +10,6 @@ functionName
10 -> AnotherLongDataTypeName4
10 -> AnotherLongDataTypeName4
11 -> b
11 -> b
12 -> c
12 -> c
13− )
13+ )
14 -> (c -> d)
14 -> (c -> d)
15 -> (a, b, c, d)
15 -> (a, b, c, d)
data/examples/declaration/signature/type/multi-value-out.hs+3−3
@@ -1,6 +1,6 @@
1foo, bar :: Int
1foo, bar :: Int
2
2
3−foo
3+foo,
4− , bar
4+ bar,
5− , baz
5+ baz
6 :: Int
6 :: Int
data/examples/declaration/splice/typed-splice-out.hs+1−1
@@ -2,6 +2,6 @@
2
2
3x =
3x =
4 $$( foo bar
4 $$( foo bar
5− )
5+ )
6
6
7x = $$foo
7x = $$foo
data/examples/declaration/splice/untyped-splice-out.hs+1−1
@@ -5,6 +5,6 @@ x = $(foo bar)
5x =
5x =
6 $( foo
6 $( foo
7 bar
7 bar
8− )
8+ )
9
9
10x = $foo
10x = $foo
data/examples/declaration/value/function/arithmetic-sequences-out.hs+6−6
@@ -4,14 +4,14 @@ foo' = [0 .. 5]
4
4
5bar x =
5bar x =
6 [ 0
6 [ 0
7− .. x
7+ .. x
8− ]
8+ ]
9
9
10baz x =
10baz x =
11− [ 1
11+ [ 1,
12− , 3
12+ 3
13− .. x
13+ .. x
14− ]
14+ ]
15
15
16barbaz x = [0, 1 ..]
16barbaz x = [0, 1 ..]
17
17
data/examples/declaration/value/function/arrow/expression-forms-out.hs+3−3
@@ -6,8 +6,8 @@ bar f g x y =
6 (| test
6 (| test
7 ( f -<
7 ( f -<
8 x
8 x
9− )
9+ )
10 ( g -<
10 ( g -<
11 y
11 y
12− )
12+ )
13− |)
13+ |)
data/examples/declaration/value/function/arrow/proc-applications-out.hs+8−8
@@ -4,15 +4,15 @@ foo x = proc a -> a -< x
4
4
5bar f x =
5bar f x =
6 proc
6 proc
7− ( y
7+ ( y,
8− , z
8+ z,
9− , w
9+ w
10− )
10+ )
11 ->
11 ->
12 f -< -- The value
12 f -< -- The value
13− ( x -- Foo
13+ ( x, -- Foo
14− , w -- Bar
14+ w, -- Bar
15− , z -- Baz
15+ z -- Baz
16− )
16+ )
17
17
18baz x = proc a -> a -<< x
18baz x = proc a -> a -<< x
data/examples/declaration/value/function/arrow/proc-cases-out.hs+3−3
@@ -5,9 +5,9 @@ foo f = proc a -> case a of Left b -> f -< b
5bar f g h j =
5bar f g h j =
6 proc a -> case a of
6 proc a -> case a of
7 Left
7 Left
8− ( (a, b)
8+ ( (a, b),
9− , (c, d)
9+ (c, d)
10− ) -> f (a <> c) -< b <> d
10+ ) -> f (a <> c) -< b <> d
11 Right
11 Right
12 (Left a) ->
12 (Left a) ->
13 h -< a
13 h -< a
data/examples/declaration/value/function/arrow/proc-do-complex-out.hs+19−19
@@ -6,37 +6,37 @@ foo
6 h
6 h
7 ma =
7 ma =
8 proc
8 proc
9− ( (a, b)
9+ ( (a, b),
10− , (c, d)
10+ (c, d),
11− , (e, f)
11+ (e, f)
12− )
12+ )
13 -> do
13 -> do
14 -- Begin do
14 -- Begin do
15 (x, y) <- -- GHC parser fails if layed out over multiple lines
15 (x, y) <- -- GHC parser fails if layed out over multiple lines
16 f -- Call into f
16 f -- Call into f
17− ( a
17+ ( a,
18− , c -- Tuple together arguments
18+ c -- Tuple together arguments
19− )
19+ )
20− ( b
20+ ( b,
21− , d
21+ d
22− ) -<
22+ ) -<
23− ( b + 1 -- Funnel into arrow
23+ ( b + 1, -- Funnel into arrow
24− , d * b
24+ d * b
25− )
25+ )
26 if x `mod` y == 0 -- Basic condition
26 if x `mod` y == 0 -- Basic condition
27 then
27 then
28 case e of -- Only left case is relevant
28 case e of -- Only left case is relevant
29 Left
29 Left
30− ( z
30+ ( z,
31− , w
31+ w
32− ) -> \u -> -- Procs can have lambdas
32+ ) -> \u -> -- Procs can have lambdas
33 let v =
33 let v =
34 u ^ -- Actually never used
34 u ^ -- Actually never used
35 2
35 2
36 in ( returnA -<
36 in ( returnA -<
37 -- Just do the calculation
37 -- Just do the calculation
38 (x + y * z)
38 (x + y * z)
39− )
39+ )
40 else
40 else
41 do
41 do
42 let u = x -- Let bindings bind expressions, not commands
42 let u = x -- Let bindings bind expressions, not commands
@@ -47,8 +47,8 @@ foo
47 n ->
47 n ->
48 ( ( h . g -<
48 ( ( h . g -<
49 y -- First actual use of y
49 y -- First actual use of y
50+ )
50 )
51 )
51− )
52 returnA -< ()
52 returnA -< ()
53 -- Sometimes execute effects
53 -- Sometimes execute effects
54 if i > 0
54 if i > 0
@@ -58,4 +58,4 @@ foo
58 ( i +
58 ( i +
59 x *
59 x *
60 y -- Just do the calculation
60 y -- Just do the calculation
61− )
61+ )
data/examples/declaration/value/function/arrow/proc-do-simple-out.hs+4−4
@@ -28,9 +28,9 @@ bazbaz f g h = proc (a, b, c) -> do
28 h
28 h
29 x
29 x
30 y -<
30 y -<
31− ( a
31+ ( a,
32− , b
32+ b,
33− , c
33+ c
34− )
34+ )
35 returnA -<
35 returnA -<
36 (x, y, z)
36 (x, y, z)
data/examples/declaration/value/function/arrow/proc-forms-out.hs+3−3
@@ -13,13 +13,13 @@ foo2 f g h x =
13 h g -<
13 h g -<
14 y x .
14 y x .
15 y z
15 y z
16− )
16+ )
17 ( h g .
17 ( h g .
18 h f -<
18 h f -<
19 y z .
19 y z .
20 y x
20 y x
21− )
21+ )
22− |)
22+ |)
23
23
24bar0 f g x y = proc _ -> f -< x &&& g -< y
24bar0 f g x y = proc _ -> f -< x &&& g -< y
25
25
data/examples/declaration/value/function/arrow/proc-parentheses-out.hs+5−5
@@ -4,15 +4,15 @@ foo f = proc a -> (f -< a)
4
4
5bar f g = proc a ->
5bar f g = proc a ->
6 ( ( (f)
6 ( ( (f)
7− ( g
7+ ( g
8− )
8+ )
9− ) -<
9+ ) -<
10 ( ( ( ( ( ( g
10 ( ( ( ( ( ( g
11− a
11+ a
12+ )
12 )
13 )
13 )
14 )
14 )
15 )
15 )
16 )
16 )
17 )
17 )
18 )
18− )
data/examples/declaration/value/function/arrow/recursive-procs-out.hs+3−3
@@ -6,9 +6,9 @@ foo f g = proc (x, y) -> do
6 g x -<
6 g x -<
7 y
7 y
8 bar -<
8 bar -<
9− ( a
9+ ( a,
10− , b
10+ b
11− )
11+ )
12 rec p <-
12 rec p <-
13 f
13 f
14 p -<
14 p -<
data/examples/declaration/value/function/do-single-multi-out.hsnew file+4
@@ -0,0 +1,4 @@
1+foo = do
2+ ( bar
3+ baz
4+ )
data/examples/declaration/value/function/do-single-multi.hsnew file+2
@@ -0,0 +1,2 @@
1+foo = do (bar
2+ baz)
data/examples/declaration/value/function/implicit-params-out.hs+3−3
@@ -7,9 +7,9 @@ sort = sortBy ?cmp
7
7
8sort'
8sort'
9 :: ( ?cmp
9 :: ( ?cmp
10− :: a -> a -> Bool
10+ :: a -> a -> Bool,
11− , ?foo :: Int
11+ ?foo :: Int
12− )
12+ )
13 => [a]
13 => [a]
14 -> [a]
14 -> [a]
15sort' = sort
15sort' = sort
data/examples/declaration/value/function/list-comprehensions-out.hs+14−14
@@ -5,21 +5,21 @@ bar x y = [(a, b) | a <- x, even a, b <- y, a != b]
5barbaz x y z w =
5barbaz x y z w =
6 [ (a, b, c, d) -- Foo
6 [ (a, b, c, d) -- Foo
7 | a <-
7 | a <-
8− x -- Bar
8+ x, -- Bar
9− , b <- y -- Baz
9+ b <- y, -- Baz
10− , any even [a, b]
10+ any even [a, b],
11− , c <-
11+ c <-
12 z *
12 z *
13 z ^
13 z ^
14− 2 -- Bar baz
14+ 2, -- Bar baz
15− , d <-
15+ d <-
16 w +
16 w +
17− w -- Baz bar
17+ w, -- Baz bar
18− , all
18+ all
19 even
19 even
20− [ a
20+ [ a,
21− , b
21+ b,
22− , c
22+ c,
23− , d
23+ d
24− ]
24+ ]
25− ]
25+ ]
data/examples/declaration/value/function/multiline-arguments-out.hs+1−1
@@ -4,5 +4,5 @@ foo
4 ( Bar
4 ( Bar
5 x
5 x
6 y
6 y
7− )
7+ )
8 z = x
8 z = x
data/examples/declaration/value/function/operator-sections-out.hs+2−2
@@ -5,9 +5,9 @@ bar = (<> "hello")
5baz =
5baz =
6 ( 1 * 2
6 ( 1 * 2
7 +
7 +
8− )
8+ )
9 ( *
9 ( *
10 3 ^ 5
10 3 ^ 5
11− )
11+ )
12
12
13quux = (,) <$> foo <$> bar
13quux = (,) <$> foo <$> bar
data/examples/declaration/value/function/parallel-comprehensions-out.hs+29−29
@@ -3,35 +3,35 @@ foo x y = [(a, b) | a <- x | b <- y]
3bar x y z w = [(a, b, c, d) | a <- x, b <- y, a `mod` b == 0 | c <- z | d <- w]
3bar x y z w = [(a, b, c, d) | a <- x, b <- y, a `mod` b == 0 | c <- z | d <- w]
4
4
5baz x y z w =
5baz x y z w =
6− [ ( a
6+ [ ( a,
7− , b
7+ b,
8− , c
8+ c,
9− , d
9+ d,
10− , e
10+ e,
11− , f
11+ f,
12− , g
12+ g,
13− , h
13+ h,
14− , i
14+ i,
15− , j
15+ j
16− )
16+ )
17 | a <- -- Foo 1
17 | a <- -- Foo 1
18− x -- Foo 2
18+ x, -- Foo 2
19− , b <- -- Bar 1
19+ b <- -- Bar 1
20− y -- Bar 2
20+ y, -- Bar 2
21− , a `mod`
21+ a `mod`
22 b == -- Value
22 b == -- Value
23 0
23 0
24− | c <- -- Baz 1
24+ | c <- -- Baz 1
25− z * -- Baz 2
25+ z * -- Baz 2
26− z -- Baz 3
26+ z -- Baz 3
27− | d <- w -- Other
27+ | d <- w -- Other
28− | e <- x * x -- Foo bar
28+ | e <- x * x -- Foo bar
29− | f <- -- Foo baz 1
29+ | f <- -- Foo baz 1
30− y + y -- Foo baz 2
30+ y + y -- Foo baz 2
31− | h <- z + z * w ^ 2 -- Bar foo
31+ | h <- z + z * w ^ 2 -- Bar foo
32− | i <- -- Bar bar 1
32+ | i <- -- Bar bar 1
33− a + -- Bar bar 2
33+ a + -- Bar bar 2
34− b -- Bar bar 3
34+ b, -- Bar bar 3
35− , j <- -- Bar baz 1
35+ j <- -- Bar baz 1
36− a + b -- Bar baz 2
36+ a + b -- Bar baz 2
37− ]
37+ ]
data/examples/declaration/value/function/pattern/famous-cardano-pattern-out.hsnew file+8
@@ -0,0 +1,8 @@
1+( getNodeSettingsR :<|>
2+ getNodeInfoR :<|>
3+ getNextUpdateR :<|>
4+ restartNodeR
5+ ) :<|>
6+ ( getUtxoR :<|>
7+ getConfirmedProposalsR
8+ ) = client nodeV1Api
data/examples/declaration/value/function/pattern/famous-cardano-pattern.hsnew file+7
@@ -0,0 +1,7 @@
1+( getNodeSettingsR
2+ :<|> getNodeInfoR
3+ :<|> getNextUpdateR
4+ :<|> restartNodeR
5+ ):<|>( getUtxoR
6+ :<|> getConfirmedProposalsR
7+ ) = client nodeV1Api
data/examples/declaration/value/function/pattern/multiline-case-pattern-out.hsnew file+15
@@ -0,0 +1,15 @@
1+readerBench doc name =
2+ runPure $ case (getReader name, getWriter name) of
3+ ( Right (TextReader r, rexts),
4+ Right (TextWriter w, wexts)
5+ ) -> undefined
6+
7+f xs = case xs of
8+ [ a,
9+ b
10+ ] -> a + b
11+
12+g xs = case xs of
13+ ( a :
14+ bs
15+ ) -> a + b
data/examples/declaration/value/function/pattern/multiline-case-pattern.hsnew file+12
@@ -0,0 +1,12 @@
1+readerBench doc name =
2+ runPure $ case (getReader name, getWriter name) of
3+ (Right (TextReader r, rexts),
4+ Right (TextWriter w, wexts)) -> undefined
5+
6+f xs = case xs of
7+ [ a,
8+ b ] -> a + b
9+
10+g xs = case xs of
11+ (a:
12+ bs) -> a + b
data/examples/declaration/value/function/pattern/n-plus-k-pattern-out.hs+1−1
@@ -7,4 +7,4 @@ multiline :: Int
7multiline
7multiline
8 ( n
8 ( n
9 + 1
9 + 1
10− ) = n
10+ ) = n
data/examples/declaration/value/function/pattern/record-patterns-out.hs+4−4
@@ -13,7 +13,7 @@ baz Boom {boom = b, ..} = b
13quux :: Boom -> Int
13quux :: Boom -> Int
14quux
14quux
15 Boom
15 Boom
16− { boom = a
16+ { boom = a,
17− , foom = b
17+ foom = b,
18− , ..
18+ ..
19− } = a + b
19+ } = a + b
data/examples/declaration/value/function/pattern/splice-pattern-out.hs+2−2
@@ -7,7 +7,7 @@ singleLine = case () of
7multiline = case () of
7multiline = case () of
8 $( x +
8 $( x +
9 y
9 y
10− ) -> ()
10+ ) -> ()
11 $( y
11 $( y
12 "something"
12 "something"
13− ) -> ()
13+ ) -> ()
data/examples/declaration/value/function/pattern/view-pattern-out.hs+1−1
@@ -12,4 +12,4 @@ multiline
12 Foo
12 Foo
13 bar
13 bar
14 baz
14 baz
15− ) = True
15+ ) = True
data/examples/declaration/value/function/record-constructors-out.hs+3−3
@@ -1,8 +1,8 @@
1foo = Foo {a = 3}
1foo = Foo {a = 3}
2
2
3bar = Bar
3bar = Bar
4− { abc = foo
4+ { abc = foo,
5− , def = Foo {a = 10}
5+ def = Foo {a = 10}
6− }
6+ }
7
7
8baz = Baz {}
8baz = Baz {}
data/examples/declaration/value/function/record-updaters-out.hs+3−3
@@ -2,8 +2,8 @@ foo x = x {a = 3}
2
2
3bar x =
3bar x =
4 x
4 x
5− { abc = foo
5+ { abc = foo,
6− , def = Foo {a = 10}
6+ def = Foo {a = 10}
7− }
7+ }
8
8
9baz x = x {}
9baz x = x {}
data/examples/declaration/value/function/record-wildcards-out.hs+5−5
@@ -4,10 +4,10 @@
4foo x y = Foo {x, y}
4foo x y = Foo {x, y}
5
5
6bar x y z = Bar
6bar x y z = Bar
7− { x
7+ { x,
8− , y
8+ y,
9− , z
9+ z,
10− , ..
10+ ..
11− }
11+ }
12
12
13baz = Baz {..}
13baz = Baz {..}
data/examples/declaration/value/function/static-pointers-out.hs+6−6
@@ -6,14 +6,14 @@ foo = static 5
6bar :: StaticPtr [Int]
6bar :: StaticPtr [Int]
7bar =
7bar =
8 static
8 static
9− [ 1
9+ [ 1,
10− , 2
10+ 2,
11− , 3
11+ 3
12− ]
12+ ]
13
13
14baz :: StaticPtr Bool
14baz :: StaticPtr Bool
15baz =
15baz =
16 static
16 static
17 ( fun 1
17 ( fun 1
18− 2
18+ 2
19− )
19+ )
data/examples/declaration/value/function/transform-comprehensions-out.hs+30−30
@@ -3,56 +3,56 @@
3foo xs ys = [(x, y) | x <- xs, y <- ys, then reverse]
3foo xs ys = [(x, y) | x <- xs, y <- ys, then reverse]
4
4
5foo' xs ys =
5foo' xs ys =
6− [ ( x
6+ [ ( x,
7− , y
7+ y
8− )
8+ )
9− | x <- xs
9+ | x <- xs,
10− , y <- ys
10+ y <- ys,
11− , -- First comment
11+ -- First comment
12 then reverse -- Second comment
12 then reverse -- Second comment
13− ]
13+ ]
14
14
15bar xs ys = [(x, y) | x <- xs, y <- ys, then sortWith by (x + y)]
15bar xs ys = [(x, y) | x <- xs, y <- ys, then sortWith by (x + y)]
16
16
17bar' xs ys =
17bar' xs ys =
18− [ ( x
18+ [ ( x,
19− , y
19+ y
20− )
20+ )
21− | x <- xs
21+ | x <- xs,
22− , y <- ys
22+ y <- ys,
23− , -- First comment
23+ -- First comment
24 then sortWith
24 then sortWith
25 by
25 by
26 ( x +
26 ( x +
27 y -- Second comment
27 y -- Second comment
28− )
28+ )
29− ]
29+ ]
30
30
31baz xs ys = [(x, y) | x <- xs, y <- ys, then group using permutations]
31baz xs ys = [(x, y) | x <- xs, y <- ys, then group using permutations]
32
32
33baz' xs ys =
33baz' xs ys =
34− [ ( x
34+ [ ( x,
35− , y
35+ y
36− )
36+ )
37− | x <- xs
37+ | x <- xs,
38− , y <- ys
38+ y <- ys,
39− , -- First comment
39+ -- First comment
40 then group using permutations -- Second comment
40 then group using permutations -- Second comment
41− ]
41+ ]
42
42
43quux xs ys = [(x, y) | x <- xs, y <- ys, then group by (x + y) using groupWith]
43quux xs ys = [(x, y) | x <- xs, y <- ys, then group by (x + y) using groupWith]
44
44
45quux' xs ys =
45quux' xs ys =
46− [ ( x
46+ [ ( x,
47− , y
47+ y
48− )
48+ )
49− | x <- xs
49+ | x <- xs,
50− , y <- ys
50+ y <- ys,
51− , -- First comment
51+ -- First comment
52 then group by
52 then group by
53 ( x +
53 ( x +
54 y
54 y
55− )
55+ )
56 -- Second comment
56 -- Second comment
57 using groupWith -- Third comment
57 using groupWith -- Third comment
58− ]
58+ ]
data/examples/declaration/value/function/tuple-sections-out.hs+1−2
@@ -5,5 +5,4 @@ foo = (,2)
5bar = (,5,)
5bar = (,5,)
6
6
7baz =
7baz =
8− ( ,,5,6,7,,,
8+ (,,5,6,7,,,)
9− )
data/examples/declaration/value/function/tuples-out.hs+4−4
@@ -1,7 +1,7 @@
1foo = (1, 2, 3)
1foo = (1, 2, 3)
2
2
3bar =
3bar =
4− ( 1
4+ ( 1,
5− , 2
5+ 2,
6− , 3
6+ 3
7− )
7+ )
data/examples/declaration/value/function/unboxed-sums-out.hs+1−1
@@ -6,4 +6,4 @@ bar = (# | | 2 | #)
6
6
7baz =
7baz =
8 (# | | | 10 | | | | |
8 (# | | | 10 | | | | |
9− #)
9+ #)
data/examples/declaration/value/function/unboxed-tuples-out.hs+4−4
@@ -3,7 +3,7 @@
3foo = (# 1, 2, 3 #)
3foo = (# 1, 2, 3 #)
4
4
5bar =
5bar =
6− (# 1
6+ (# 1,
7− , 2
7+ 2,
8− , 3
8+ 3
9− #)
9+ #)
data/examples/declaration/value/other/line-multi-line-out.hs+4−4
@@ -1,6 +1,6 @@
1x :: [Int]
1x :: [Int]
2x =
2x =
3− [ 1
3+ [ 1,
4− , 2
4+ 2,
5− , somethingSomething 3
5+ somethingSomething 3
6− ]
6+ ]
data/examples/declaration/warning/warning-multiline-out.hs+5−5
@@ -1,9 +1,9 @@
1{-# WARNING
1{-# WARNING
2− test
2+ test,
3− , foo
3+ foo
4− [ "These are bad functions"
4+ [ "These are bad functions",
5− , "Really bad!"
5+ "Really bad!"
6− ]
6+ ]
7 #-}
7 #-}
8test :: IO ()
8test :: IO ()
9test = pure ()
9test = pure ()
data/examples/import/explicit-imports-out.hs+11−11
@@ -1,12 +1,12 @@
1import qualified MegaModule as M
1import qualified MegaModule as M
2− ( (<<<)
2+ ( (<<<),
3− , (>>>)
3+ (>>>),
4− , Either
4+ Either,
5− , Maybe (Just, Nothing)
5+ Maybe (Just, Nothing),
6− , MaybeT (..)
6+ MaybeT (..),
7− , Monad ((>>), (>>=), return)
7+ Monad ((>>), (>>=), return),
8− , MonadBaseControl
8+ MonadBaseControl,
9− , join
9+ join,
10− , liftIO
10+ liftIO,
11− , void
11+ void
12− )
12+ )
data/examples/import/explicit-imports-with-comments-out.hs+4−4
@@ -1,6 +1,6 @@
1import qualified MegaModule as M
1import qualified MegaModule as M
2 ( -- (1)
2 ( -- (1)
3− (<<<) -- (2)
3+ (<<<), -- (2)
4− , (>>>)
4+ (>>>),
5− , Either -- (3)
5+ Either -- (3)
6− )
6+ )
data/examples/import/misc-out.hs+8−8
@@ -1,11 +1,11 @@
1import A hiding
1import A hiding
2− ( foobarbazqux
2+ ( foobarbazqux,
3+ foobarbazqux,
3− , foobarbazqux
4+ foobarbazqux,
5+ foobarbazqux,
4− , foobarbazqux
6+ foobarbazqux,
5− , foobarbazqux
6− , foobarbazqux
7+ foobarbazqux,
7− , foobarbazqux
8− , foobarbazqux
8+ foobarbazqux
9− )
9+ )
10import {-# SOURCE #-} safe qualified Module as M hiding (a, b, c, d, e, f)
10import {-# SOURCE #-} safe qualified Module as M hiding (a, b, c, d, e, f)
11import Name hiding ()
11import Name hiding ()
data/examples/import/nested-explicit-imports-out.hs+9−9
@@ -1,10 +1,10 @@
1import qualified MegaModule as M
1import qualified MegaModule as M
2− ( (<<<)
2+ ( (<<<),
3− , (>>>)
3+ (>>>),
4− , Either
4+ Either,
5− , Monad
5+ Monad
6− ( (>>)
6+ ( (>>),
7− , (>>=)
7+ (>>=),
8− , return
8+ return
9− )
9+ )
10− )
10+ )
data/examples/module-header/double-dot-with-names-out.hs+4−4
@@ -1,10 +1,10 @@
1{-# LANGUAGE PatternSynonyms #-}
1{-# LANGUAGE PatternSynonyms #-}
2
2
3module ExportSyntax
3module ExportSyntax
4− ( A (.., NoA)
4+ ( A (.., NoA),
5− , Q (F, ..)
5+ Q (F, ..),
6− , G (T, .., U)
6+ G (T, .., U)
7− )
7+ )
8where
8where
9
9
10data A = A | B
10data A = A | B
data/examples/module-header/multiline-out.hs+4−4
@@ -1,6 +1,6 @@
1module Foo
1module Foo
2− ( foo
2+ ( foo,
3− , bar
3+ bar,
4− , baz
4+ baz
5− )
5+ )
6where
6where
data/examples/module-header/multiline-with-comments-out.hs+11−11
@@ -4,18 +4,18 @@
4-- | Header.
4-- | Header.
5module My.Module
5module My.Module
6 ( -- * Something
6 ( -- * Something
7− foo
7+ foo,
8− , bar
8+ bar,
9− , -- * Another thing
9+ -- * Another thing
10− (<?>)
10+ (<?>),
11− , {- some other thing -} foo2 -- yet another
11+ {- some other thing -} foo2, -- yet another
12− , foo3 -- third one
12+ foo3, -- third one
13− , baz
13+ baz,
14− , bar2 -- a multiline comment
14+ bar2, -- a multiline comment
15 -- the second line
15 -- the second line
16− , bar3
16+ bar3,
17− , module Foo.Bar.Baz
17+ module Foo.Bar.Baz
18− )
18+ )
19where
19where
20
20
21-- Wow
21-- Wow
data/examples/module-header/multiline2-out.hs+4−4
@@ -1,6 +1,6 @@
1module Foo
1module Foo
2− ( foo
2+ ( foo,
3− , bar
3+ bar,
4− , baz
4+ baz
5− )
5+ )
6where
6where
data/examples/module-header/warning-pragma-list-multiline-out.hs+7−7
@@ -1,11 +1,11 @@
1module Test
1module Test
2 {-# DEPRECATED
2 {-# DEPRECATED
3− [ "This module is deprecated."
3+ [ "This module is deprecated.",
4− , "Please use OtherModule instead."
4+ "Please use OtherModule instead."
5− ]
5+ ]
6 #-}
6 #-}
7− ( foo
7+ ( foo,
8− , bar
8+ bar,
9− , baz
9+ baz
10− )
10+ )
11where
11where
data/examples/module-header/warning-pragma-multiline-out.hs+4−4
@@ -1,8 +1,8 @@
1module Test {-# DEPRECATED "This module is unstable" #-}
1module Test {-# DEPRECATED "This module is unstable" #-}
2− ( foo
2+ ( foo,
3− , bar
3+ bar,
4− , baz
4+ baz
5− )
5+ )
6where
6where
7
7
8import Blah
8import Blah
data/printer/list0-multi.hs+4−4
@@ -1,4 +1,4 @@
1−[ foo
1+[ foo,
2−, bar
2+ bar,
3−, baz
3+ baz
4−]
4+ ]
data/printer/list1-multi.hs+5−5
@@ -1,8 +1,8 @@
1−[ foo
1+[ foo,
2−, bar
2+ bar,
3−, foo
3+ foo
4 :: ( Int
4 :: ( Int
5 -> Int
5 -> Int
6− )
6+ )
7 -> Bool
7 -> Bool
8−]
8+ ]
data/printer/mhdr-multi.hs+5−5
@@ -1,7 +1,7 @@
1module MyModule
1module MyModule
2− ( R
2+ ( R,
3− , runR
3+ runR,
4− , txt
4+ txt,
5− , blah
5+ blah
6− )
6+ )
7where
7where
data/printer/ssig-multi.hs+1−1
@@ -1,5 +1,5 @@
1foo
1foo
2 :: ( Int
2 :: ( Int
3 -> Int
3 -> Int
4− )
4+ )
5 -> Bool
5 -> Bool
src/Ormolu/Printer/Combinators.hs+33−79
@@ -17,18 +17,13 @@ module Ormolu.Printer.Combinators
17 , newline
17 , newline
18 , inci
18 , inci
19 , located
19 , located
20− , locatedVia
21 , located'
20 , located'
22 , switchLayout
21 , switchLayout
23 , vlayout
22 , vlayout
24 , breakpoint
23 , breakpoint
25 , breakpoint'
24 , breakpoint'
26 -- ** Formatting lists
25 -- ** Formatting lists
27− , velt
26+ , sep
28− , velt'
29− , withSep
30− , spaceSep
31− , newlineSep
32 -- ** Wrapping
27 -- ** Wrapping
33 , sitcc
28 , sitcc
34 , line
29 , line
@@ -85,18 +80,7 @@ located
85 => Located a -- ^ Thing to enter
80 => Located a -- ^ Thing to enter
86 -> (a -> R ()) -- ^ How to render inner value
81 -> (a -> R ()) -- ^ How to render inner value
87 -> R ()
82 -> R ()
88−located loc@(L l _) = locatedVia (Just l) loc
83+located loc f = do
89−
90−-- | A special version of 'located' that allows to control layout using an
91−-- externally provided span. 'Nothing' means that layout won't be changed.
92−
93−locatedVia
94− :: Data a
95− => Maybe SrcSpan -- ^ Span that controls layout selection
96− -> Located a -- ^ Thing to enter
97− -> (a -> R ()) -- ^ How to render inner value
98− -> R ()
99−locatedVia ml loc f = do
100 let withRealLocated (L l a) g =
84 let withRealLocated (L l a) g =
101 case l of
85 case l of
102 UnhelpfulSpan _ -> return ()
86 UnhelpfulSpan _ -> return ()
@@ -109,9 +93,7 @@ locatedVia ml loc f = do
109 if isModule (unLoc loc)
93 if isModule (unLoc loc)
110 then id
94 then id
111 else withEnclosingSpan orf
95 else withEnclosingSpan orf
112− setEnclosingSpan $ case ml of
113− Nothing -> f (unLoc loc)
114− Just l' -> switchLayout l' (f (unLoc loc))
96+ setEnclosingSpan $ switchLayout [getLoc loc] (f (unLoc loc))
115 withRealLocated loc spitFollowingComments
97 withRealLocated loc spitFollowingComments
116
98
117-- | A version of 'located' with arguments flipped.
99-- | A version of 'located' with arguments flipped.
@@ -123,19 +105,28 @@ located'
123 -> R ()
105 -> R ()
124located' = flip located
106located' = flip located
125
107
126−-- | Set layout according to given 'SrcSpan' for a given computation. Use
108+-- | Set layout according to combination of given 'SrcSpan's for a given.
127−-- this only when you need to set layout based on e.g. combined span of
109+-- Use this only when you need to set layout based on e.g. combined span of
128-- several elements when there is no corresponding 'Located' wrapper
110-- several elements when there is no corresponding 'Located' wrapper
129-- provided by GHC AST. It is relatively rare that this one is needed.
111-- provided by GHC AST. It is relatively rare that this one is needed.
112+--
113+-- Given empty list this function will set layout to single line.
130
114
131switchLayout
115switchLayout
132− :: SrcSpan -- ^ Span that controls layout
116+ :: [SrcSpan] -- ^ Span that controls layout
133 -> R () -- ^ Computation to run with changed layout
117 -> R () -- ^ Computation to run with changed layout
134 -> R ()
118 -> R ()
135−switchLayout spn = enterLayout
119+switchLayout spans' = enterLayout (spansLayout spans')
120+
121+-- | Which layout combined spans result in?
122+
123+spansLayout :: [SrcSpan] -> Layout
124+spansLayout = \case
125+ [] -> SingleLine
126+ (x:xs) ->
136− (if isOneLineSpan spn
127+ if isOneLineSpan (foldr combineSrcSpans x xs)
137− then SingleLine
128+ then SingleLine
138− else MultiLine)
129+ else MultiLine
139
130
140-- | Insert a space if enclosing layout is single-line, or newline if it's
131-- | Insert a space if enclosing layout is single-line, or newline if it's
141-- multiline.
132-- multiline.
@@ -156,56 +147,14 @@ breakpoint' = vlayout (return ()) newline
156----------------------------------------------------------------------------
147----------------------------------------------------------------------------
157-- Formatting lists
148-- Formatting lists
158
149
159−-- | Element of variable layout. This means that the sub-components may be
150+-- | Render a collection of elements inserting a separator between them.
160−-- rendered either on single line or each on its own line depending on
161−-- current layout.
162−--
163−-- This version does not make subsequent element (second and later) align
164−-- with the first automatically and does not insert spaces between elements
165−-- when layout is single line.
166−
167−velt :: [R ()] -> R ()
168−velt xs = sequence_ (intersperse breakpoint' (sitcc <$> xs))
169−
170−-- | Like 'velt', but all sub-elements start at the same indentation level
171−-- as first element, additionally spaces are inserted when layout is single
172−-- line.
173−
174−velt' :: [R ()] -> R ()
175−velt' xs = sitcc $ sequence_ (intersperse breakpoint (sitcc <$> xs))
176
151
177−-- | Put separator between renderings of items of a list.
152+sep
178−
179−withSep
180 :: R () -- ^ Separator
153 :: R () -- ^ Separator
181− -> (a -> R ()) -- ^ How to render list items
154+ -> (a -> R ()) -- ^ How to render an element
182− -> [a] -- ^ List to render
183− -> [R ()] -- ^ List of printing actions
184−withSep sep f = \case
185− [] -> []
186− (x:xs) ->
187− let g a = sep >> f a
188− in f x : fmap g xs
189−
190−-- | Render space-separated elements.
191−--
192−-- > spaceSep f = sequence_ . withSep space f
193−
194−spaceSep
195− :: (a -> R ()) -- ^ How to render list items
196− -> [a] -- ^ List to render
155+ -> [a] -- ^ Elements to render
197 -> R ()
156 -> R ()
198−spaceSep f = sequence_ . withSep space f
157+sep s f xs = sequence_ (intersperse s (f <$> xs))
199−
200−-- | Render newline-separated elements.
201−--
202−-- > newlineSep f = sequence_ . withSep newline f
203−
204−newlineSep
205− :: (a -> R ()) -- ^ How to render list items
206− -> [a] -- ^ List to render
207− -> R ()
208−newlineSep f = sequence_ . withSep newline f
209
158
210----------------------------------------------------------------------------
159----------------------------------------------------------------------------
211-- Wrapping
160-- Wrapping
@@ -259,6 +208,7 @@ bracketsPar :: R () -> R ()
259bracketsPar m = sitcc $ do
208bracketsPar m = sitcc $ do
260 txt "[: "
209 txt "[: "
261 m
210 m
211+ vlayout (return ()) space
262 txt " :]"
212 txt " :]"
263
213
264-- | Surround given entity by parentheses @(@ and @)@.
214-- | Surround given entity by parentheses @(@ and @)@.
@@ -275,7 +225,7 @@ parensHash :: R () -> R ()
275parensHash m = sitcc $ do
225parensHash m = sitcc $ do
276 txt "(# "
226 txt "(# "
277 m
227 m
278− breakpoint
228+ vlayout space (newline >> txt " ")
279 txt "#)"
229 txt "#)"
280
230
281-- | Braces as used for pragmas: @{-#@ and @#-}@.
231-- | Braces as used for pragmas: @{-#@ and @#-}@.
@@ -302,15 +252,19 @@ pragma pragmaText body = pragmaBraces $ do
302-- current layout is multiline.
252-- current layout is multiline.
303
253
304ospaces :: R () -> R ()
254ospaces :: R () -> R ()
305−ospaces m = vlayout m (txt " " >> m >> newline)
255+ospaces m = vlayout m $ do
256+ space
257+ m
258+ newline
259+ txt " "
306
260
307----------------------------------------------------------------------------
261----------------------------------------------------------------------------
308-- Literals
262-- Literals
309
263
310−-- | Print @,@ followed by a space.
264+-- | Print @,@.
311
265
312comma :: R ()
266comma :: R ()
313−comma = txt ", "
267+comma = txt ","
314
268
315-- | Print single space.
269-- | Print single space.
316
270
src/Ormolu/Printer/Meat/Common.hs+2−2
@@ -130,9 +130,9 @@ p_infixDefHelper isInfix inci' name args =
130 inci' p1
130 inci' p1
131 unless (null ps) . inci' $ do
131 unless (null ps) . inci' $ do
132 breakpoint
132 breakpoint
133− velt' ps
133+ sitcc (sep breakpoint sitcc ps)
134 (_, ps) -> do
134 (_, ps) -> do
135 name
135 name
136 unless (null ps) $ do
136 unless (null ps) $ do
137 breakpoint
137 breakpoint
138− inci' (velt' args)
138+ inci' $ sitcc (sep breakpoint sitcc args)
src/Ormolu/Printer/Meat/Declaration/Class.hs+7−11
@@ -21,7 +21,6 @@ import Ormolu.Printer.Meat.Common
21import Ormolu.Printer.Meat.Type
21import Ormolu.Printer.Meat.Type
22import Ormolu.Utils
22import Ormolu.Utils
23import RdrName (RdrName (..))
23import RdrName (RdrName (..))
24−import SrcLoc (Located, combineSrcSpans)
25import {-# SOURCE #-} Ormolu.Printer.Meat.Declaration
24import {-# SOURCE #-} Ormolu.Printer.Meat.Declaration
26
25
27p_classDecl
26p_classDecl
@@ -37,13 +36,10 @@ p_classDecl
37 -> R ()
36 -> R ()
38p_classDecl ctx name tvars fixity fdeps csigs cdefs cats catdefs = do
37p_classDecl ctx name tvars fixity fdeps csigs cdefs cats catdefs = do
39 let HsQTvs {..} = tvars
38 let HsQTvs {..} = tvars
40− variableSpans = foldr (combineSrcSpans . getLoc) noSrcSpan hsq_explicit
39+ variableSpans = getLoc <$> hsq_explicit
41− signatureSpans = getLoc name `combineSrcSpans` variableSpans
40+ signatureSpans = getLoc name : variableSpans
42− dependencySpans = foldr (combineSrcSpans . getLoc) noSrcSpan fdeps
41+ dependencySpans = getLoc <$> fdeps
43− combinedSpans =
44− getLoc ctx `combineSrcSpans`
45− signatureSpans `combineSrcSpans`
46− dependencySpans
42+ combinedSpans = getLoc ctx : (signatureSpans ++ dependencySpans)
47 txt "class"
43 txt "class"
48 switchLayout combinedSpans $ do
44 switchLayout combinedSpans $ do
49 breakpoint
45 breakpoint
@@ -86,13 +82,13 @@ p_classFundeps :: [Located (FunDep (Located RdrName))] -> R ()
86p_classFundeps fdeps = unless (null fdeps) $ do
82p_classFundeps fdeps = unless (null fdeps) $ do
87 breakpoint
83 breakpoint
88 txt "| "
84 txt "| "
89− velt $ withSep comma (located' p_funDep) fdeps
85+ sitcc $ sep (comma >> breakpoint) (sitcc . located' p_funDep) fdeps
90
86
91p_funDep :: FunDep (Located RdrName) -> R ()
87p_funDep :: FunDep (Located RdrName) -> R ()
92p_funDep (before, after) = do
88p_funDep (before, after) = do
93− spaceSep p_rdrName before
89+ sep space p_rdrName before
94 txt " -> "
90 txt " -> "
95− spaceSep p_rdrName after
91+ sep space p_rdrName after
96
92
97----------------------------------------------------------------------------
93----------------------------------------------------------------------------
98-- Helpers
94-- Helpers
src/Ormolu/Printer/Meat/Declaration/Data.hs+18−18
@@ -10,7 +10,6 @@ module Ormolu.Printer.Meat.Declaration.Data
10where
10where
11
11
12import Control.Monad
12import Control.Monad
13−import Data.List.NonEmpty (NonEmpty (..))
14import Data.Maybe (isJust)
13import Data.Maybe (isJust)
15import GHC
14import GHC
16import Ormolu.Printer.Combinators
15import Ormolu.Printer.Combinators
@@ -28,14 +27,13 @@ p_dataDecl
28 -> HsDataDefn GhcPs -- ^ Data definition
27 -> HsDataDefn GhcPs -- ^ Data definition
29 -> R ()
28 -> R ()
30p_dataDecl style name tpats fixity HsDataDefn {..} = do
29p_dataDecl style name tpats fixity HsDataDefn {..} = do
31− let combinedSpans = combineSrcSpans' (getLoc name :| (getLoc <$> tpats))
32 txt $ case dd_ND of
30 txt $ case dd_ND of
33 NewType -> "newtype"
31 NewType -> "newtype"
34 DataType -> "data"
32 DataType -> "data"
35 txt $ case style of
33 txt $ case style of
36 Associated -> mempty
34 Associated -> mempty
37 Free -> " instance"
35 Free -> " instance"
38− switchLayout combinedSpans $ do
36+ switchLayout (getLoc name : fmap getLoc tpats) $ do
39 breakpoint
37 breakpoint
40 inci $ p_infixDefHelper
38 inci $ p_infixDefHelper
41 (isInfix fixity)
39 (isInfix fixity)
@@ -54,13 +52,13 @@ p_dataDecl style name tpats fixity HsDataDefn {..} = do
54 then do
52 then do
55 txt " where"
53 txt " where"
56 newline
54 newline
57− inci $ newlineSep (sitcc . located' p_conDecl) dd_cons
55+ inci . sitcc $ sep newline (sitcc . located' p_conDecl) dd_cons
58− else switchLayout (combineSrcSpans' (getLoc name :| (getLoc <$> dd_cons))) $
56+ else switchLayout (getLoc name : (getLoc <$> dd_cons)) $
59 inci $ do
57 inci $ do
60 breakpoint
58 breakpoint
61 txt "= "
59 txt "= "
62− let sep = vlayout (txt " | ") (txt "| ")
60+ let s = vlayout (txt " | ") (newline >> txt "| ")
63− velt $ withSep sep (sitcc . located' p_conDecl) dd_cons
61+ sep s (sitcc . located' p_conDecl) dd_cons
64 newline
62 newline
65 inci . located dd_derivs $ \xs ->
63 inci . located dd_derivs $ \xs ->
66 forM_ xs (line . located' p_hsDerivingClause)
64 forM_ xs (line . located' p_hsDerivingClause)
@@ -73,11 +71,10 @@ p_conDecl = \case
73 [] -> return ()
71 [] -> return ()
74 (c:cs) -> do
72 (c:cs) -> do
75 p_rdrName c
73 p_rdrName c
76− unless (null cs) $ do
74+ unless (null cs) . inci $ do
77− breakpoint'
78− inci $ do
79− comma
75+ comma
76+ breakpoint
80− velt $ withSep comma p_rdrName cs
77+ sitcc $ sep (comma >> breakpoint) p_rdrName cs
81 breakpoint
78 breakpoint
82 inci $ do
79 inci $ do
83 txt ":: "
80 txt ":: "
@@ -85,7 +82,7 @@ p_conDecl = \case
85 forM_ con_mb_cxt p_lhsContext
82 forM_ con_mb_cxt p_lhsContext
86 case con_args of
83 case con_args of
87 PrefixCon xs -> do
84 PrefixCon xs -> do
88− velt' (located' p_hsType <$> xs)
85+ sep breakpoint (located' p_hsType) xs
89 unless (null xs) $ do
86 unless (null xs) $ do
90 breakpoint
87 breakpoint
91 txt "-> "
88 txt "-> "
@@ -95,7 +92,7 @@ p_conDecl = \case
95 breakpoint
92 breakpoint
96 txt "-> "
93 txt "-> "
97 InfixCon _ _ -> notImplemented "InfixCon"
94 InfixCon _ _ -> notImplemented "InfixCon"
98− locatedVia Nothing con_res_ty p_hsType
95+ p_hsType (unLoc con_res_ty)
99 ConDeclH98 {..} -> do
96 ConDeclH98 {..} -> do
100 p_forallBndrs con_ex_tvs
97 p_forallBndrs con_ex_tvs
101 forM_ con_mb_cxt p_lhsContext
98 forM_ con_mb_cxt p_lhsContext
@@ -103,7 +100,7 @@ p_conDecl = \case
103 PrefixCon xs -> do
100 PrefixCon xs -> do
104 p_rdrName con_name
101 p_rdrName con_name
105 unless (null xs) breakpoint
102 unless (null xs) breakpoint
106− inci $ velt' (located' p_hsType <$> xs)
103+ inci . sitcc $ sep breakpoint (sitcc . located' p_hsType) xs
107 RecCon l -> do
104 RecCon l -> do
108 p_rdrName con_name
105 p_rdrName con_name
109 breakpoint
106 breakpoint
@@ -124,7 +121,7 @@ p_forallBndrs = \case
124 [] -> return ()
121 [] -> return ()
125 bndrs -> do
122 bndrs -> do
126 txt "forall "
123 txt "forall "
127− spaceSep (located' p_hsTyVarBndr) bndrs
124+ sep space (located' p_hsTyVarBndr) bndrs
128 txt ". "
125 txt ". "
129
126
130p_lhsContext
127p_lhsContext
@@ -150,12 +147,15 @@ p_hsDerivingClause HsDerivingClause {..} = do
150 txt "deriving"
147 txt "deriving"
151 let derivingWhat = located deriv_clause_tys $ \case
148 let derivingWhat = located deriv_clause_tys $ \case
152 [] -> txt "()"
149 [] -> txt "()"
150+ xs -> parens . sitcc $ sep
151+ (comma >> breakpoint)
153− xs -> parens . velt $ withSep comma (located' p_hsType . hsib_body) xs
152+ (sitcc . located' p_hsType . hsib_body)
153+ xs
154 case deriv_clause_strategy of
154 case deriv_clause_strategy of
155 Nothing -> do
155 Nothing -> do
156 breakpoint
156 breakpoint
157 inci derivingWhat
157 inci derivingWhat
158− Just l -> locatedVia Nothing l $ \case
158+ Just (L _ a) -> case a of
159 StockStrategy -> do
159 StockStrategy -> do
160 txt " stock"
160 txt " stock"
161 breakpoint
161 breakpoint
src/Ormolu/Printer/Meat/Declaration/Default.hs+2−2
@@ -16,6 +16,6 @@ p_defaultDecl = \case
16 DefaultDecl NoExt ts -> line $ do
16 DefaultDecl NoExt ts -> line $ do
17 txt "default"
17 txt "default"
18 breakpoint
18 breakpoint
19− inci . parens . velt $
19+ inci . parens . sitcc $
20− withSep comma (located' p_hsType) ts
20+ sep (comma >> breakpoint) (sitcc . located' p_hsType) ts
21 XDefaultDecl {} -> notImplemented "XDefaultDecl"
21 XDefaultDecl {} -> notImplemented "XDefaultDecl"
src/Ormolu/Printer/Meat/Declaration/Foreign.hs+1−1
@@ -35,7 +35,7 @@ p_foreignTypeSig fd = do
35 breakpoint
35 breakpoint
36 -- Switch into the layout of the signature, to allow us to pull name and
36 -- Switch into the layout of the signature, to allow us to pull name and
37 -- signature onto a single line.
37 -- signature onto a single line.
38− inci . switchLayout (getLoc . hsib_body $ fd_sig_ty fd) $ do
38+ inci . switchLayout [getLoc . hsib_body $ fd_sig_ty fd] $ do
39 p_rdrName (fd_name fd)
39 p_rdrName (fd_name fd)
40 p_typeAscription (HsWC NoExt (fd_sig_ty fd))
40 p_typeAscription (HsWC NoExt (fd_sig_ty fd))
41
41
src/Ormolu/Printer/Meat/Declaration/Instance.hs+25−23
@@ -41,7 +41,7 @@ p_standaloneDerivDecl DerivDecl {..} = do
41 Nothing -> do
41 Nothing -> do
42 space
42 space
43 instTypes False
43 instTypes False
44− Just l -> locatedVia Nothing l $ \case
44+ Just (L _ a) -> case a of
45 StockStrategy -> do
45 StockStrategy -> do
46 txt " stock "
46 txt " stock "
47 instTypes False
47 instTypes False
@@ -72,29 +72,31 @@ p_clsInstDecl = \case
72 inci $ do
72 inci $ do
73 match_overlap_mode cid_overlap_mode breakpoint
73 match_overlap_mode cid_overlap_mode breakpoint
74 p_hsType x
74 p_hsType x
75+ -- GHC's AST does not necessarily store each kind of element in source
76+ -- location order. This happens because different declarations are stored in
77+ -- different lists. Consequently, to get all the declarations in proper
78+ -- order, they need to be manually sorted.
79+ let sigs = (getLoc &&& fmap (SigD NoExt)) <$> cid_sigs
80+ vals = (getLoc &&& fmap (ValD NoExt)) <$> toList cid_binds
81+ tyFamInsts =
82+ ( getLoc &&& fmap (InstD NoExt . TyFamInstD NoExt)
83+ ) <$> cid_tyfam_insts
84+ dataFamInsts =
85+ ( getLoc &&& fmap (InstD NoExt . DataFamInstD NoExt)
86+ ) <$> cid_datafam_insts
87+ allDecls =
88+ snd <$>
89+ sortBy (comparing fst) (sigs <> vals <> tyFamInsts <> dataFamInsts)
90+ if null allDecls
91+ then newline
92+ else do
93+ switchLayout [getLoc hsib_body] breakpoint
94+ inci $ do
95+ txt "where"
96+ newline -- Ensure line is added after where clause.
97+ newline -- Add newline before first declaration.
98+ p_hsDecls Associated allDecls
75 XHsImplicitBndrs NoExt -> notImplemented "XHsImplicitBndrs"
99 XHsImplicitBndrs NoExt -> notImplemented "XHsImplicitBndrs"
76− -- GHC's AST does not necessarily store each kind of element in source
77− -- location order. This happens because different declarations are stored in
78− -- different lists. Consequently, to get all the declarations in proper
79− -- order, they need to be manually sorted.
80− let sigs = (getLoc &&& fmap (SigD NoExt)) <$> cid_sigs
81− vals = (getLoc &&& fmap (ValD NoExt)) <$> toList cid_binds
82− tyFamInsts =
83− ( getLoc &&& fmap (InstD NoExt . TyFamInstD NoExt)
84− ) <$> cid_tyfam_insts
85− dataFamInsts =
86− ( getLoc &&& fmap (InstD NoExt . DataFamInstD NoExt)
87− ) <$> cid_datafam_insts
88− allDecls =
89− snd <$>
90− sortBy (comparing fst) (sigs <> vals <> tyFamInsts <> dataFamInsts)
91− if not (null allDecls)
92− then do
93− txt " where"
94− newline -- Ensure line is added after where clause.
95− newline -- Add newline before first declaration.
96− inci (p_hsDecls Associated allDecls)
97− else newline
98 XClsInstDecl NoExt -> notImplemented "XClsInstDecl"
100 XClsInstDecl NoExt -> notImplemented "XClsInstDecl"
99
101
100p_tyFamInstDecl :: FamilyStyle -> TyFamInstDecl GhcPs -> R ()
102p_tyFamInstDecl :: FamilyStyle -> TyFamInstDecl GhcPs -> R ()
src/Ormolu/Printer/Meat/Declaration/RoleAnnotation.hs+1−1
@@ -32,7 +32,7 @@ p_roleAnnot' l_name anns = line $ do
32 breakpoint
32 breakpoint
33 let
33 let
34 p_role' = maybe (txt "_") p_role
34 p_role' = maybe (txt "_") p_role
35− inci $ velt' $ (located' p_role') <$> anns
35+ inci . sitcc $ sep breakpoint (sitcc . located' p_role') anns
36
36
37p_role :: Role -> R ()
37p_role :: Role -> R ()
38p_role = \case
38p_role = \case
src/Ormolu/Printer/Meat/Declaration/Rule.hs+9−10
@@ -16,13 +16,12 @@ import Ormolu.Printer.Meat.Common
16import Ormolu.Printer.Meat.Declaration.Signature
16import Ormolu.Printer.Meat.Declaration.Signature
17import Ormolu.Printer.Meat.Declaration.Value
17import Ormolu.Printer.Meat.Declaration.Value
18import Ormolu.Utils
18import Ormolu.Utils
19−import qualified Data.List.NonEmpty as NE
20import qualified Data.Text as T
19import qualified Data.Text as T
21
20
22p_ruleDecls :: RuleDecls GhcPs -> R ()
21p_ruleDecls :: RuleDecls GhcPs -> R ()
23p_ruleDecls = \case
22p_ruleDecls = \case
24− HsRules NoExt _ xs -> line $ pragma "RULES" $
23+ HsRules NoExt _ xs -> line . pragma "RULES" . sitcc $
25− velt' $ (located' p_ruleDecl) <$> xs
24+ sep breakpoint (sitcc . located' p_ruleDecl) xs
26 XRuleDecls NoExt -> notImplemented "XRuleDecls"
25 XRuleDecls NoExt -> notImplemented "XRuleDecls"
27
26
28p_ruleDecl :: RuleDecl GhcPs -> R ()
27p_ruleDecl :: RuleDecl GhcPs -> R ()
@@ -50,14 +49,14 @@ p_ruleName (_, name) = do
50 txt "\""
49 txt "\""
51
50
52p_ruleBndrs :: [LRuleBndr GhcPs] -> R ()
51p_ruleBndrs :: [LRuleBndr GhcPs] -> R ()
52+p_ruleBndrs [] = return ()
53p_ruleBndrs bndrs =
53p_ruleBndrs bndrs =
54− forM_ (NE.nonEmpty bndrs) $ \bndrs_ne ->
55− switchLayout (combineSrcSpans' (getLoc <$> bndrs_ne)) $ do
54+ switchLayout (getLoc <$> bndrs) $ do
56− txt "forall"
55+ txt "forall"
57− breakpoint
56+ breakpoint
58− inci $ do
57+ inci $ do
59− velt' (located' p_ruleBndr <$> bndrs)
58+ sitcc $ sep breakpoint (sitcc . located' p_ruleBndr) bndrs
60− txt "."
59+ txt "."
61
60
62p_ruleBndr :: RuleBndr GhcPs -> R ()
61p_ruleBndr :: RuleBndr GhcPs -> R ()
63p_ruleBndr = \case
62p_ruleBndr = \case
src/Ormolu/Printer/Meat/Declaration/Signature.hs+13−11
@@ -49,9 +49,9 @@ p_typeSig (n:ns) hswc = do
49 if null ns
49 if null ns
50 then p_typeAscription hswc
50 then p_typeAscription hswc
51 else inci $ do
51 else inci $ do
52− vlayout (return ()) newline
53 comma
52 comma
53+ breakpoint
54− velt (withSep comma p_rdrName ns)
54+ sep (comma >> breakpoint) p_rdrName ns
55 p_typeAscription hswc
55 p_typeAscription hswc
56
56
57p_typeAscription
57p_typeAscription
@@ -93,7 +93,7 @@ p_fixSig = \case
93 space
93 space
94 atom n
94 atom n
95 space
95 space
96− sequence_ (withSep comma p_rdrName names)
96+ sitcc $ sep (comma >> breakpoint) p_rdrName names
97 XFixitySig NoExt -> notImplemented "XFixitySig"
97 XFixitySig NoExt -> notImplemented "XFixitySig"
98
98
99p_inlineSig
99p_inlineSig
@@ -125,7 +125,7 @@ p_specSig name ts InlinePragma {..} = pragmaBraces $ do
125 breakpoint
125 breakpoint
126 inci $ do
126 inci $ do
127 txt ":: "
127 txt ":: "
128− velt (withSep comma (located' p_hsType) (hsib_body <$> ts))
128+ sep (comma >> breakpoint) (located' p_hsType . hsib_body) ts
129
129
130p_activation :: Activation -> R ()
130p_activation :: Activation -> R ()
131p_activation = \case
131p_activation = \case
@@ -162,12 +162,14 @@ p_booleanFormula
162 -> R ()
162 -> R ()
163p_booleanFormula = \case
163p_booleanFormula = \case
164 Var name -> p_rdrName name
164 Var name -> p_rdrName name
165− And xs -> velt $
165+ And xs -> sitcc $ sep
166+ (comma >> breakpoint)
166− withSep comma (located' p_booleanFormula) xs
167+ (located' p_booleanFormula)
168+ xs
167− Or xs -> velt $
169+ Or xs -> sitcc $ sep
168− withSep (vlayout space (return ()) >> txt "| ")
170+ (breakpoint >> txt "| ")
169− (located' p_booleanFormula)
171+ (located' p_booleanFormula)
170− xs
172+ xs
171 Parens l -> located l (parens . p_booleanFormula)
173 Parens l -> located l (parens . p_booleanFormula)
172
174
173p_completeSig
175p_completeSig
@@ -177,7 +179,7 @@ p_completeSig
177p_completeSig cs' mty =
179p_completeSig cs' mty =
178 located cs' $ \cs ->
180 located cs' $ \cs ->
179 pragma "COMPLETE" . inci $ do
181 pragma "COMPLETE" . inci $ do
180− velt (withSep comma p_rdrName cs)
182+ sitcc $ sep (comma >> breakpoint) p_rdrName cs
181 forM_ mty $ \ty -> do
183 forM_ mty $ \ty -> do
182 breakpoint
184 breakpoint
183 inci $ do
185 inci $ do
src/Ormolu/Printer/Meat/Declaration/Type.hs+1−1
@@ -26,6 +26,6 @@ p_synDecl name tvars t = line $ do
26 p_rdrName name
26 p_rdrName name
27 let HsQTvs {..} = tvars
27 let HsQTvs {..} = tvars
28 unless (null hsq_explicit) space
28 unless (null hsq_explicit) space
29− spaceSep (located' p_hsTyVarBndr) hsq_explicit
29+ sep space (located' p_hsTyVarBndr) hsq_explicit
30 breakpoint
30 breakpoint
31 inci (txt "= " >> located t p_hsType)
31 inci (txt "= " >> located t p_hsType)
src/Ormolu/Printer/Meat/Declaration/TypeFamily.hs+3−8
@@ -12,7 +12,6 @@ where
12
12
13import BasicTypes (LexicalFixity (..))
13import BasicTypes (LexicalFixity (..))
14import Control.Monad
14import Control.Monad
15−import Data.List.NonEmpty (NonEmpty (..))
16import Data.Maybe (isNothing, isJust)
15import Data.Maybe (isNothing, isJust)
17import GHC
16import GHC
18import Ormolu.Printer.Combinators
17import Ormolu.Printer.Combinators
@@ -31,11 +30,9 @@ p_famDecl style FamilyDecl {..} = do
31 Associated -> mempty
30 Associated -> mempty
32 Free -> " family"
31 Free -> " family"
33 let HsQTvs {..} = fdTyVars
32 let HsQTvs {..} = fdTyVars
34− combinedSpans = combineSrcSpans' $
35− getLoc fdLName :| fmap getLoc hsq_explicit
36 breakpoint
33 breakpoint
37 inci $ do
34 inci $ do
38− switchLayout combinedSpans $ do
35+ switchLayout (getLoc fdLName : (getLoc <$> hsq_explicit)) $ do
39 p_infixDefHelper
36 p_infixDefHelper
40 (isInfix fdFixity)
37 (isInfix fdFixity)
41 inci
38 inci
@@ -82,14 +79,12 @@ p_injectivityAnn (InjectivityAnn a bs) = do
82 p_rdrName a
79 p_rdrName a
83 space
80 space
84 txt "-> "
81 txt "-> "
85− spaceSep p_rdrName bs
82+ sep space p_rdrName bs
86
83
87p_tyFamInstEqn :: TyFamInstEqn GhcPs -> R ()
84p_tyFamInstEqn :: TyFamInstEqn GhcPs -> R ()
88p_tyFamInstEqn HsIB {..} = do
85p_tyFamInstEqn HsIB {..} = do
89 let FamEqn {..} = hsib_body
86 let FamEqn {..} = hsib_body
90− combinedSpans = combineSrcSpans' $
91− getLoc feqn_tycon :| fmap getLoc feqn_pats
87+ switchLayout (getLoc feqn_tycon : (getLoc <$> feqn_pats)) $ p_infixDefHelper
92− switchLayout combinedSpans $ p_infixDefHelper
93 (isInfix feqn_fixity)
88 (isInfix feqn_fixity)
94 inci
89 inci
95 (p_rdrName feqn_tycon)
90 (p_rdrName feqn_tycon)
src/Ormolu/Printer/Meat/Declaration/Value.hs+46−45
@@ -85,9 +85,9 @@ p_matchGroup'
85 -> MatchGroup GhcPs (Located body)
85 -> MatchGroup GhcPs (Located body)
86 -> R ()
86 -> R ()
87p_matchGroup' placer pretty style MG {..} =
87p_matchGroup' placer pretty style MG {..} =
88− locatedVia Nothing mg_alts $
89− newlineSep (located' (\m@Match {..} ->
88+ sep newline (located' (\m@Match {..} ->
90− p_match' placer pretty style (isInfixMatch m) (matchStrictness m) m_pats m_grhss))
89+ p_match' placer pretty style (isInfixMatch m) (matchStrictness m) m_pats m_grhss))
90+ (unLoc mg_alts)
91p_matchGroup' _ _ _ (XMatchGroup NoExt) = notImplemented "XMatchGroup"
91p_matchGroup' _ _ _ (XMatchGroup NoExt) = notImplemented "XMatchGroup"
92
92
93matchStrictness :: Match id body -> SrcStrictness
93matchStrictness :: Match id body -> SrcStrictness
@@ -137,8 +137,8 @@ p_match' placer pretty style isInfix strictness m_pats m_grhss = do
137 inci' = if isOneLineSpan combinedSpans
137 inci' = if isOneLineSpan combinedSpans
138 then id
138 then id
139 else inci
139 else inci
140− switchLayout combinedSpans $ do
140+ switchLayout [combinedSpans] $ do
141− let stdCase = velt' (located' p_pat <$> m_pats)
141+ let stdCase = sep breakpoint (located' p_pat) m_pats
142 case style of
142 case style of
143 Function name ->
143 Function name ->
144 p_infixDefHelper
144 p_infixDefHelper
@@ -201,12 +201,12 @@ p_match' placer pretty style isInfix strictness m_pats m_grhss = do
201 if isCase style && hasGuards
201 if isCase style && hasGuards
202 then RightArrow
202 then RightArrow
203 else EqualSign
203 else EqualSign
204− newlineSep (located' (p_grhs' pretty groupStyle)) grhssGRHSs
204+ sep newline (located' (p_grhs' pretty groupStyle)) grhssGRHSs
205 let whereLocation = combineSrcSpans patGrhssSpan $ getLoc grhssLocalBinds
205 let whereLocation = combineSrcSpans patGrhssSpan $ getLoc grhssLocalBinds
206 whereIsEmpty = GHC.isEmptyLocalBindsPR (unLoc grhssLocalBinds)
206 whereIsEmpty = GHC.isEmptyLocalBindsPR (unLoc grhssLocalBinds)
207 unless (GHC.eqEmptyLocalBinds (unLoc grhssLocalBinds))
207 unless (GHC.eqEmptyLocalBinds (unLoc grhssLocalBinds))
208 . inciLocalBinds
208 . inciLocalBinds
209− . switchLayout whereLocation $ do
209+ . switchLayout [whereLocation] $ do
210 if whereIsEmpty then newline else breakpoint
210 if whereIsEmpty then newline else breakpoint
211 txt "where"
211 txt "where"
212 unless whereIsEmpty $ do
212 unless whereIsEmpty $ do
@@ -214,8 +214,8 @@ p_match' placer pretty style isInfix strictness m_pats m_grhss = do
214 inci (located grhssLocalBinds p_hsLocalBinds)
214 inci (located grhssLocalBinds p_hsLocalBinds)
215 case style of
215 case style of
216 Lambda -> placeHanging placement $
216 Lambda -> placeHanging placement $
217− switchLayout patGrhssSpan p_body
217+ switchLayout [patGrhssSpan] p_body
218− _ -> switchLayout patGrhssSpan $
218+ _ -> switchLayout [patGrhssSpan] $
219 placeHanging placement p_body
219 placeHanging placement p_body
220
220
221p_grhs :: GroupStyle -> GRHS GhcPs (LHsExpr GhcPs) -> R ()
221p_grhs :: GroupStyle -> GRHS GhcPs (LHsExpr GhcPs) -> R ()
@@ -232,7 +232,7 @@ p_grhs' pretty style (GRHS NoExt guards body) =
232 [] -> p_body
232 [] -> p_body
233 xs -> do
233 xs -> do
234 txt "| "
234 txt "| "
235− velt $ withSep comma (located' p_stmt) xs
235+ sitcc (sep (comma >> breakpoint) (sitcc . located' p_stmt) xs)
236 space
236 space
237 txt $ case style of
237 txt $ case style of
238 EqualSign -> "="
238 EqualSign -> "="
@@ -298,7 +298,7 @@ p_hsCmd = \case
298 HsCmdDo NoExt es -> do
298 HsCmdDo NoExt es -> do
299 txt "do"
299 txt "do"
300 newline
300 newline
301− inci (located es (newlineSep (located' (sitcc . p_stmt' p_hsCmd))))
301+ inci (located es (sitcc . sep newline (located' (sitcc . p_stmt' p_hsCmd))))
302 HsCmdWrap {} -> notImplemented "HsCmdWrap"
302 HsCmdWrap {} -> notImplemented "HsCmdWrap"
303 XCmd {} -> notImplemented "XCmd"
303 XCmd {} -> notImplemented "XCmd"
304
304
@@ -368,7 +368,7 @@ p_stmt' pretty = \case
368 inci (p_hsExpr x)
368 inci (p_hsExpr x)
369 RecStmt {..} -> do
369 RecStmt {..} -> do
370 txt "rec "
370 txt "rec "
371− sitcc $ newlineSep (located' (p_stmt' pretty)) recS_stmts
371+ sitcc $ sep newline (located' (p_stmt' pretty)) recS_stmts
372 XStmtLR {} -> notImplemented "XStmtLR"
372 XStmtLR {} -> notImplemented "XStmtLR"
373
373
374gatherStmt :: ExprLStmt GhcPs -> [[ExprLStmt GhcPs]]
374gatherStmt :: ExprLStmt GhcPs -> [[ExprLStmt GhcPs]]
@@ -393,7 +393,7 @@ p_hsLocalBinds = \case
393 (Left <$> bagToList bag) ++ (Right <$> lsigs)
393 (Left <$> bagToList bag) ++ (Right <$> lsigs)
394 p_item (Left x) = located x p_valDecl'
394 p_item (Left x) = located x p_valDecl'
395 p_item (Right x) = located x p_sigDecl'
395 p_item (Right x) = located x p_sigDecl'
396− newlineSep (sitcc . p_item) (sortOn ssStart items)
396+ sitcc $ sep newline (sitcc . p_item) (sortOn ssStart items)
397 HsValBinds NoExt _ -> notImplemented "HsValBinds"
397 HsValBinds NoExt _ -> notImplemented "HsValBinds"
398 HsIPBinds NoExt _ -> notImplemented "HsIPBinds"
398 HsIPBinds NoExt _ -> notImplemented "HsIPBinds"
399 EmptyLocalBinds NoExt -> return ()
399 EmptyLocalBinds NoExt -> return ()
@@ -439,7 +439,7 @@ p_hsExpr = \case
439 txt "\\case"
439 txt "\\case"
440 newline
440 newline
441 inci (p_matchGroup LambdaCase mgroup)
441 inci (p_matchGroup LambdaCase mgroup)
442− HsApp NoExt f x -> do
442+ HsApp NoExt f x -> sitcc $ do
443 located f p_hsExpr
443 located f p_hsExpr
444 breakpoint
444 breakpoint
445 inci (located x p_hsExpr)
445 inci (located x p_hsExpr)
@@ -479,9 +479,11 @@ p_hsExpr = \case
479 case boxity of
479 case boxity of
480 Boxed -> parens
480 Boxed -> parens
481 Unboxed -> parensHash
481 Unboxed -> parensHash
482− parens' $ if isSection
482+ if isSection
483+ then switchLayout [] . parens' $
483− then sequence_ (withSep (txt ",") (located' p_hsTupArg) args)
484+ sep comma (located' p_hsTupArg) args
485+ else switchLayout (getLoc <$> args) . parens' . sitcc $
484− else velt (withSep comma (located' p_hsTupArg) args)
486+ sep (comma >> breakpoint) (sitcc . located' p_hsTupArg) args
485 ExplicitSum NoExt tag arity e -> do
487 ExplicitSum NoExt tag arity e -> do
486 let before = tag - 1
488 let before = tag - 1
487 after = arity - before - 1
489 after = arity - before - 1
@@ -496,7 +498,7 @@ p_hsExpr = \case
496 unless isFirst space
498 unless isFirst space
497 located l p_hsExpr
499 located l p_hsExpr
498 unless isLast space
500 unless isLast space
499− parensHash $ sequence_ (withSep (txt "|") f (zip args [0..]))
501+ parensHash $ sep (txt "|") f (zip args [0..])
500 HsCase NoExt e mgroup -> do
502 HsCase NoExt e mgroup -> do
501 txt "case "
503 txt "case "
502 located e p_hsExpr
504 located e p_hsExpr
@@ -518,7 +520,7 @@ p_hsExpr = \case
518 inci (p_hsExpr x)
520 inci (p_hsExpr x)
519 HsMultiIf NoExt guards -> do
521 HsMultiIf NoExt guards -> do
520 txt "if "
522 txt "if "
521− sitcc $ newlineSep (located' (p_grhs RightArrow)) guards
523+ sitcc $ sep newline (located' (p_grhs RightArrow)) guards
522 HsLet NoExt localBinds e -> do
524 HsLet NoExt localBinds e -> do
523 txt "let "
525 txt "let "
524 sitcc (located localBinds p_hsLocalBinds)
526 sitcc (located localBinds p_hsLocalBinds)
@@ -529,16 +531,14 @@ p_hsExpr = \case
529 let doBody header = do
531 let doBody header = do
530 txt header
532 txt header
531 newline
533 newline
532− inci $ located es (newlineSep (located' (sitcc . p_stmt)))
534+ inci $ located es (sep newline (located' (sitcc . p_stmt)))
533− compBody = brackets $ located es $ \xs -> do
535+ compBody = brackets $ located es $ \xs -> do
534− let p_parBody =
536+ let p_parBody = sitcc . sep
535− sequence_ .
536− intersperse breakpoint .
537+ (breakpoint >> txt "| ")
537− withSep (txt "| ") p_seqBody
538+ p_seqBody
538− p_seqBody =
539+ p_seqBody = sitcc . sep
539− sequence_ .
540+ (comma >> breakpoint)
540− intersperse (vlayout (pure ()) newline) .
541− withSep comma (located' (sitcc . p_stmt))
541+ (located' (sitcc . p_stmt))
542 stmts = init xs
542 stmts = init xs
543 yield = last xs
543 yield = last xs
544 lists = foldr (liftAppend . gatherStmt) [] stmts
544 lists = foldr (liftAppend . gatherStmt) [] stmts
@@ -557,7 +557,7 @@ p_hsExpr = \case
557 ParStmtCtxt _ -> notImplemented "ParStmtCtxt"
557 ParStmtCtxt _ -> notImplemented "ParStmtCtxt"
558 TransStmtCtxt _ -> notImplemented "TransStmtCtxt"
558 TransStmtCtxt _ -> notImplemented "TransStmtCtxt"
559 ExplicitList _ _ xs ->
559 ExplicitList _ _ xs ->
560− brackets $ velt (withSep comma (located' p_hsExpr) xs)
560+ brackets . sitcc $ sep (comma >> breakpoint) (sitcc . located' p_hsExpr) xs
561 RecordCon {..} -> do
561 RecordCon {..} -> do
562 located rcon_con_name atom
562 located rcon_con_name atom
563 breakpoint
563 breakpoint
@@ -567,11 +567,12 @@ p_hsExpr = \case
567 case rec_dotdot of
567 case rec_dotdot of
568 Just {} -> [txt ".."]
568 Just {} -> [txt ".."]
569 Nothing -> []
569 Nothing -> []
570− inci $ braces $ velt (withSep comma id (fields <> dotdot))
570+ inci . braces . sitcc $ sep (comma >> breakpoint) sitcc (fields <> dotdot)
571 RecordUpd {..} -> do
571 RecordUpd {..} -> do
572 located rupd_expr p_hsExpr
572 located rupd_expr p_hsExpr
573 breakpoint
573 breakpoint
574+ inci . braces . sitcc $
574− inci $ braces $ velt (withSep comma (located' p_hsRecField) rupd_flds)
575+ sep (comma >> breakpoint) (sitcc . located' p_hsRecField) rupd_flds
575 ExprWithTySig affix x -> sitcc $ do
576 ExprWithTySig affix x -> sitcc $ do
576 located x p_hsExpr
577 located x p_hsExpr
577 breakpoint
578 breakpoint
@@ -582,21 +583,21 @@ p_hsExpr = \case
582 located hsib_body p_hsType
583 located hsib_body p_hsType
583 ArithSeq NoExt _ x -> do
584 ArithSeq NoExt _ x -> do
584 case x of
585 case x of
585− From from -> brackets $ do
586+ From from -> brackets . sitcc $ do
586 located from p_hsExpr
587 located from p_hsExpr
587 breakpoint
588 breakpoint
588 txt ".."
589 txt ".."
589− FromThen from next -> brackets $ do
590+ FromThen from next -> brackets . sitcc $ do
590− velt (withSep comma (located' p_hsExpr) [from, next])
591+ sitcc $ sep (comma >> breakpoint) (located' p_hsExpr) [from, next]
591 breakpoint
592 breakpoint
592 txt ".."
593 txt ".."
593− FromTo from to -> brackets $ do
594+ FromTo from to -> brackets . sitcc $ do
594 located from p_hsExpr
595 located from p_hsExpr
595 breakpoint
596 breakpoint
596 txt ".. "
597 txt ".. "
597 located to p_hsExpr
598 located to p_hsExpr
598− FromThenTo from next to -> brackets $ do
599+ FromThenTo from next to -> brackets . sitcc $ do
599− velt (withSep comma (located' p_hsExpr) [from, next])
600+ sitcc $ sep (comma >> breakpoint) (located' p_hsExpr) [from, next]
600 breakpoint
601 breakpoint
601 txt ".. "
602 txt ".. "
602 located to p_hsExpr
603 located to p_hsExpr
@@ -680,9 +681,9 @@ p_patSynBind (XPatSynBind NoExt) = notImplemented "XPatSynBind"
680p_patSynDetails :: HsPatSynDetails (Located RdrName) -> R ()
681p_patSynDetails :: HsPatSynDetails (Located RdrName) -> R ()
681p_patSynDetails = \case
682p_patSynDetails = \case
682 PrefixCon xs ->
683 PrefixCon xs ->
683− velt' (p_rdrName <$> xs)
684+ sitcc $ sep breakpoint p_rdrName xs
684 RecCon xs ->
685 RecCon xs ->
685− velt' (p_rdrName . recordPatSynPatVar <$> xs)
686+ sitcc $ sep breakpoint (p_rdrName . recordPatSynPatVar) xs
686 InfixCon _ _ -> notImplemented "InfixCon"
687 InfixCon _ _ -> notImplemented "InfixCon"
687
688
688p_pat :: Pat GhcPs -> R ()
689p_pat :: Pat GhcPs -> R ()
@@ -702,13 +703,13 @@ p_pat = \case
702 txt "!"
703 txt "!"
703 located pat p_pat
704 located pat p_pat
704 ListPat NoExt pats -> do
705 ListPat NoExt pats -> do
705− brackets $ velt (withSep comma (located' p_pat) pats)
706+ brackets . sitcc $ sep (comma >> breakpoint) (located' p_pat) pats
706 TuplePat NoExt pats boxing -> do
707 TuplePat NoExt pats boxing -> do
707 let f =
708 let f =
708 case boxing of
709 case boxing of
709 Boxed -> parens
710 Boxed -> parens
710 Unboxed -> parensHash
711 Unboxed -> parensHash
711− f $ velt (withSep comma (located' p_pat) pats)
712+ f . sitcc $ sep (comma >> breakpoint) (sitcc . located' p_pat) pats
712 SumPat NoExt pat _ _ -> do
713 SumPat NoExt pat _ _ -> do
713 -- XXX I'm not sure about this one.
714 -- XXX I'm not sure about this one.
714 located pat p_pat
715 located pat p_pat
@@ -718,14 +719,14 @@ p_pat = \case
718 p_rdrName pat
719 p_rdrName pat
719 unless (null xs) $ do
720 unless (null xs) $ do
720 breakpoint
721 breakpoint
721− inci $ velt' (located' p_pat <$> xs)
722+ inci . sitcc $ sep breakpoint (sitcc . located' p_pat) xs
722 RecCon (HsRecFields fields dotdot) -> do
723 RecCon (HsRecFields fields dotdot) -> do
723 p_rdrName pat
724 p_rdrName pat
724 breakpoint
725 breakpoint
725 let f = \case
726 let f = \case
726 Nothing -> txt ".."
727 Nothing -> txt ".."
727 Just x -> located x p_pat_hsRecField
728 Just x -> located x p_pat_hsRecField
728− inci . braces . velt . withSep comma f $ case dotdot of
729+ inci . braces . sitcc . sep (comma >> breakpoint) f $ case dotdot of
729 Nothing -> Just <$> fields
730 Nothing -> Just <$> fields
730 Just n -> (Just <$> take n fields) ++ [Nothing]
731 Just n -> (Just <$> take n fields) ++ [Nothing]
731 InfixCon x y -> do
732 InfixCon x y -> do
@@ -899,7 +900,7 @@ exprPlacement = \case
899 RecordCon NoExt _ _ -> Hanging
900 RecordCon NoExt _ _ -> Hanging
900 HsProc NoExt (L s _) _ ->
901 HsProc NoExt (L s _) _ ->
901 -- Indentation breaks if pattern is longer than one line and left hanging.
902 -- Indentation breaks if pattern is longer than one line and left hanging.
902− -- Consequentally, once apply hanging when it is safe.
903+ -- Consequently, only apply hanging when it is safe.
903 if isOneLineSpan s
904 if isOneLineSpan s
904 then Hanging
905 then Hanging
905 else Normal
906 else Normal
src/Ormolu/Printer/Meat/Declaration/Warning.hs+4−9
@@ -9,13 +9,11 @@ where
9
9
10import BasicTypes
10import BasicTypes
11import Data.Foldable
11import Data.Foldable
12−import qualified Data.List.NonEmpty as NE
13import Data.Text (Text)
12import Data.Text (Text)
14import GHC
13import GHC
15import Ormolu.Printer.Combinators
14import Ormolu.Printer.Combinators
16import Ormolu.Printer.Meat.Common
15import Ormolu.Printer.Meat.Common
17import Ormolu.Utils
16import Ormolu.Utils
18−import SrcLoc (combineSrcSpans)
19
17
20p_warnDecls :: WarnDecls GhcPs -> R ()
18p_warnDecls :: WarnDecls GhcPs -> R ()
21p_warnDecls (Warnings NoExt _ warnings) =
19p_warnDecls (Warnings NoExt _ warnings) =
@@ -30,16 +28,16 @@ p_warnDecl XWarnDecl {} = notImplemented "XWarnDecl"
30p_moduleWarning :: WarningTxt -> R ()
28p_moduleWarning :: WarningTxt -> R ()
31p_moduleWarning wtxt = do
29p_moduleWarning wtxt = do
32 let (pragmaText, lits) = warningText wtxt
30 let (pragmaText, lits) = warningText wtxt
33− switchLayout (listSpan lits) $ do
31+ switchLayout (getLoc <$> lits) $ do
34 breakpoint
32 breakpoint
35 inci $ pragma pragmaText (inci $ p_lits lits)
33 inci $ pragma pragmaText (inci $ p_lits lits)
36
34
37p_topLevelWarning :: [Located RdrName] -> WarningTxt -> R ()
35p_topLevelWarning :: [Located RdrName] -> WarningTxt -> R ()
38p_topLevelWarning fnames wtxt = do
36p_topLevelWarning fnames wtxt = do
39 let (pragmaText, lits) = warningText wtxt
37 let (pragmaText, lits) = warningText wtxt
40− switchLayout (combineSrcSpans (listSpan fnames) (listSpan lits)) $ do
38+ switchLayout (fmap getLoc fnames ++ fmap getLoc lits) $ do
41 pragma pragmaText . inci $ do
39 pragma pragmaText . inci $ do
42− velt (withSep comma p_rdrName fnames)
40+ sitcc $ sep (comma >> breakpoint) p_rdrName fnames
43 breakpoint
41 breakpoint
44 p_lits lits
42 p_lits lits
45
43
@@ -48,10 +46,7 @@ warningText = \case
48 WarningTxt _ lits -> ("WARNING", lits)
46 WarningTxt _ lits -> ("WARNING", lits)
49 DeprecatedTxt _ lits -> ("DEPRECATED", lits)
47 DeprecatedTxt _ lits -> ("DEPRECATED", lits)
50
48
51−listSpan :: [Located a] -> SrcSpan
52−listSpan xs = combineSrcSpans' (getLoc <$> NE.fromList xs)
53−
54p_lits :: [Located StringLiteral] -> R ()
49p_lits :: [Located StringLiteral] -> R ()
55p_lits = \case
50p_lits = \case
56 [l] -> atom l
51 [l] -> atom l
57− ls -> brackets . velt $ withSep comma atom ls
52+ ls -> brackets . sitcc $ sep (comma >> breakpoint) atom ls
src/Ormolu/Printer/Meat/ImportExport.hs+5−5
@@ -23,7 +23,7 @@ p_hsmodExports [] = do
23 breakpoint'
23 breakpoint'
24 txt ")"
24 txt ")"
25p_hsmodExports xs =
25p_hsmodExports xs =
26− parens . velt $ withSep comma (sitcc . located' p_lie) xs
26+ parens . sitcc $ sep (comma >> breakpoint) (sitcc . located' p_lie) xs
27
27
28p_hsmodImport :: ImportDecl GhcPs -> R ()
28p_hsmodImport :: ImportDecl GhcPs -> R ()
29p_hsmodImport ImportDecl {..} = line $ do
29p_hsmodImport ImportDecl {..} = line $ do
@@ -52,10 +52,10 @@ p_hsmodImport ImportDecl {..} = line $ do
52 txt " hiding"
52 txt " hiding"
53 case ideclHiding of
53 case ideclHiding of
54 Nothing -> return ()
54 Nothing -> return ()
55− Just (_, l) -> do
55+ Just (_, (L _ a)) -> do
56 breakpoint
56 breakpoint
57− inci . locatedVia Nothing l $
57+ inci . parens . sitcc $
58− parens . velt . withSep comma (located' p_lie)
58+ sep (comma >> breakpoint) (sitcc . located' p_lie) a
59p_hsmodImport (XImportDecl NoExt) = notImplemented "XImportDecl"
59p_hsmodImport (XImportDecl NoExt) = notImplemented "XImportDecl"
60
60
61p_lie :: IE GhcPs -> R ()
61p_lie :: IE GhcPs -> R ()
@@ -72,7 +72,7 @@ p_lie = \case
72 inci $ do
72 inci $ do
73 let names :: [R ()]
73 let names :: [R ()]
74 names = located' p_ieWrappedName <$> xs
74 names = located' p_ieWrappedName <$> xs
75− parens . velt . withSep comma id $
75+ parens . sitcc . sep (comma >> breakpoint) sitcc $
76 case w of
76 case w of
77 NoIEWildcard -> names
77 NoIEWildcard -> names
78 IEWildcard n ->
78 IEWildcard n ->
src/Ormolu/Printer/Meat/Module.hs+6−8
@@ -20,18 +20,16 @@ import Ormolu.Printer.Meat.Declaration
20import Ormolu.Printer.Meat.Declaration.Warning
20import Ormolu.Printer.Meat.Declaration.Warning
21import Ormolu.Printer.Meat.ImportExport
21import Ormolu.Printer.Meat.ImportExport
22import Ormolu.Printer.Meat.LanguagePragma
22import Ormolu.Printer.Meat.LanguagePragma
23−import SrcLoc (combineSrcSpans)
24
23
25p_hsModule :: Set String -> ParsedSource -> R ()
24p_hsModule :: Set String -> ParsedSource -> R ()
26−p_hsModule exts loc@(L moduleSpan hsModule) = do
25+p_hsModule exts (L moduleSpan HsModule {..}) = do
27 -- NOTE If span of exports in multiline, the whole thing is multiline.
26 -- NOTE If span of exports in multiline, the whole thing is multiline.
28 -- This is especially important because span of module itself always seems
27 -- This is especially important because span of module itself always seems
29 -- to have length zero, so it's not reliable for layout selection.
28 -- to have length zero, so it's not reliable for layout selection.
30− let spn =
31− case hsmodExports hsModule of
29+ let spans' = case hsmodExports of
32− Nothing -> moduleSpan
30+ Nothing -> [moduleSpan]
33− Just (L exportsSpan _) -> combineSrcSpans moduleSpan exportsSpan
31+ Just (L exportsSpan _) -> moduleSpan : [exportsSpan]
34− locatedVia (Just spn) loc $ \HsModule {..} -> do
32+ switchLayout spans' $ do
35 let hasLangPragmas = not (null exts)
33 let hasLangPragmas = not (null exts)
36 hasModuleHeader = isJust hsmodName
34 hasModuleHeader = isJust hsmodName
37 hasImports = not (null hsmodImports)
35 hasImports = not (null hsmodImports)
@@ -49,7 +47,7 @@ p_hsModule exts loc@(L moduleSpan hsModule) = do
49 Nothing -> return ()
47 Nothing -> return ()
50 Just hsmodExports' -> do
48 Just hsmodExports' -> do
51 breakpoint
49 breakpoint
52− inci (locatedVia Nothing hsmodExports' p_hsmodExports)
50+ inci (p_hsmodExports (unLoc hsmodExports'))
53 breakpoint
51 breakpoint
54 txt "where"
52 txt "where"
55 when (hasImports || hasDecls) newline
53 when (hasImports || hasDecls) newline
src/Ormolu/Printer/Meat/Type.hs+17−15
@@ -22,16 +22,16 @@ p_hsType :: HsType GhcPs -> R ()
22p_hsType = \case
22p_hsType = \case
23 HsForAllTy NoExt bndrs t -> do
23 HsForAllTy NoExt bndrs t -> do
24 txt "forall "
24 txt "forall "
25− spaceSep (located' p_hsTyVarBndr) bndrs
25+ sep space (located' p_hsTyVarBndr) bndrs
26 txt ". "
26 txt ". "
27− locatedVia Nothing t p_hsType
27+ p_hsType (unLoc t)
28 HsQualTy NoExt qs t -> do
28 HsQualTy NoExt qs t -> do
29 located qs p_hsContext
29 located qs p_hsContext
30 breakpoint
30 breakpoint
31 txt "=> "
31 txt "=> "
32 case unLoc t of
32 case unLoc t of
33− HsQualTy {} -> locatedVia Nothing t p_hsType
33+ HsQualTy {} -> p_hsType (unLoc t)
34− HsFunTy {} -> locatedVia Nothing t p_hsType
34+ HsFunTy {} -> p_hsType (unLoc t)
35 _ -> located t p_hsType
35 _ -> located t p_hsType
36 HsTyVar NoExt p n -> do
36 HsTyVar NoExt p n -> do
37 case p of
37 case p of
@@ -60,9 +60,11 @@ p_hsType = \case
60 HsBoxedTuple -> parens
60 HsBoxedTuple -> parens
61 HsConstraintTuple -> parens
61 HsConstraintTuple -> parens
62 HsBoxedOrConstraintTuple -> parens
62 HsBoxedOrConstraintTuple -> parens
63+ in parens' . sitcc $
63− in parens' . velt $ withSep comma (located' p_hsType) xs
64+ sep (comma >> breakpoint) (sitcc . located' p_hsType) xs
64 HsSumTy NoExt xs ->
65 HsSumTy NoExt xs ->
66+ parensHash . sitcc $
65− parensHash . velt $ withSep (txt "| ") (located' p_hsType) xs
67+ sep (txt "| " >> breakpoint') (sitcc . located' p_hsType) xs
66 HsOpTy NoExt x op y -> do
68 HsOpTy NoExt x op y -> do
67 located x p_hsType
69 located x p_hsType
68 breakpoint
70 breakpoint
@@ -115,10 +117,10 @@ p_hsType = \case
115 case xs of
117 case xs of
116 ((L _ (HsTyVar _ Promoted _)):_) -> space
118 ((L _ (HsTyVar _ Promoted _)):_) -> space
117 _ -> return ()
119 _ -> return ()
118− velt $ withSep comma (located' p_hsType) xs
120+ sitcc $ sep (comma >> breakpoint) (sitcc . located' p_hsType) xs
119 HsExplicitTupleTy NoExt xs -> do
121 HsExplicitTupleTy NoExt xs -> do
120 txt "'"
122 txt "'"
121− parens . velt $ withSep comma (located' p_hsType) xs
123+ parens $ sep (comma >> breakpoint) (located' p_hsType) xs
122 HsTyLit NoExt t -> atom t
124 HsTyLit NoExt t -> atom t
123 HsWildCardTy NoExt -> txt "_"
125 HsWildCardTy NoExt -> txt "_"
124 XHsType (NHsCoreTy t) -> atom t
126 XHsType (NHsCoreTy t) -> atom t
@@ -127,7 +129,8 @@ p_hsContext :: HsContext GhcPs -> R ()
127p_hsContext = \case
129p_hsContext = \case
128 [] -> txt "()"
130 [] -> txt "()"
129 [x] -> located x p_hsType
131 [x] -> located x p_hsType
132+ xs -> parens . sitcc $
130− xs -> parens . velt $ withSep comma (located' p_hsType) xs
133+ sep (comma >> breakpoint) (sitcc . located' p_hsType) xs
131
134
132p_hsTyVarBndr :: HsTyVarBndr GhcPs -> R ()
135p_hsTyVarBndr :: HsTyVarBndr GhcPs -> R ()
133p_hsTyVarBndr = \case
136p_hsTyVarBndr = \case
@@ -142,23 +145,22 @@ p_hsTyVarBndr = \case
142 XTyVarBndr NoExt -> notImplemented "XTyVarBndr"
145 XTyVarBndr NoExt -> notImplemented "XTyVarBndr"
143
146
144p_conDeclFields :: [LConDeclField GhcPs] -> R ()
147p_conDeclFields :: [LConDeclField GhcPs] -> R ()
145−p_conDeclFields =
148+p_conDeclFields xs = braces . sitcc $
146− braces . velt . withSep comma (sitcc . located' p_conDeclField)
149+ sep (comma >> breakpoint) (sitcc . located' p_conDeclField) xs
147
150
148p_conDeclField :: ConDeclField GhcPs -> R ()
151p_conDeclField :: ConDeclField GhcPs -> R ()
149p_conDeclField ConDeclField {..} = do
152p_conDeclField ConDeclField {..} = do
150− sitcc . velt $ withSep
153+ sitcc $ sep (comma >> breakpoint)
151− comma
152 (located' (p_rdrName . rdrNameFieldOcc))
154 (located' (p_rdrName . rdrNameFieldOcc))
153 cd_fld_names
155 cd_fld_names
154 breakpoint
156 breakpoint
155 sitcc . inci $ do
157 sitcc . inci $ do
156 txt ":: "
158 txt ":: "
157− locatedVia Nothing cd_fld_type p_hsType
159+ p_hsType (unLoc cd_fld_type)
158p_conDeclField (XConDeclField NoExt) = notImplemented "XConDeclField"
160p_conDeclField (XConDeclField NoExt) = notImplemented "XConDeclField"
159
161
160----------------------------------------------------------------------------
162----------------------------------------------------------------------------
161−-- Convertion functions
163+-- Conversion functions
162
164
163tyVarsToTypes :: LHsQTyVars GhcPs -> [LHsType GhcPs]
165tyVarsToTypes :: LHsQTyVars GhcPs -> [LHsType GhcPs]
164tyVarsToTypes = \case
166tyVarsToTypes = \case
src/Ormolu/Utils.hs+2
@@ -1,5 +1,7 @@
1-- | Random utilities used by the code.
1-- | Random utilities used by the code.
2
2
3+{-# LANGUAGE LambdaCase #-}
4+
3module Ormolu.Utils
5module Ormolu.Utils
4 ( combineSrcSpans'
6 ( combineSrcSpans'
5 , isModule
7 , isModule
tests/Ormolu/Printer/CombinatorsSpec.hs+18−16
@@ -47,27 +47,27 @@ rSimpleSig :: R ()
47rSimpleSig = line rFn
47rSimpleSig = line rFn
48
48
49rList0 :: R ()
49rList0 :: R ()
50−rList0 = line . brackets $
50+rList0 = line . brackets . sitcc $
51− velt
51+ sep (comma >> breakpoint) id
52 [ txt "foo"
52 [ txt "foo"
53− , comma >> txt "bar"
53+ , txt "bar"
54− , comma >> txt "baz"
54+ , txt "baz"
55 ]
55 ]
56
56
57rList1 :: R ()
57rList1 :: R ()
58−rList1 = line . brackets $
58+rList1 = line . brackets . sitcc $
59− velt
59+ sep (comma >> breakpoint) id
60 [ txt "foo"
60 [ txt "foo"
61− , comma >> txt "bar"
61+ , txt "bar"
62− , comma >> rFn
62+ , rFn
63 ]
63 ]
64
64
65rFn :: R ()
65rFn :: R ()
66−rFn = velt'
66+rFn = sitcc $ sep breakpoint sitcc
67 [ txt "foo"
67 [ txt "foo"
68− , inci $ velt'
68+ , inci . sitcc $ sep breakpoint sitcc
69 [ do txt ":: "
69 [ do txt ":: "
70− parens $ velt'
70+ parens . sitcc $ sep breakpoint sitcc
71 [ txt "Int"
71 [ txt "Int"
72 , txt "-> " >> txt "Int"
72 , txt "-> " >> txt "Int"
73 ]
73 ]
@@ -80,11 +80,11 @@ rModuleHeader = do
80 line $ do
80 line $ do
81 txt "module "
81 txt "module "
82 txt "MyModule"
82 txt "MyModule"
83− line . inci . parens . velt $
83+ line . inci . parens . sitcc . sep (comma >> breakpoint) sitcc $
84 [ txt "R"
84 [ txt "R"
85− , comma >> txt "runR"
85+ , txt "runR"
86− , comma >> txt "txt"
86+ , txt "txt"
87− , comma >> txt "blah"
87+ , txt "blah"
88 ]
88 ]
89 line (txt "where")
89 line (txt "where")
90
90
@@ -96,8 +96,10 @@ rModuleHeader = do
96
96
97shouldRender :: R () -> FilePath -> Expectation
97shouldRender :: R () -> FilePath -> Expectation
98shouldRender m path = do
98shouldRender m path = do
99+ let rendered = runR False m mempty mempty emptyAnns
100+ -- T.writeFile path rendered
99 expected <- T.readFile path
101 expected <- T.readFile path
100− runR False m mempty mempty emptyAnns `shouldBe` expected
102+ rendered `shouldBe` expected
101
103
102-- | Render using single-line layout.
104-- | Render using single-line layout.
103
105
tests/Ormolu/PrinterSpec.hs+1
@@ -32,6 +32,7 @@ checkExample srcPath' = it (fromRelFile srcPath' ++ " works") $ do
32 formatted0 <- ormoluFile defaultConfig (fromRelFile srcPath)
32 formatted0 <- ormoluFile defaultConfig (fromRelFile srcPath)
33 -- 3. Check the output against expected output. Thus all tests should
33 -- 3. Check the output against expected output. Thus all tests should
34 -- include two files: input and expected output.
34 -- include two files: input and expected output.
35+ -- T.writeFile (fromRelFile expectedOutputPath) formatted0
35 expected <- (liftIO . T.readFile . fromRelFile) expectedOutputPath
36 expected <- (liftIO . T.readFile . fromRelFile) expectedOutputPath
36 shouldMatch False formatted0 expected
37 shouldMatch False formatted0 expected
37 -- 4. Check that running the formatter on the output produces the same
38 -- 4. Check that running the formatter on the output produces the same