1
1
mirror of https://github.com/google/ormolu.git synced 2025-01-05 22:16:03 +03:00

Support rendering of role annotation declarations

This commit is contained in:
PanAeon 2019-06-14 16:36:38 +01:00 committed by Mark Karpov
parent 5570439bb4
commit a325cd6cdf
5 changed files with 96 additions and 3 deletions

View File

@ -0,0 +1,25 @@
{-# LANGUAGE RoleAnnotations #-}
{-# LANGUAGE MagicHash #-}
type role Ptr representational
type role A nominal nominal
type role B _ phantom
type role C _ _
type role
D
phantom
nominal
type role
E
_
nominal
type role
E
_
nominal
phantom

View File

@ -0,0 +1,25 @@
{-# LANGUAGE RoleAnnotations #-}
{-# LANGUAGE MagicHash #-}
type role Ptr representational
type role A nominal nominal
type role B _ phantom
type role C _ _
type role
D phantom nominal
type
role
E
_
nominal
type
role
E
_
nominal
phantom

View File

@ -61,8 +61,9 @@ library
, Ormolu.Printer.Meat.Common
, Ormolu.Printer.Meat.Declaration
, Ormolu.Printer.Meat.Declaration.Class
, Ormolu.Printer.Meat.Declaration.Instance
, Ormolu.Printer.Meat.Declaration.Data
, Ormolu.Printer.Meat.Declaration.Instance
, Ormolu.Printer.Meat.Declaration.RoleAnnotation
, Ormolu.Printer.Meat.Declaration.Signature
, Ormolu.Printer.Meat.Declaration.Type
, Ormolu.Printer.Meat.Declaration.TypeFamily

View File

@ -10,10 +10,11 @@ where
import GHC
import Ormolu.Printer.Combinators
import Ormolu.Printer.Meat.Declaration.Class
import Ormolu.Printer.Meat.Common
import Ormolu.Printer.Meat.Declaration.Class
import Ormolu.Printer.Meat.Declaration.Data
import Ormolu.Printer.Meat.Declaration.Instance
import Ormolu.Printer.Meat.Declaration.RoleAnnotation
import Ormolu.Printer.Meat.Declaration.Signature
import Ormolu.Printer.Meat.Declaration.Type
import Ormolu.Printer.Meat.Declaration.TypeFamily
@ -35,7 +36,7 @@ p_hsDecl = \case
RuleD _ _ -> notImplemented "RuleD"
SpliceD _ _ -> notImplemented "SpliceD"
DocD _ _ -> notImplemented "DocD"
RoleAnnotD _ _ -> notImplemented "RoleAnnotD"
RoleAnnotD NoExt x -> p_roleAnnot x
XHsDecl _ -> notImplemented "XHsDecl"
p_tyClDecl :: TyClDecl GhcPs -> R ()

View File

@ -0,0 +1,41 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeFamilies #-}
-- | Rendering of Role annotation declarations.
module Ormolu.Printer.Meat.Declaration.RoleAnnotation
( p_roleAnnot
)
where
import CoAxiom
import GHC
import Ormolu.Printer.Combinators
import Ormolu.Printer.Meat.Common
import Ormolu.Utils
import RdrName (RdrName (..))
import SrcLoc (Located)
p_roleAnnot :: RoleAnnotDecl GhcPs -> R ()
p_roleAnnot = \case
RoleAnnotDecl NoExt l_name anns -> p_roleAnnot' l_name anns
XRoleAnnotDecl _ -> notImplemented "XRoleAnnotDecl"
p_roleAnnot' :: Located RdrName -> [Located (Maybe Role)] -> R ()
p_roleAnnot' l_name anns = line $ do
txt "type role"
breakpoint
inci $ do
p_rdrName l_name
breakpoint
let
p_role' = maybe (txt "_") p_role
inci $ velt' $ (located' p_role') <$> anns
p_role :: Role -> R ()
p_role = \case
Nominal -> txt "nominal"
Representational -> txt "representational"
Phantom -> txt "phantom"