@@ -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"