on master help sign in
Implement properly indented constraint contexts
ba64967yumiova
data/examples/declaration/class/dependency-super-classes-out.hs+6−5
@@ -8,11 +8,12 @@ class (MonadReader r s, MonadWriter w m) => MonadState s m | m -> s where
8 put :: s -> m ()
8 put :: s -> m ()
9
9
10-- | 'MonadParsec'
10-- | 'MonadParsec'
11+class
11−class ( Stream s -- Token streams
12+ ( Stream s -- Token streams
12− , MonadPlus m -- Potential for failure
13+ , MonadPlus m -- Potential for failure
13− )
14+ )
14− => MonadParsec e s m
15+ => MonadParsec e s m
15− | m -> e s where
16+ | m -> e s where
16
17
17 -- | 'getState' returns state
18 -- | 'getState' returns state
18 getState
19 getState
data/examples/declaration/class/functional-dependencies-out.hs+7−6
@@ -8,11 +8,12 @@ class Bar a b | a -> b, b -> a where
8 bar :: a
8 bar :: a
9
9
10-- | Something else.
10-- | Something else.
11+class
11−class Baz a b c d
12+ Baz a b c d
12− | a b -> c d -- Foo
13+ | a b -> c d -- Foo
13− , b c -> a d -- Bar
14+ , b c -> a d -- Bar
14− , a c -> b d -- Baz
15+ , a c -> b d -- Baz
15− , a c d -> b
16+ , a c d -> b
16− , a b d -> a b c d where
17+ , a b d -> a b c d where
17
18
18 baz :: a -> b
19 baz :: a -> b
data/examples/declaration/class/multi-parameters-out.hs+9−8
@@ -13,18 +13,19 @@ class Bar a b c d where
13 -> d
13 -> d
14
14
15class -- Before name
15class -- Before name
16− Baz where
16+ Baz where
17
17
18 baz :: Int
18 baz :: Int
19
19
20-- | Something else.
20-- | Something else.
21+class
21−class BarBaz
22+ BarBaz
22− a -- Foo
23+ a -- Foo
23− b -- Bar
24+ b -- Bar
24− c -- Baz bar
25+ c -- Baz bar
25− d -- Baz baz
26+ d -- Baz baz
26− e -- Rest
27+ e -- Rest
27− f where
28+ f where
28
29
29 barbaz
30 barbaz
30 :: a -> f
31 :: a -> f
data/examples/declaration/class/poly-kinded-classes-out.hs+5−4
@@ -1,7 +1,8 @@
1{-# LANGUAGE PolyKinds #-}
1{-# LANGUAGE PolyKinds #-}
2class Foo (a :: k)
2class Foo (a :: k)
3
3
4−class Bar
4+class
5+ Bar
5− ( a -- Variable
6+ ( a -- Variable
6− :: * -- Star
7+ :: * -- Star
7− )
8+ )
data/examples/declaration/class/super-classes-out.hs+9−7
@@ -2,11 +2,13 @@ class Foo a
2
2
3class Foo a => Bar a
3class Foo a => Bar a
4
4
5+class
5−class (Foo a, Bar a)
6+ (Foo a, Bar a)
6− => Baz a
7+ => Baz a
7
8
9+class
8−class ( Foo a -- Foo?
10+ ( Foo a -- Foo?
9− , Bar a -- Bar?
11+ , Bar a -- Bar?
10− , Baz a -- Baz
12+ , Baz a -- Baz
11− )
13+ )
12− => BarBar a
14+ => BarBar a
data/examples/declaration/class/type-operators-out.hs+20−15
@@ -2,28 +2,33 @@
2{-# LANGUAGE TypeOperators #-}
2{-# LANGUAGE TypeOperators #-}
3class (:$) a b
3class (:$) a b
4
4
5−class (:&)
5+class
6+ (:&)
6− a
7+ a
7− b
8+ b
8
9
9class a :* b
10class a :* b
10
11
12+class
11−class a :+ -- Before operator
13+ a :+ -- Before operator
12− b -- After operator
14+ b -- After operator
13
15
14−class ( f :.
16+class
17+ ( f :.
15− g
18+ g
16− )
19+ )
17− a
20+ a
18
21
19class a `Pair` b
22class a `Pair` b
20
23
21−class a `Sum`
24+class
25+ a `Sum`
22− b
26+ b
23
27
24class (f `Product` g) a
28class (f `Product` g) a
25
29
26−class ( f `Sum`
30+class
31+ ( f `Sum`
27− g
32+ g
28− )
33+ )
29− a
34+ a
data/examples/declaration/instance/contexts-out.hs+34−5
@@ -2,10 +2,39 @@ instance Eq a => Eq [a] where
2
2
3 (==) _ _ = False
3 (==) _ _ = False
4
4
5−instance ( Ord a
5+instance
6+ ( Ord a
6− , Ord b
7+ , Ord b
7− )
8+ )
8− => Ord
9− (a, b) where
9+ => Ord (a, b) where
10
10
11 compare _ _ = GT
11 compare _ _ = GT
12+
13+instance
14+ (Show a, Show b)
15+ => Show
16+ ( a
17+ , b
18+ ) where
19+
20+ showsPrec _ _ = showString ""
21+
22+instance
23+ ( Read a -- Foo
24+ , Read b
25+ , Read
26+ ( c
27+ , -- Bar
28+ d
29+ )
30+ )
31+ => Read
32+ ( a
33+ , -- Baz
34+ b
35+ , ( c -- Quux
36+ , d
37+ )
38+ ) where
39+
40+ readsPrec = undefined
data/examples/declaration/instance/contexts.hs+26
@@ -5,3 +5,29 @@ instance (
5 Ord b
5 Ord b
6 ) => Ord (a,b) where
6 ) => Ord (a,b) where
7 compare _ _ = GT
7 compare _ _ = GT
8+
9+instance (Show a, Show b) =>
10+ Show (
11+ a,
12+ b
13+ ) where
14+ showsPrec _ _ = showString ""
15+
16+instance (
17+ Read a, -- Foo
18+ Read b
19+ , Read (
20+ c, -- Bar
21+ d
22+ )
23+ )
24+ =>
25+ Read (
26+ a, -- Baz
27+ b
28+ ,(
29+ c, -- Quux
30+ d
31+ )
32+ ) where
33+ readsPrec = undefined
data/examples/declaration/instance/overlappable-instances-out.hs+4−1
@@ -10,6 +10,9 @@ instance {-# OVERLAPS #-} Eq Double where
10
10
11 (==) _ _ = False
11 (==) _ _ = False
12
12
13+instance
14+ {-# INCOHERENT #-}
15+ Ord
13−instance {-# INCOHERENT #-} Ord Double where
16+ Double where
14
17
15 compare _ _ = GT
18 compare _ _ = GT
data/examples/declaration/instance/overlappable-instances.hs+3−1
@@ -7,5 +7,7 @@ instance {-# OVERLAPS #-} Eq Double where
7 (==) _ _ = False
7 (==) _ _ = False
8
8
9instance
9instance
10+ {-# INCOHERENT #-}
11+ Ord
10− {-# INCOHERENT #-} Ord Double where
12+ Double where
11 compare _ _ = GT
13 compare _ _ = GT
src/Ormolu/Printer/Meat/Declaration/Class.hs+12−10
@@ -44,16 +44,18 @@ p_classDecl ctx name tvars fixity fdeps csigs cdefs cats catdefs = do
44 getLoc ctx `combineSrcSpans`
44 getLoc ctx `combineSrcSpans`
45 signatureSpans `combineSrcSpans`
45 signatureSpans `combineSrcSpans`
46 dependencySpans
46 dependencySpans
47− txt "class "
47+ txt "class"
48− sitcc $ do
48+ switchLayout combinedSpans $ do
49+ breakpoint
50+ inci $ do
49− switchLayout combinedSpans $ p_classContext ctx
51+ p_classContext ctx
50− switchLayout signatureSpans $ do
52+ switchLayout signatureSpans $ do
51− p_infixDefHelper
53+ p_infixDefHelper
52− (isInfix fixity)
54+ (isInfix fixity)
53− inci
55+ inci
54− (p_rdrName name)
56+ (p_rdrName name)
55− (located' p_hsTyVarBndr <$> hsq_explicit)
57+ (located' p_hsTyVarBndr <$> hsq_explicit)
56− switchLayout combinedSpans $ p_classFundeps fdeps
58+ inci (p_classFundeps fdeps)
57 -- GHC's AST does not necessarily store each kind of element in source
59 -- GHC's AST does not necessarily store each kind of element in source
58 -- location order. This happens because different declarations are stored in
60 -- location order. This happens because different declarations are stored in
59 -- different lists. Consequently, to get all the declarations in proper order,
61 -- different lists. Consequently, to get all the declarations in proper order,
src/Ormolu/Printer/Meat/Declaration/Instance.hs+6−3
@@ -65,10 +65,13 @@ p_standaloneDerivDecl (XDerivDecl _) = notImplemented "XDerivDecl"
65p_clsInstDecl :: ClsInstDecl GhcPs -> R ()
65p_clsInstDecl :: ClsInstDecl GhcPs -> R ()
66p_clsInstDecl = \case
66p_clsInstDecl = \case
67 ClsInstDecl {..} -> do
67 ClsInstDecl {..} -> do
68− txt "instance "
68+ txt "instance"
69− match_overlap_mode cid_overlap_mode space
70 case cid_poly_ty of
69 case cid_poly_ty of
71− HsIB {..} -> sitcc (located hsib_body p_hsType)
70+ HsIB {..} -> located hsib_body $ \x -> do
71+ breakpoint
72+ inci $ do
73+ match_overlap_mode cid_overlap_mode breakpoint
74+ p_hsType x
72 XHsImplicitBndrs NoExt -> notImplemented "XHsImplicitBndrs"
75 XHsImplicitBndrs NoExt -> notImplemented "XHsImplicitBndrs"
73 -- GHC's AST does not necessarily store each kind of element in source
76 -- GHC's AST does not necessarily store each kind of element in source
74 -- location order. This happens because different declarations are stored in
77 -- location order. This happens because different declarations are stored in
src/Ormolu/Printer/Meat/Type.hs+4−1
@@ -29,7 +29,10 @@ p_hsType = \case
29 located qs p_hsContext
29 located qs p_hsContext
30 breakpoint
30 breakpoint
31 txt "=> "
31 txt "=> "
32+ case unLoc t of
32− locatedVia Nothing t p_hsType
33+ HsQualTy {} -> locatedVia Nothing t p_hsType
34+ HsFunTy {} -> locatedVia Nothing t p_hsType
35+ _ -> located t p_hsType
33 HsTyVar NoExt p n -> do
36 HsTyVar NoExt p n -> do
34 case p of
37 case p of
35 Promoted -> txt "'"
38 Promoted -> txt "'"