on master help sign in
Support StandaloneKindSignatures
commitb0a261fe5b7e0bb2ef9dbdfdcfad6b6dffe3f10b authorUtku Demir <me@utdemir.com> dateSun 29 Mar 2020, 19:45 (7 years ago) parent2c54729
4 files changed+51−2
data/examples/declaration/signature/standalone-kind-out.hs+13 data/examples/declaration/signature/standalone-kind.hs+13 src/Ormolu/Printer/Meat/Declaration.hs+11−2 src/Ormolu/Printer/Meat/Declaration/Signature.hs+14
data/examples/declaration/signature/standalone-kind-out.hsnew file+13
@@ -0,0 +1,13 @@
1+{-# LANGUAGE StandaloneKindSignatures #-}
2+
3+type T ::
4+ (k -> Type) ->
5+ k ->
6+ Type
7+data T m a = MkT (m a) (T Maybe (m a))
8+
9+type C1 :: Type -> Constraint
10+class C1 a
11+
12+type F :: Type -> Type
13+type family F
data/examples/declaration/signature/standalone-kind.hsnew file+13
@@ -0,0 +1,13 @@
1+{-# LANGUAGE StandaloneKindSignatures #-}
2+
3+type T :: (k -> Type)
4+ -> k
5+ -> Type
6+
7+data T m a = MkT (m a) (T Maybe (m a))
8+
9+type C1 :: Type -> Constraint
10+class C1 a
11+
12+type F :: Type -> Type
13+type family F
src/Ormolu/Printer/Meat/Declaration.hs+11−2
@@ -128,7 +128,7 @@ p_hsDecl style = \case
128128 DocCommentNamed name str -> p_hsDocString (Named name) False (noLoc str)
129129 DocGroup n str -> p_hsDocString (Asterisk n) False (noLoc str)
130130 RoleAnnotD NoExtField x -> p_roleAnnot x
131− KindSigD NoExtField _ -> notImplemented "StandaloneKindSignatures"
131+ KindSigD NoExtField s -> p_standaloneKindSig s
132132 XHsDecl x -> noExtCon x
133133
134134p_tyClDecl :: FamilyStyle -> TyClDecl GhcPs -> R ()
@@ -187,6 +187,9 @@ groupedDecls x y | Just ns <- isPragma x, Just ns' <- isPragma y = ns `intersect
187187groupedDecls x (TypeSignature ns) | Just ns' <- isPragma x = ns `intersects` ns'
188188groupedDecls (TypeSignature ns) x | Just ns' <- isPragma x = ns `intersects` ns'
189189groupedDecls (PatternSignature ns) (Pattern n) = n `elem` ns
190+groupedDecls (KindSignature n) (DataDeclaration n') = n == n'
191+groupedDecls (KindSignature n) (ClassDeclaration n') = n == n'
192+groupedDecls (KindSignature n) (FamilyDeclaration n') = n == n'
190193-- This looks only at Haddocks, normal comments are handled elsewhere
191194groupedDecls DocNext _ = True
192195groupedDecls _ DocPrev = True
@@ -224,7 +227,10 @@ pattern
224227 AnnTypePragma,
225228 AnnValuePragma,
226229 Pattern,
227− DataDeclaration ::
230+ DataDeclaration,
231+ ClassDeclaration,
232+ KindSignature,
233+ FamilyDeclaration ::
228234 RdrName -> HsDecl GhcPs
229235pattern InlinePragma n <- SigD NoExtField (InlineSig NoExtField (L _ n) _)
230236pattern SpecializePragma n <- SigD NoExtField (SpecSig NoExtField (L _ n) _ _)
@@ -233,6 +239,9 @@ pattern AnnTypePragma n <- AnnD NoExtField (HsAnnotation NoExtField _ (TypeAnnPr
233239pattern AnnValuePragma n <- AnnD NoExtField (HsAnnotation NoExtField _ (ValueAnnProvenance (L _ n)) _)
234240pattern Pattern n <- ValD NoExtField (PatSynBind NoExtField (PSB _ (L _ n) _ _ _))
235241pattern DataDeclaration n <- TyClD NoExtField (DataDecl NoExtField (L _ n) _ _ _)
242+pattern ClassDeclaration n <- TyClD NoExtField (ClassDecl NoExtField _ (L _ n) _ _ _ _ _ _ _ _)
243+pattern KindSignature n <- KindSigD NoExtField (StandaloneKindSig NoExtField (L _ n) _)
244+pattern FamilyDeclaration n <- TyClD NoExtField (FamDecl NoExtField (FamilyDecl NoExtField _ (L _ n) _ _ _ _))
236245
237246-- Declarations which can refer to multiple names
238247
src/Ormolu/Printer/Meat/Declaration/Signature.hs+14
@@ -7,6 +7,7 @@ module Ormolu.Printer.Meat.Declaration.Signature
77 ( p_sigDecl,
88 p_typeAscription,
99 p_activation,
10+ p_standaloneKindSig,
1011 )
1112where
1213
@@ -218,3 +219,16 @@ p_sccSig loc literal = pragma "SCC" . inci $ do
218219 forM_ literal $ \x -> do
219220 breakpoint
220221 atom x
222+
223+p_standaloneKindSig :: StandaloneKindSig GhcPs -> R ()
224+p_standaloneKindSig (StandaloneKindSig NoExtField name bndrs) = do
225+ txt "type"
226+ space
227+ p_rdrName name
228+ space
229+ txt "::"
230+ breakpoint
231+ inci $ case bndrs of
232+ HsIB NoExtField sig -> located sig p_hsType
233+ XHsImplicitBndrs x -> noExtCon x
234+p_standaloneKindSig (XStandaloneKindSig c) = noExtCon c