on master help sign in
Support rendering of role annotation declarations
a325cd6PanAeon
data/examples/declaration/role-annotation/simple-out.hsnew file+25
@@ -0,0 +1,25 @@
1+{-# LANGUAGE RoleAnnotations #-}
2+{-# LANGUAGE MagicHash #-}
3+type role Ptr representational
4+
5+type role A nominal nominal
6+
7+type role B _ phantom
8+
9+type role C _ _
10+
11+type role
12+ D
13+ phantom
14+ nominal
15+
16+type role
17+ E
18+ _
19+ nominal
20+
21+type role
22+ E
23+ _
24+ nominal
25+ phantom
data/examples/declaration/role-annotation/simple.hsnew file+25
@@ -0,0 +1,25 @@
1+{-# LANGUAGE RoleAnnotations #-}
2+{-# LANGUAGE MagicHash #-}
3+
4+type role Ptr representational
5+
6+type role A nominal nominal
7+
8+type role B _ phantom
9+type role C _ _
10+
11+type role
12+ D phantom nominal
13+
14+type
15+ role
16+ E
17+ _
18+ nominal
19+
20+type
21+ role
22+ E
23+ _
24+ nominal
25+ phantom
ormolu.cabal+2−1
@@ -61,8 +61,9 @@ library
61 , Ormolu.Printer.Meat.Common
61 , Ormolu.Printer.Meat.Common
62 , Ormolu.Printer.Meat.Declaration
62 , Ormolu.Printer.Meat.Declaration
63 , Ormolu.Printer.Meat.Declaration.Class
63 , Ormolu.Printer.Meat.Declaration.Class
64− , Ormolu.Printer.Meat.Declaration.Instance
65 , Ormolu.Printer.Meat.Declaration.Data
64 , Ormolu.Printer.Meat.Declaration.Data
65+ , Ormolu.Printer.Meat.Declaration.Instance
66+ , Ormolu.Printer.Meat.Declaration.RoleAnnotation
66 , Ormolu.Printer.Meat.Declaration.Signature
67 , Ormolu.Printer.Meat.Declaration.Signature
67 , Ormolu.Printer.Meat.Declaration.Type
68 , Ormolu.Printer.Meat.Declaration.Type
68 , Ormolu.Printer.Meat.Declaration.TypeFamily
69 , Ormolu.Printer.Meat.Declaration.TypeFamily
src/Ormolu/Printer/Meat/Declaration.hs+3−2
@@ -10,10 +10,11 @@ where
10
10
11import GHC
11import GHC
12import Ormolu.Printer.Combinators
12import Ormolu.Printer.Combinators
13−import Ormolu.Printer.Meat.Declaration.Class
14import Ormolu.Printer.Meat.Common
13import Ormolu.Printer.Meat.Common
14+import Ormolu.Printer.Meat.Declaration.Class
15import Ormolu.Printer.Meat.Declaration.Data
15import Ormolu.Printer.Meat.Declaration.Data
16import Ormolu.Printer.Meat.Declaration.Instance
16import Ormolu.Printer.Meat.Declaration.Instance
17+import Ormolu.Printer.Meat.Declaration.RoleAnnotation
17import Ormolu.Printer.Meat.Declaration.Signature
18import Ormolu.Printer.Meat.Declaration.Signature
18import Ormolu.Printer.Meat.Declaration.Type
19import Ormolu.Printer.Meat.Declaration.Type
19import Ormolu.Printer.Meat.Declaration.TypeFamily
20import Ormolu.Printer.Meat.Declaration.TypeFamily
@@ -35,7 +36,7 @@ p_hsDecl = \case
35 RuleD _ _ -> notImplemented "RuleD"
36 RuleD _ _ -> notImplemented "RuleD"
36 SpliceD _ _ -> notImplemented "SpliceD"
37 SpliceD _ _ -> notImplemented "SpliceD"
37 DocD _ _ -> notImplemented "DocD"
38 DocD _ _ -> notImplemented "DocD"
38− RoleAnnotD _ _ -> notImplemented "RoleAnnotD"
39+ RoleAnnotD NoExt x -> p_roleAnnot x
39 XHsDecl _ -> notImplemented "XHsDecl"
40 XHsDecl _ -> notImplemented "XHsDecl"
40
41
41p_tyClDecl :: TyClDecl GhcPs -> R ()
42p_tyClDecl :: TyClDecl GhcPs -> R ()
src/Ormolu/Printer/Meat/Declaration/RoleAnnotation.hsnew file+41
@@ -0,0 +1,41 @@
1+{-# LANGUAGE LambdaCase #-}
2+{-# LANGUAGE OverloadedStrings #-}
3+{-# LANGUAGE RecordWildCards #-}
4+{-# LANGUAGE TypeFamilies #-}
5+
6+-- | Rendering of Role annotation declarations.
7+
8+module Ormolu.Printer.Meat.Declaration.RoleAnnotation
9+ ( p_roleAnnot
10+ )
11+where
12+
13+import CoAxiom
14+import GHC
15+import Ormolu.Printer.Combinators
16+import Ormolu.Printer.Meat.Common
17+import Ormolu.Utils
18+import RdrName (RdrName (..))
19+import SrcLoc (Located)
20+
21+p_roleAnnot :: RoleAnnotDecl GhcPs -> R ()
22+p_roleAnnot = \case
23+ RoleAnnotDecl NoExt l_name anns -> p_roleAnnot' l_name anns
24+ XRoleAnnotDecl _ -> notImplemented "XRoleAnnotDecl"
25+
26+p_roleAnnot' :: Located RdrName -> [Located (Maybe Role)] -> R ()
27+p_roleAnnot' l_name anns = line $ do
28+ txt "type role"
29+ breakpoint
30+ inci $ do
31+ p_rdrName l_name
32+ breakpoint
33+ let
34+ p_role' = maybe (txt "_") p_role
35+ inci $ velt' $ (located' p_role') <$> anns
36+
37+p_role :: Role -> R ()
38+p_role = \case
39+ Nominal -> txt "nominal"
40+ Representational -> txt "representational"
41+ Phantom -> txt "phantom"