diff --git a/hie.yaml b/hie.yaml new file mode 100644 index 000000000..df85cdd99 --- /dev/null +++ b/hie.yaml @@ -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" diff --git a/hindent.cabal b/hindent.cabal index 09d6b009a..e89aeeaf6 100644 --- a/hindent.cabal +++ b/hindent.cabal @@ -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 diff --git a/src/HIndent/Ast/Declaration.hs b/src/HIndent/Ast/Declaration.hs index cad8635aa..77c7ea34f 100644 --- a/src/HIndent/Ast/Declaration.hs +++ b/src/HIndent/Ast/Declaration.hs @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/src/HIndent/Ast/Declaration/Splice.hs b/src/HIndent/Ast/Declaration/Splice.hs new file mode 100644 index 000000000..e29c6ed65 --- /dev/null +++ b/src/HIndent/Ast/Declaration/Splice.hs @@ -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 diff --git a/src/HIndent/Pretty.hs b/src/HIndent/Pretty.hs index f5b5d37c6..cbe9a517b 100644 --- a/src/HIndent/Pretty.hs +++ b/src/HIndent/Pretty.hs @@ -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 diff --git a/src/HIndent/Pretty.hs-boot b/src/HIndent/Pretty.hs-boot index 5cb1005ea..6b54b7556 100644 --- a/src/HIndent/Pretty.hs-boot +++ b/src/HIndent/Pretty.hs-boot @@ -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) @@ -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