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:
parent
5570439bb4
commit
a325cd6cdf
25
data/examples/declaration/role-annotation/simple-out.hs
Normal file
25
data/examples/declaration/role-annotation/simple-out.hs
Normal 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
|
25
data/examples/declaration/role-annotation/simple.hs
Normal file
25
data/examples/declaration/role-annotation/simple.hs
Normal 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
|
@ -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
|
||||
|
@ -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 ()
|
||||
|
41
src/Ormolu/Printer/Meat/Declaration/RoleAnnotation.hs
Normal file
41
src/Ormolu/Printer/Meat/Declaration/RoleAnnotation.hs
Normal 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"
|
Loading…
Reference in New Issue
Block a user