Use new operator style in types & declarations

```
a
  + b
```

instead of

```
a +
  b
This commit is contained in:
Utku Demir 2019-08-16 11:59:41 +12:00 committed by Mark Karpov
parent f86155a8ea
commit 159e5e7761
6 changed files with 54 additions and 24 deletions

View File

@ -11,25 +11,33 @@ class
class a :* b
class
a :+ -- Before operator
b -- After operator
a -- Before operator
:+ b -- After operator
class
( f :.
g
( f
:. g
)
a
class a `Pair` b
class
a `Sum`
b
a
`Sum` b
class (f `Product` g) a
class
( f `Sum`
g
( f
`Sum` g
)
a
type API
= "route1" :> ApiRoute1
:<|> "route2"
:> ApiRoute2 -- comment here
:<|> OmitDocs
:> "i"
:> ASomething API

View File

@ -30,3 +30,10 @@ class (f`Product`g)a
class (
f `Sum` g
) a
type API
= "route1" :> ApiRoute1
:<|> "route2" :> ApiRoute2 -- comment here
:<|> OmitDocs :> "i" :> ASomething API

View File

@ -9,8 +9,8 @@ data a :-> b = Arrow (a -> b)
data (f :* g) a = f a :* g a
data
( f :+
g
( f
:+ g
)
a
= L (f a)
@ -21,8 +21,8 @@ data a `Arrow` b = Arrow' (a -> b)
data (f `Product` g) a = f a `Product` g a
data
( f `Sum`
g
( f
`Sum` g
)
a
= L' (f a)

View File

@ -8,5 +8,5 @@ bar :: Int -> Int -> Int -> Int
(x `bar` y) z = z
multiline :: Int -> Int -> Int
x `multiline`
y = z
x
`multiline` y = z

View File

@ -124,10 +124,11 @@ p_infixDefHelper isInfix inci' name args =
else parens
parens' $ do
p0
space
name
breakpoint
inci' p1
inci $ sitcc $ do
name
space
p1
unless (null ps) . inci' $ do
breakpoint
sitcc (sep breakpoint sitcc ps)

View File

@ -17,6 +17,7 @@ import GHC
import Ormolu.Printer.Combinators
import Ormolu.Printer.Meat.Common
import Ormolu.Utils
import SrcLoc (combineSrcSpans)
import {-# SOURCE #-} Ormolu.Printer.Meat.Declaration.Value (p_hsSplice)
p_hsType :: HsType GhcPs -> R ()
@ -66,13 +67,26 @@ p_hsType = \case
HsSumTy NoExt xs ->
parensHash . sitcc $
sep (txt "| " >> breakpoint') (sitcc . located' p_hsType) xs
HsOpTy NoExt x op y -> do
located x p_hsType
breakpoint
inci $ do
p_rdrName op
space
located y p_hsType
HsOpTy NoExt x op y -> sitcc $ do
-- In the AST, type operators are right-associative instead of left-associative
-- like value level operators. This makes similar constructs look inconsistent.
-- Here, we shake the AST to convert right-associative tree to a left-associative
-- one.
case unLoc y of
HsOpTy NoExt x' op' y' ->
p_hsType $
HsOpTy
NoExt
(L (combineSrcSpans (getLoc x) (getLoc x')) (HsOpTy NoExt x op x'))
op'
y'
_ -> do
located x p_hsType
breakpoint
inci $ do
p_rdrName op
space
located y p_hsType
HsParTy NoExt (L _ t@HsKindSig {}) ->
-- NOTE Kind signatures already put parentheses around in all cases, so
-- skip this layer of parentheses. The reason for this behavior is that