-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
69 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{-# LANGUAGE RecordWildCards #-} | ||
|
||
module HIndent.Ast.Declaration.Annotation.Role | ||
( RoleAnnotation | ||
, mkRoleAnnotation | ||
) where | ||
|
||
import HIndent.Ast.NodeComments | ||
import HIndent.Ast.Role | ||
import HIndent.Ast.WithComments | ||
import qualified HIndent.GhcLibParserWrapper.GHC.Hs as GHC | ||
import {-# SOURCE #-} HIndent.Pretty | ||
import HIndent.Pretty.Combinators | ||
import HIndent.Pretty.NodeComments | ||
|
||
data RoleAnnotation = RoleAnnotation | ||
{ name :: GHC.LIdP GHC.GhcPs | ||
, roles :: [WithComments (Maybe Role)] | ||
} | ||
|
||
instance CommentExtraction RoleAnnotation where | ||
nodeComments RoleAnnotation {} = NodeComments [] [] [] | ||
|
||
instance Pretty RoleAnnotation where | ||
pretty' RoleAnnotation {..} = | ||
spaced | ||
$ [string "type role", pretty name] | ||
++ fmap (`prettyWith` maybe (string "_") pretty) roles | ||
|
||
mkRoleAnnotation :: GHC.RoleAnnotDecl GHC.GhcPs -> RoleAnnotation | ||
mkRoleAnnotation (GHC.RoleAnnotDecl _ name rs) = RoleAnnotation {..} | ||
where | ||
roles = fmap (fmap (fmap mkRole) . fromGenLocated) rs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module HIndent.Ast.Role | ||
( Role | ||
, mkRole | ||
) where | ||
|
||
import qualified GHC.Core.TyCon as GHC | ||
import HIndent.Ast.NodeComments | ||
import {-# SOURCE #-} HIndent.Pretty | ||
import HIndent.Pretty.Combinators | ||
import HIndent.Pretty.NodeComments | ||
|
||
data Role | ||
= Nominal | ||
| Representational | ||
| Phantom | ||
|
||
instance CommentExtraction Role where | ||
nodeComments Nominal = NodeComments [] [] [] | ||
nodeComments Representational = NodeComments [] [] [] | ||
nodeComments Phantom = NodeComments [] [] [] | ||
|
||
instance Pretty Role where | ||
pretty' Nominal = string "nominal" | ||
pretty' Representational = string "representational" | ||
pretty' Phantom = string "phantom" | ||
|
||
mkRole :: GHC.Role -> Role | ||
mkRole GHC.Nominal = Nominal | ||
mkRole GHC.Representational = Representational | ||
mkRole GHC.Phantom = Phantom |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters