Skip to content

Commit

Permalink
Implement StandaloneKind (#870)
Browse files Browse the repository at this point in the history
  • Loading branch information
toku-sa-n authored Apr 11, 2024
1 parent 3cccdb9 commit 70c90bd
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
1 change: 1 addition & 0 deletions hindent.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ library
HIndent.Ast.Declaration.Signature.Fixity.Associativity
HIndent.Ast.Declaration.Signature.Inline.Phase
HIndent.Ast.Declaration.Signature.Inline.Spec
HIndent.Ast.Declaration.Signature.StandaloneKind
HIndent.Ast.Declaration.StandAloneDeriving
HIndent.Ast.Declaration.TypeSynonym
HIndent.Ast.Declaration.TypeSynonym.Lhs
Expand Down
9 changes: 5 additions & 4 deletions src/HIndent/Ast/Declaration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import HIndent.Ast.Declaration.Instance.Class
import HIndent.Ast.Declaration.Instance.Family.Data
import HIndent.Ast.Declaration.Instance.Family.Type
import HIndent.Ast.Declaration.Signature
import HIndent.Ast.Declaration.Signature.StandaloneKind
import HIndent.Ast.Declaration.StandAloneDeriving
import HIndent.Ast.Declaration.TypeSynonym
import HIndent.Ast.NodeComments
Expand All @@ -36,7 +37,7 @@ data Declaration
| StandAloneDeriving StandAloneDeriving
| Bind Bind
| Signature Signature
| KindSigDecl (GHC.StandaloneKindSig GHC.GhcPs)
| StandaloneKindSignature StandaloneKind
| DefDecl (GHC.DefaultDecl GHC.GhcPs)
| ForDecl (GHC.ForeignDecl GHC.GhcPs)
| WarningDecl (GHC.WarnDecls GHC.GhcPs)
Expand All @@ -57,7 +58,7 @@ instance CommentExtraction Declaration where
nodeComments StandAloneDeriving {} = NodeComments [] [] []
nodeComments Bind {} = NodeComments [] [] []
nodeComments Signature {} = NodeComments [] [] []
nodeComments KindSigDecl {} = NodeComments [] [] []
nodeComments StandaloneKindSignature {} = NodeComments [] [] []
nodeComments DefDecl {} = NodeComments [] [] []
nodeComments ForDecl {} = NodeComments [] [] []
nodeComments WarningDecl {} = NodeComments [] [] []
Expand All @@ -78,7 +79,7 @@ instance Pretty Declaration where
pretty' (StandAloneDeriving x) = pretty x
pretty' (Bind x) = pretty x
pretty' (Signature x) = pretty x
pretty' (KindSigDecl x) = pretty x
pretty' (StandaloneKindSignature x) = pretty x
pretty' (DefDecl x) = pretty x
pretty' (ForDecl x) = pretty x
pretty' (WarningDecl x) = pretty x
Expand All @@ -105,7 +106,7 @@ mkDeclaration (GHC.InstD _ [email protected] {}) =
mkDeclaration (GHC.DerivD _ x) = StandAloneDeriving $ mkStandAloneDeriving x
mkDeclaration (GHC.ValD _ x) = Bind $ mkBind x
mkDeclaration (GHC.SigD _ x) = Signature $ mkSignature x
mkDeclaration (GHC.KindSigD _ x) = KindSigDecl x
mkDeclaration (GHC.KindSigD _ x) = StandaloneKindSignature $ mkStandaloneKind x
mkDeclaration (GHC.DefD _ x) = DefDecl x
mkDeclaration (GHC.ForD _ x) = ForDecl x
mkDeclaration (GHC.WarningD _ x) = WarningDecl x
Expand Down
27 changes: 27 additions & 0 deletions src/HIndent/Ast/Declaration/Signature/StandaloneKind.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{-# LANGUAGE RecordWildCards #-}

module HIndent.Ast.Declaration.Signature.StandaloneKind
( StandaloneKind
, mkStandaloneKind
) where

import qualified GHC.Hs as GHC
import HIndent.Ast.NodeComments
import {-# SOURCE #-} HIndent.Pretty
import HIndent.Pretty.Combinators
import HIndent.Pretty.NodeComments

data StandaloneKind = StandaloneKind
{ name :: GHC.LIdP GHC.GhcPs
, kind :: GHC.LHsSigType GHC.GhcPs
}

instance CommentExtraction StandaloneKind where
nodeComments StandaloneKind {} = NodeComments [] [] []

instance Pretty StandaloneKind where
pretty' StandaloneKind {..} =
spaced [string "type", pretty name, string "::", pretty kind]

mkStandaloneKind :: GHC.StandaloneKindSig GHC.GhcPs -> StandaloneKind
mkStandaloneKind (GHC.StandaloneKindSig _ name kind) = StandaloneKind {..}
4 changes: 0 additions & 4 deletions src/HIndent/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1545,10 +1545,6 @@ instance Pretty
(GHC.GenLocated GHC.SrcSpanAnnA (GHC.HsType GHC.GhcPs))) where
pretty' GHC.HsWC {..} = pretty hswc_body

instance Pretty (GHC.StandaloneKindSig GHC.GhcPs) where
pretty' (GHC.StandaloneKindSig _ name kind) =
spaced [string "type", pretty name, string "::", pretty kind]

instance Pretty (GHC.DefaultDecl GHC.GhcPs) where
pretty' (GHC.DefaultDecl _ xs) =
spaced [string "default", hTuple $ fmap pretty xs]
Expand Down
2 changes: 0 additions & 2 deletions src/HIndent/Pretty.hs-boot
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ instance Pretty (GHC.HsPatSynDir GHC.GhcPs)

instance Pretty PatInsidePatDecl

instance Pretty (GHC.StandaloneKindSig GHC.GhcPs)

instance Pretty (GHC.DefaultDecl GHc.GhcPs)

instance Pretty (GHC.ForeignDecl GHC.GhcPs)
Expand Down

0 comments on commit 70c90bd

Please sign in to comment.