on master help sign in
Support rendering of role annotation declarations
commita325cd6cdf4c2fc6e70ad0f23df233bb162476da authorPanAeon <vitalii.voloshyn@gmail.com> dateFri 14 Jun 2019, 16:36 (7 years ago) parent5570439
5 files changed+96−3
data/examples/declaration/role-annotation/simple-out.hs+25 data/examples/declaration/role-annotation/simple.hs+25 ormolu.cabal+2−1 src/Ormolu/Printer/Meat/Declaration.hs+3−2 src/Ormolu/Printer/Meat/Declaration/RoleAnnotation.hs+41
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
6161 , Ormolu.Printer.Meat.Common
6262 , Ormolu.Printer.Meat.Declaration
6363 , Ormolu.Printer.Meat.Declaration.Class
64− , Ormolu.Printer.Meat.Declaration.Instance
6564 , Ormolu.Printer.Meat.Declaration.Data
65+ , Ormolu.Printer.Meat.Declaration.Instance
66+ , Ormolu.Printer.Meat.Declaration.RoleAnnotation
6667 , Ormolu.Printer.Meat.Declaration.Signature
6768 , Ormolu.Printer.Meat.Declaration.Type
6869 , Ormolu.Printer.Meat.Declaration.TypeFamily
src/Ormolu/Printer/Meat/Declaration.hs+3−2
@@ -10,10 +10,11 @@ where
1010
1111import GHC
1212import Ormolu.Printer.Combinators
13−import Ormolu.Printer.Meat.Declaration.Class
1413import Ormolu.Printer.Meat.Common
14+import Ormolu.Printer.Meat.Declaration.Class
1515import Ormolu.Printer.Meat.Declaration.Data
1616import Ormolu.Printer.Meat.Declaration.Instance
17+import Ormolu.Printer.Meat.Declaration.RoleAnnotation
1718import Ormolu.Printer.Meat.Declaration.Signature
1819import Ormolu.Printer.Meat.Declaration.Type
1920import Ormolu.Printer.Meat.Declaration.TypeFamily
@@ -35,7 +36,7 @@ p_hsDecl = \case
3536 RuleD _ _ -> notImplemented "RuleD"
3637 SpliceD _ _ -> notImplemented "SpliceD"
3738 DocD _ _ -> notImplemented "DocD"
38− RoleAnnotD _ _ -> notImplemented "RoleAnnotD"
39+ RoleAnnotD NoExt x -> p_roleAnnot x
3940 XHsDecl _ -> notImplemented "XHsDecl"
4041
4142p_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"