Skip to content

Commit

Permalink
Implement SpliceDeclaration (#892)
Browse files Browse the repository at this point in the history
  • Loading branch information
toku-sa-n authored May 14, 2024
1 parent 4c678b6 commit 9cbf254
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 9 deletions.
19 changes: 19 additions & 0 deletions hie.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cradle:
stack:
- path: "././"
component: "hindent:bench:S.md"

- path: "./src"
component: "hindent:lib"

- path: "./internal"
component: "hindent:lib:hindent-internal"

- path: "./app/Main.hs"
component: "hindent:exe:hindent"

- path: "./tests"
component: "hindent:test:hindent-test"

- path: "./benchmarks/Main.hs"
component: "hindent:bench:hindent-bench"
1 change: 1 addition & 0 deletions hindent.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ library
HIndent.Ast.Declaration.Signature.Inline.Phase
HIndent.Ast.Declaration.Signature.Inline.Spec
HIndent.Ast.Declaration.Signature.StandaloneKind
HIndent.Ast.Declaration.Splice
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 @@ -22,6 +22,7 @@ import HIndent.Ast.Declaration.Instance.Family.Type
import HIndent.Ast.Declaration.Rule.Collection
import HIndent.Ast.Declaration.Signature
import HIndent.Ast.Declaration.Signature.StandaloneKind
import HIndent.Ast.Declaration.Splice
import HIndent.Ast.Declaration.StandAloneDeriving
import HIndent.Ast.Declaration.TypeSynonym
import HIndent.Ast.Declaration.Warning.Collection
Expand All @@ -48,7 +49,7 @@ data Declaration
| Warnings WarningCollection
| Annotation Annotation
| RuleDecl RuleCollection
| SpliceDecl (GHC.SpliceDecl GHC.GhcPs)
| Splice SpliceDeclaration
| RoleAnnotDecl (GHC.RoleAnnotDecl GHC.GhcPs)

instance CommentExtraction Declaration where
Expand All @@ -69,7 +70,7 @@ instance CommentExtraction Declaration where
nodeComments Warnings {} = NodeComments [] [] []
nodeComments Annotation {} = NodeComments [] [] []
nodeComments RuleDecl {} = NodeComments [] [] []
nodeComments SpliceDecl {} = NodeComments [] [] []
nodeComments Splice {} = NodeComments [] [] []
nodeComments RoleAnnotDecl {} = NodeComments [] [] []

instance Pretty Declaration where
Expand All @@ -90,7 +91,7 @@ instance Pretty Declaration where
pretty' (Warnings x) = pretty x
pretty' (Annotation x) = pretty x
pretty' (RuleDecl x) = pretty x
pretty' (SpliceDecl x) = pretty x
pretty' (Splice x) = pretty x
pretty' (RoleAnnotDecl x) = pretty x

mkDeclaration :: GHC.HsDecl GHC.GhcPs -> Declaration
Expand All @@ -117,7 +118,7 @@ mkDeclaration (GHC.ForD _ x) = Foreign $ mkForeignDeclaration x
mkDeclaration (GHC.WarningD _ x) = Warnings $ mkWarningCollection x
mkDeclaration (GHC.AnnD _ x) = Annotation $ mkAnnotation x
mkDeclaration (GHC.RuleD _ x) = RuleDecl $ mkRuleCollection x
mkDeclaration (GHC.SpliceD _ x) = SpliceDecl x
mkDeclaration (GHC.SpliceD _ x) = Splice $ mkSpliceDeclaration x
mkDeclaration (GHC.RoleAnnotD _ x) = RoleAnnotDecl x
mkDeclaration GHC.DocD {} =
error
Expand Down
21 changes: 21 additions & 0 deletions src/HIndent/Ast/Declaration/Splice.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module HIndent.Ast.Declaration.Splice
( SpliceDeclaration
, mkSpliceDeclaration
) where

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

newtype SpliceDeclaration =
SpliceDeclaration (GHC.SpliceDecl GHC.GhcPs)

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

instance Pretty SpliceDeclaration where
pretty' (SpliceDeclaration (GHC.SpliceDecl _ sp _)) = pretty sp

mkSpliceDeclaration :: GHC.SpliceDecl GHC.GhcPs -> SpliceDeclaration
mkSpliceDeclaration = SpliceDeclaration
3 changes: 0 additions & 3 deletions src/HIndent/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -939,9 +939,6 @@ instance Pretty GHC.EpaCommentTok where
-- contains indent spaces for all lines except the first one.
indentedWithFixedLevel 0 $ lined $ fmap string xs
pretty' _ = docNode

instance Pretty (GHC.SpliceDecl GHC.GhcPs) where
pretty' (GHC.SpliceDecl _ sp _) = pretty sp
#if !MIN_VERSION_ghc_lib_parser(9,6,1)
instance Pretty (GHC.HsSplice GHC.GhcPs) where
pretty' (GHC.HsTypedSplice _ _ _ body) = string "$$" >> pretty body
Expand Down
7 changes: 5 additions & 2 deletions src/HIndent/Pretty.hs-boot
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ instance Pretty PatInsidePatDecl

instance Pretty GHC.StringLiteral

instance Pretty (GHC.SpliceDecl GHC.GhcPs)

instance Pretty (GHC.RoleAnnotDecl GHC.GhcPs)

instance Pretty (GHC.HsSigType GHC.GhcPs)
Expand All @@ -104,3 +102,8 @@ instance Pretty
(GHC.GenLocated GHC.SrcSpanAnnA (GHC.HsType GHC.GhcPs)))
#endif
instance Pretty (GHC.HsExpr GHC.GhcPs)
#if MIN_VERSION_ghc_lib_parser(9, 6, 1)
instance Pretty (GHC.HsUntypedSplice GHC.GhcPs)
#else
instance Pretty (GHC.HsSplice GHC.GhcPs)
#endif

0 comments on commit 9cbf254

Please sign in to comment.