on master help sign in
Implement fixity signatures, plus some refactoring
a8235f7mrkkrp
data/examples/declaration/signature/fixity/infix-out.hsnew file+3
@@ -0,0 +1,3 @@
1+infix 0 <?>
2+
3+infix 9 <^-^>
data/examples/declaration/signature/fixity/infix.hsnew file+2
@@ -0,0 +1,2 @@
1+infix 0 <?>
2+infix 9 <^-^>
data/examples/declaration/signature/fixity/infixl-out.hsnew file+3
@@ -0,0 +1,3 @@
1+infixl 8 ***
2+
3+infixl 0 $, *, +, &&, **
data/examples/declaration/signature/fixity/infixl.hsnew file+2
@@ -0,0 +1,2 @@
1+infixl 8 ***
2+infixl 0 $, *, +, &&, **
data/examples/declaration/signature/fixity/infixr-out.hsnew file+3
@@ -0,0 +1,3 @@
1+infixr 8 `Foo`
2+
3+infixr 0 ***, &&&
data/examples/declaration/signature/fixity/infixr.hsnew file+2
@@ -0,0 +1,2 @@
1+infixr 8 `Foo`
2+infixr 0 ***, &&&
data/examples/declaration/type/arguments-out.hs → data/examples/declaration/signature/type/arguments-out.hsrenamed

The content is the same.

data/examples/declaration/type/arguments.hs → data/examples/declaration/signature/type/arguments.hsrenamed

The content is the same.

data/examples/declaration/type/context-multi-line-out.hs → data/examples/declaration/signature/type/context-multi-line-out.hsrenamed

The content is the same.

data/examples/declaration/type/context-multi-line.hs → data/examples/declaration/signature/type/context-multi-line.hsrenamed

The content is the same.

data/examples/declaration/type/context-single-line-out.hs → data/examples/declaration/signature/type/context-single-line-out.hsrenamed

The content is the same.

data/examples/declaration/type/context-single-line.hs → data/examples/declaration/signature/type/context-single-line.hsrenamed

The content is the same.

data/examples/declaration/type/infix-promoted-type-constructor-out.hs → data/examples/declaration/signature/type/infix-promoted-type-constructor-out.hsrenamed

The content is the same.

data/examples/declaration/type/infix-promoted-type-constructor.hs → data/examples/declaration/signature/type/infix-promoted-type-constructor.hsrenamed

The content is the same.

data/examples/declaration/type/long-function-name-out.hs → data/examples/declaration/signature/type/long-function-name-out.hsrenamed

The content is the same.

data/examples/declaration/type/long-function-name.hs → data/examples/declaration/signature/type/long-function-name.hsrenamed

The content is the same.

data/examples/declaration/type/long-multiline-applications-out.hs → data/examples/declaration/signature/type/long-multiline-applications-out.hsrenamed

The content is the same.

data/examples/declaration/type/long-multiline-applications.hs → data/examples/declaration/signature/type/long-multiline-applications.hsrenamed

The content is the same.

src/Ormolu/Printer/Meat/Declaration/Signature.hs+29−5
@@ -10,6 +10,7 @@ module Ormolu.Printer.Meat.Declaration.Signature
10 )
10 )
11where
11where
12
12
13+import BasicTypes (Fixity (..))
13import Control.Monad
14import Control.Monad
14import GHC
15import GHC
15import Ormolu.Printer.Combinators
16import Ormolu.Printer.Combinators
@@ -23,14 +24,13 @@ p_sigDecl = line . p_sigDecl'
23p_sigDecl' :: Sig GhcPs -> R ()
24p_sigDecl' :: Sig GhcPs -> R ()
24p_sigDecl' = \case
25p_sigDecl' = \case
25 TypeSig NoExt names hswc -> p_typeSig names hswc
26 TypeSig NoExt names hswc -> p_typeSig names hswc
26− ClassOpSig NoExt def names hsib -> do
27+ ClassOpSig NoExt def names hsib -> p_classOpSig def names hsib
27− when def (txt "default ")
28+ FixSig NoExt sig -> p_fixSig sig
28− p_typeSig names HsWC {hswc_ext = NoExt, hswc_body = hsib}
29 _ -> notImplemented "certain types of signature declarations"
29 _ -> notImplemented "certain types of signature declarations"
30
30
31p_typeSig
31p_typeSig
32− :: [Located RdrName]
32+ :: [Located RdrName] -- ^ Names (before @::@)
33− -> LHsSigWcType GhcPs
33+ -> LHsSigWcType GhcPs -- ^ Type
34 -> R ()
34 -> R ()
35p_typeSig names HsWC {..} = do
35p_typeSig names HsWC {..} = do
36 spaceSep p_rdrName names
36 spaceSep p_rdrName names
@@ -39,3 +39,27 @@ p_typeSig names HsWC {..} = do
39 txt ":: "
39 txt ":: "
40 located (hsib_body hswc_body) p_hsType
40 located (hsib_body hswc_body) p_hsType
41p_typeSig _ (XHsWildCardBndrs NoExt) = notImplemented "XHsWildCardBndrs"
41p_typeSig _ (XHsWildCardBndrs NoExt) = notImplemented "XHsWildCardBndrs"
42+
43+p_classOpSig
44+ :: Bool -- ^ Whether this is a \"default\" signature
45+ -> [Located RdrName] -- ^ Names (before @::@)
46+ -> HsImplicitBndrs GhcPs (LHsType GhcPs) -- ^ Type
47+ -> R ()
48+p_classOpSig def names hsib = do
49+ when def (txt "default ")
50+ p_typeSig names HsWC {hswc_ext = NoExt, hswc_body = hsib}
51+
52+p_fixSig
53+ :: FixitySig GhcPs
54+ -> R ()
55+p_fixSig = \case
56+ FixitySig NoExt names (Fixity _ n dir) -> do
57+ txt $ case dir of
58+ InfixL -> "infixl"
59+ InfixR -> "infixr"
60+ InfixN -> "infix"
61+ space
62+ atom n
63+ space
64+ sequence_ (withSep comma p_rdrName names)
65+ XFixitySig NoExt -> notImplemented "XFixitySig"