From 4fd36d81b5fc9a50c2c4e1e2a6598eb2d1d512b1 Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 02:23:25 +0900 Subject: [PATCH 01/40] Remove an unused instance --- src/HIndent/Pretty/NodeComments.hs | 51 +----------------------------- 1 file changed, 1 insertion(+), 50 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index 77478d39c..1ffa04bb5 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -22,7 +22,6 @@ import GHC.Types.Name.Reader import GHC.Types.SourceText import GHC.Types.SrcLoc import HIndent.Ast.NodeComments -import HIndent.Pragma import HIndent.Pretty.SigBindFamily import HIndent.Pretty.Types #if MIN_VERSION_ghc_lib_parser(9, 6, 1) @@ -33,55 +32,7 @@ import GHC.Unit -- | An interface to extract comments from an AST node. class CommentExtraction a where nodeComments :: a -> NodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -instance CommentExtraction (HsModule GhcPs) where - nodeComments = - nodeComments . filterOutEofAndPragmasFromAnn . hsmodAnn . hsmodExt - where - filterOutEofAndPragmasFromAnn EpAnn {..} = - EpAnn {comments = filterOutEofAndPragmasFromComments comments, ..} - filterOutEofAndPragmasFromComments comments = - EpaCommentsBalanced - { priorComments = filterOutEofAndPragmas $ priorComments comments - , followingComments = - filterOutEofAndPragmas $ getFollowingComments comments - } - filterOutEofAndPragmas = filter isNeitherEofNorPragmaComment - isNeitherEofNorPragmaComment (L _ (EpaComment tok _)) = not $ isPragma tok -#elif MIN_VERSION_ghc_lib_parser(9, 6, 1) -instance CommentExtraction (HsModule GhcPs) where - nodeComments = - nodeComments . filterOutEofAndPragmasFromAnn . hsmodAnn . hsmodExt - where - filterOutEofAndPragmasFromAnn EpAnn {..} = - EpAnn {comments = filterOutEofAndPragmasFromComments comments, ..} - filterOutEofAndPragmasFromAnn EpAnnNotUsed = EpAnnNotUsed - filterOutEofAndPragmasFromComments comments = - EpaCommentsBalanced - { priorComments = filterOutEofAndPragmas $ priorComments comments - , followingComments = - filterOutEofAndPragmas $ getFollowingComments comments - } - filterOutEofAndPragmas = filter isNeitherEofNorPragmaComment - isNeitherEofNorPragmaComment (L _ (EpaComment EpaEofComment _)) = False - isNeitherEofNorPragmaComment (L _ (EpaComment tok _)) = not $ isPragma tok -#else -instance CommentExtraction HsModule where - nodeComments = nodeComments . filterOutEofAndPragmasFromAnn . hsmodAnn - where - filterOutEofAndPragmasFromAnn EpAnn {..} = - EpAnn {comments = filterOutEofAndPragmasFromComments comments, ..} - filterOutEofAndPragmasFromAnn EpAnnNotUsed = EpAnnNotUsed - filterOutEofAndPragmasFromComments comments = - EpaCommentsBalanced - { priorComments = filterOutEofAndPragmas $ priorComments comments - , followingComments = - filterOutEofAndPragmas $ getFollowingComments comments - } - filterOutEofAndPragmas = filter isNeitherEofNorPragmaComment - isNeitherEofNorPragmaComment (L _ (EpaComment EpaEofComment _)) = False - isNeitherEofNorPragmaComment (L _ (EpaComment tok _)) = not $ isPragma tok -#endif + instance CommentExtraction l => CommentExtraction (GenLocated l e) where nodeComments (L l _) = nodeComments l From 5958d473c59c88faba012d493e55419b88a1485e Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 12:07:05 +0900 Subject: [PATCH 02/40] wip --- src/HIndent/Pretty/NodeComments.hs | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index 1ffa04bb5..7071c9d4a 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -35,23 +35,6 @@ class CommentExtraction a where instance CommentExtraction l => CommentExtraction (GenLocated l e) where nodeComments (L l _) = nodeComments l - -instance CommentExtraction (HsDecl GhcPs) where - nodeComments TyClD {} = emptyNodeComments - nodeComments InstD {} = emptyNodeComments - nodeComments DerivD {} = emptyNodeComments - nodeComments ValD {} = emptyNodeComments - nodeComments SigD {} = emptyNodeComments - nodeComments KindSigD {} = emptyNodeComments - nodeComments DefD {} = emptyNodeComments - nodeComments ForD {} = emptyNodeComments - nodeComments WarningD {} = emptyNodeComments - nodeComments AnnD {} = emptyNodeComments - nodeComments RuleD {} = emptyNodeComments - nodeComments SpliceD {} = emptyNodeComments - nodeComments DocD {} = - error "Document comments should be treated as normal ones." - nodeComments RoleAnnotD {} = emptyNodeComments #if MIN_VERSION_ghc_lib_parser(9, 10, 0) instance CommentExtraction (TyClDecl GhcPs) where nodeComments FamDecl {} = emptyNodeComments From f3ef6dccd28e2d575a6daaf5b1cacb773ff7290d Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 12:15:22 +0900 Subject: [PATCH 03/40] wip --- src/HIndent/Pretty/NodeComments.hs | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index 7071c9d4a..da391fdd1 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -35,36 +35,6 @@ class CommentExtraction a where instance CommentExtraction l => CommentExtraction (GenLocated l e) where nodeComments (L l _) = nodeComments l -#if MIN_VERSION_ghc_lib_parser(9, 10, 0) -instance CommentExtraction (TyClDecl GhcPs) where - nodeComments FamDecl {} = emptyNodeComments - nodeComments SynDecl {..} = mconcat $ fmap nodeComments tcdSExt - nodeComments DataDecl {..} = mconcat $ fmap nodeComments tcdDExt - nodeComments ClassDecl {tcdCExt = (x, _, _)} = mconcat $ fmap nodeComments x -#elif MIN_VERSION_ghc_lib_parser(9, 6, 0) -instance CommentExtraction (TyClDecl GhcPs) where - nodeComments FamDecl {} = emptyNodeComments - nodeComments SynDecl {..} = nodeComments tcdSExt - nodeComments DataDecl {..} = nodeComments tcdDExt - nodeComments ClassDecl {tcdCExt = (x, _)} = nodeComments x -#else -instance CommentExtraction (TyClDecl GhcPs) where - nodeComments FamDecl {} = emptyNodeComments - nodeComments SynDecl {..} = nodeComments tcdSExt - nodeComments DataDecl {..} = nodeComments tcdDExt - nodeComments ClassDecl {tcdCExt = (x, _, _)} = nodeComments x -#endif -instance CommentExtraction (InstDecl GhcPs) where - nodeComments = nodeCommentsInstDecl - -nodeCommentsInstDecl :: InstDecl GhcPs -> NodeComments -nodeCommentsInstDecl ClsInstD {} = emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9,4,1) -nodeCommentsInstDecl DataFamInstD {} = emptyNodeComments -#else -nodeCommentsInstDecl DataFamInstD {..} = nodeComments dfid_ext -#endif -nodeCommentsInstDecl TyFamInstD {} = emptyNodeComments instance CommentExtraction (HsBind GhcPs) where nodeComments = nodeCommentsHsBind From 2e85b654c4ca6c04e1070e2a2ae60eb2d20ba7ea Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 13:20:52 +0900 Subject: [PATCH 04/40] wip --- src/HIndent/Pretty/NodeComments.hs | 64 ++++++++++++++---------------- 1 file changed, 29 insertions(+), 35 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index da391fdd1..cf8dbcf14 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -51,43 +51,37 @@ nodeCommentsHsBind VarBind {} = emptyNodeComments nodeCommentsHsBind AbsBinds {} = emptyNodeComments #endif nodeCommentsHsBind PatSynBind {} = emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 0) + instance CommentExtraction (Sig GhcPs) where - nodeComments (TypeSig x _ _) = nodeComments x - nodeComments (PatSynSig x _ _) = nodeComments x - nodeComments (ClassOpSig x _ _ _) = nodeComments x - nodeComments (FixSig x _) = mconcat $ fmap nodeComments x - nodeComments (InlineSig x _ _) = mconcat $ fmap nodeComments x - nodeComments (SpecSig x _ _ _) = mconcat $ fmap nodeComments x - nodeComments (SpecInstSig x _) = mconcat $ fmap nodeComments $ fst x - nodeComments (MinimalSig x _) = mconcat $ fmap nodeComments $ fst x - nodeComments (SCCFunSig x _ _) = mconcat $ fmap nodeComments $ fst x - nodeComments (CompleteMatchSig x _ _) = mconcat $ fmap nodeComments $ fst x + nodeComments = nodeCommentsSig + +nodeCommentsSig :: Sig GhcPs -> NodeComments +nodeCommentsSig (TypeSig x _ _) = nodeComments x +nodeCommentsSig (PatSynSig x _ _) = nodeComments x +nodeCommentsSig (ClassOpSig x _ _ _) = nodeComments x +nodeCommentsSig (FixSig x _) = nodeComments x +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsSig (InlineSig x _ _) = mconcat $ nodeComments x +nodeCommentsSig (SpecSig x _ _ _) = mconcat $ nodeComments x +nodeCommentsSig (SpecInstSig x _ _) = mconcat $ nodeComments x +nodeCommentsSig (MinimalSig x _ _) = mconcat $ nodeComments x +nodeCommentsSig (SCCFunSig x _ _ _) = mconcat $ nodeComments x +nodeCommentsSig (CompleteMatchSig x _ _ _) = mconcat $ nodeComments x #elif MIN_VERSION_ghc_lib_parser(9, 6, 1) -instance CommentExtraction (Sig GhcPs) where - nodeComments (TypeSig x _ _) = nodeComments x - nodeComments (PatSynSig x _ _) = nodeComments x - nodeComments (ClassOpSig x _ _ _) = nodeComments x - nodeComments (FixSig x _) = nodeComments x - nodeComments (InlineSig x _ _) = nodeComments x - nodeComments (SpecSig x _ _ _) = nodeComments x - nodeComments (SpecInstSig x _) = nodeComments $ fst x - nodeComments (MinimalSig x _) = nodeComments $ fst x - nodeComments (SCCFunSig x _ _) = nodeComments $ fst x - nodeComments (CompleteMatchSig x _ _) = nodeComments $ fst x -#else -instance CommentExtraction (Sig GhcPs) where - nodeComments (TypeSig x _ _) = nodeComments x - nodeComments (PatSynSig x _ _) = nodeComments x - nodeComments (ClassOpSig x _ _ _) = nodeComments x - nodeComments IdSig {} = emptyNodeComments - nodeComments (FixSig x _) = nodeComments x - nodeComments (InlineSig x _ _) = nodeComments x - nodeComments (SpecSig x _ _ _) = nodeComments x - nodeComments (SpecInstSig x _ _) = nodeComments x - nodeComments (MinimalSig x _ _) = nodeComments x - nodeComments (SCCFunSig x _ _ _) = nodeComments x - nodeComments (CompleteMatchSig x _ _ _) = nodeComments x +nodeCommentsSig (InlineSig x _ _) = nodeComments x +nodeCommentsSig (SpecSig x _ _ _) = nodeComments x +nodeCommentsSig (SpecInstSig (x, _) _) = nodeComments x +nodeCommentsSig (MinimalSig (x, _) _) = nodeComments x +nodeCommentsSig (SCCFunSig (x, _) _ _) = nodeComments x +nodeCommentsSig (CompleteMatchSig (x, _) _ _) = nodeComments x +#else +nodeCommentsSig (InlineSig x _ _) = nodeComments x +nodeCommentsSig (SpecSig x _ _ _) = nodeComments x +nodeCommentsSig IdSig {} = emptyNodeComments +nodeCommentsSig (SpecInstSig x _ _) = nodeComments x +nodeCommentsSig (MinimalSig x _ _) = nodeComments x +nodeCommentsSig (SCCFunSig x _ _ _) = nodeComments x +nodeCommentsSig (CompleteMatchSig x _ _ _) = nodeComments x #endif instance CommentExtraction (HsDataDefn GhcPs) where nodeComments HsDataDefn {} = emptyNodeComments From a66fbe5c35fec3ca477ff0e7dfabe0a9bb2aafe0 Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 13:34:30 +0900 Subject: [PATCH 05/40] wip --- src/HIndent/Pretty/NodeComments.hs | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index cf8dbcf14..864e9ef84 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -59,15 +59,16 @@ nodeCommentsSig :: Sig GhcPs -> NodeComments nodeCommentsSig (TypeSig x _ _) = nodeComments x nodeCommentsSig (PatSynSig x _ _) = nodeComments x nodeCommentsSig (ClassOpSig x _ _ _) = nodeComments x -nodeCommentsSig (FixSig x _) = nodeComments x #if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsSig (InlineSig x _ _) = mconcat $ nodeComments x -nodeCommentsSig (SpecSig x _ _ _) = mconcat $ nodeComments x -nodeCommentsSig (SpecInstSig x _ _) = mconcat $ nodeComments x -nodeCommentsSig (MinimalSig x _ _) = mconcat $ nodeComments x -nodeCommentsSig (SCCFunSig x _ _ _) = mconcat $ nodeComments x -nodeCommentsSig (CompleteMatchSig x _ _ _) = mconcat $ nodeComments x +nodeCommentsSig (FixSig x _) = mconcat $ fmap nodeComments x +nodeCommentsSig (InlineSig x _ _) = mconcat $ fmap nodeComments x +nodeCommentsSig (SpecSig x _ _ _) = mconcat $ fmap nodeComments x +nodeCommentsSig (SpecInstSig (x, _) _) = mconcat $ fmap nodeComments x +nodeCommentsSig (MinimalSig (x, _) _) = mconcat $ fmap nodeComments x +nodeCommentsSig (SCCFunSig (x, _) _ _) = mconcat $ fmap nodeComments x +nodeCommentsSig (CompleteMatchSig (x, _) _ _) = mconcat $ fmap nodeComments x #elif MIN_VERSION_ghc_lib_parser(9, 6, 1) +nodeCommentsSig (FixSig x _) = nodeComments x nodeCommentsSig (InlineSig x _ _) = nodeComments x nodeCommentsSig (SpecSig x _ _ _) = nodeComments x nodeCommentsSig (SpecInstSig (x, _) _) = nodeComments x @@ -75,6 +76,7 @@ nodeCommentsSig (MinimalSig (x, _) _) = nodeComments x nodeCommentsSig (SCCFunSig (x, _) _ _) = nodeComments x nodeCommentsSig (CompleteMatchSig (x, _) _ _) = nodeComments x #else +nodeCommentsSig (FixSig x _) = nodeComments x nodeCommentsSig (InlineSig x _ _) = nodeComments x nodeCommentsSig (SpecSig x _ _ _) = nodeComments x nodeCommentsSig IdSig {} = emptyNodeComments @@ -85,14 +87,7 @@ nodeCommentsSig (CompleteMatchSig x _ _ _) = nodeComments x #endif instance CommentExtraction (HsDataDefn GhcPs) where nodeComments HsDataDefn {} = emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 0) -instance CommentExtraction (ClsInstDecl GhcPs) where - nodeComments ClsInstDecl {cid_ext = (x, _, _)} = - fromMaybe mempty $ fmap nodeComments x -#else -instance CommentExtraction (ClsInstDecl GhcPs) where - nodeComments ClsInstDecl {cid_ext = (x, _)} = nodeComments x -#endif + instance CommentExtraction (MatchGroup GhcPs a) where nodeComments MG {} = emptyNodeComments From 63bae2d153ae0afbcf6e6a78eb753c000d49c621 Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 13:51:52 +0900 Subject: [PATCH 06/40] wip --- src/HIndent/Pretty/NodeComments.hs | 124 ++++++++++------------------- 1 file changed, 40 insertions(+), 84 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index 864e9ef84..a73cf09d2 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -160,103 +160,32 @@ nodeCommentsHsExpr (NegApp x _ _) = mconcat $ fmap nodeComments x #else nodeCommentsHsExpr (NegApp x _ _) = nodeComments x #endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsExpr HsPar {} = emptyNodeComments -#elif MIN_VERSION_ghc_lib_parser(9, 4, 1) -nodeCommentsHsExpr (HsPar x _ _ _) = nodeComments x -#else -nodeCommentsHsExpr (HsPar x _) = nodeComments x -#endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsExpr SectionL {} = emptyNodeComments -#else -nodeCommentsHsExpr (SectionL x _ _) = nodeComments x -#endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsExpr SectionR {} = emptyNodeComments -#else -nodeCommentsHsExpr (SectionR x _ _) = nodeComments x -#endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsExpr (ExplicitTuple x _ _) = mconcat $ fmap nodeComments x -#else -nodeCommentsHsExpr (ExplicitTuple x _ _) = nodeComments x -#endif nodeCommentsHsExpr (ExplicitSum x _ _ _) = nodeComments x nodeCommentsHsExpr (HsCase x _ _) = nodeComments x nodeCommentsHsExpr (HsIf x _ _ _) = nodeComments x -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsExpr (HsMultiIf x _) = mconcat $ fmap nodeComments x -#else -nodeCommentsHsExpr (HsMultiIf x _) = nodeComments x -#endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsExpr HsLet {} = emptyNodeComments -#elif MIN_VERSION_ghc_lib_parser(9, 4, 1) -nodeCommentsHsExpr (HsLet x _ _ _ _) = nodeComments x -#else -nodeCommentsHsExpr (HsLet x _ _) = nodeComments x -#endif nodeCommentsHsExpr (HsDo x _ _) = nodeComments x nodeCommentsHsExpr (ExplicitList x _) = nodeComments x -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsExpr RecordCon {..} = mconcat $ fmap nodeComments rcon_ext -#else -nodeCommentsHsExpr RecordCon {..} = nodeComments rcon_ext -#endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsExpr RecordUpd {..} = mconcat $ fmap nodeComments rupd_ext -#else -nodeCommentsHsExpr RecordUpd {..} = nodeComments rupd_ext -#endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsExpr HsGetField {} = emptyNodeComments -#else -nodeCommentsHsExpr HsGetField {..} = nodeComments gf_ext -#endif nodeCommentsHsExpr HsProjection {..} = nodeComments proj_ext -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsExpr (ExprWithTySig x _ _) = mconcat $ fmap nodeComments x -#else -nodeCommentsHsExpr (ExprWithTySig x _ _) = nodeComments x -#endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsExpr (ArithSeq x _ _) = mconcat $ fmap nodeComments x -#else -nodeCommentsHsExpr (ArithSeq x _ _) = nodeComments x -#endif -#if !MIN_VERSION_ghc_lib_parser(9,4,1) -nodeCommentsHsExpr (HsBracket x _) = nodeComments x -nodeCommentsHsExpr HsRnBracketOut {} = notUsedInParsedStage -nodeCommentsHsExpr HsTcBracketOut {} = notUsedInParsedStage -#endif -#if !MIN_VERSION_ghc_lib_parser(9,6,1) -nodeCommentsHsExpr (HsSpliceE x _) = nodeComments x -#endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsExpr (HsProc x _ _) = mconcat $ fmap nodeComments x -#else -nodeCommentsHsExpr (HsProc x _ _) = nodeComments x -#endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsExpr (HsStatic x _) = mconcat $ fmap nodeComments x -#else -nodeCommentsHsExpr (HsStatic x _) = nodeComments x -#endif -#if !MIN_VERSION_ghc_lib_parser(9, 4, 1) -nodeCommentsHsExpr HsTick {} = emptyNodeComments -nodeCommentsHsExpr HsBinTick {} = emptyNodeComments -#endif nodeCommentsHsExpr HsPragE {} = emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9, 4, 1) -nodeCommentsHsExpr HsRecSel {} = emptyNodeComments -#endif #if MIN_VERSION_ghc_lib_parser(9, 10, 1) nodeCommentsHsExpr (HsTypedBracket x _) = mconcat $ fmap nodeComments x nodeCommentsHsExpr (HsUntypedBracket x _) = mconcat $ fmap nodeComments x +nodeCommentsHsExpr HsLet {} = emptyNodeComments +nodeCommentsHsExpr HsPar {} = emptyNodeComments #elif MIN_VERSION_ghc_lib_parser(9, 4, 1) +nodeCommentsHsExpr HsRecSel {} = emptyNodeComments nodeCommentsHsExpr (HsTypedBracket x _) = nodeComments x nodeCommentsHsExpr (HsUntypedBracket x _) = nodeComments x +nodeCommentsHsExpr (HsLet x _ _ _ _) = nodeComments x +nodeCommentsHsExpr (HsPar x _ _ _) = nodeComments x +#else +nodeCommentsHsExpr HsTick {} = emptyNodeComments +nodeCommentsHsExpr HsBinTick {} = emptyNodeComments +nodeCommentsHsExpr (HsBracket x _) = nodeComments x +nodeCommentsHsExpr HsRnBracketOut {} = notUsedInParsedStage +nodeCommentsHsExpr HsTcBracketOut {} = notUsedInParsedStage +nodeCommentsHsExpr (HsLet x _ _) = nodeComments x +nodeCommentsHsExpr (HsPar x _) = nodeComments x #endif #if MIN_VERSION_ghc_lib_parser(9, 10, 1) nodeCommentsHsExpr (HsTypedSplice x _) = mconcat $ fmap nodeComments x @@ -264,6 +193,33 @@ nodeCommentsHsExpr HsUntypedSplice {} = emptyNodeComments #elif MIN_VERSION_ghc_lib_parser(9, 6, 1) nodeCommentsHsExpr (HsTypedSplice (x, y) _) = nodeComments x <> nodeComments y nodeCommentsHsExpr (HsUntypedSplice x _) = nodeComments x +#else +nodeCommentsHsExpr (HsSpliceE x _) = nodeComments x +#endif +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsHsExpr (HsStatic x _) = mconcat $ fmap nodeComments x +nodeCommentsHsExpr (HsProc x _ _) = mconcat $ fmap nodeComments x +nodeCommentsHsExpr (ArithSeq x _ _) = mconcat $ fmap nodeComments x +nodeCommentsHsExpr (ExprWithTySig x _ _) = mconcat $ fmap nodeComments x +nodeCommentsHsExpr HsGetField {} = emptyNodeComments +nodeCommentsHsExpr RecordUpd {..} = mconcat $ fmap nodeComments rupd_ext +nodeCommentsHsExpr RecordCon {..} = mconcat $ fmap nodeComments rcon_ext +nodeCommentsHsExpr (HsMultiIf x _) = mconcat $ fmap nodeComments x +nodeCommentsHsExpr (ExplicitTuple x _ _) = mconcat $ fmap nodeComments x +nodeCommentsHsExpr SectionR {} = emptyNodeComments +nodeCommentsHsExpr SectionL {} = emptyNodeComments +#else +nodeCommentsHsExpr (HsStatic x _) = nodeComments x +nodeCommentsHsExpr (HsProc x _ _) = nodeComments x +nodeCommentsHsExpr (ArithSeq x _ _) = nodeComments x +nodeCommentsHsExpr (ExprWithTySig x _ _) = nodeComments x +nodeCommentsHsExpr HsGetField {..} = nodeComments gf_ext +nodeCommentsHsExpr RecordUpd {..} = nodeComments rupd_ext +nodeCommentsHsExpr RecordCon {..} = nodeComments rcon_ext +nodeCommentsHsExpr (HsMultiIf x _) = nodeComments x +nodeCommentsHsExpr (ExplicitTuple x _ _) = nodeComments x +nodeCommentsHsExpr (SectionR x _ _) = nodeComments x +nodeCommentsHsExpr (SectionL x _ _) = nodeComments x #endif instance CommentExtraction (HsSigType GhcPs) where nodeComments HsSig {} = emptyNodeComments From 1dfb1bfe4280f75bdcc9bdc0dc174bb8b0b95c61 Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 13:59:20 +0900 Subject: [PATCH 07/40] wip --- src/HIndent/Pretty/NodeComments.hs | 74 +++++++++--------------------- 1 file changed, 21 insertions(+), 53 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index a73cf09d2..ceef21a8b 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -105,61 +105,8 @@ instance CommentExtraction QualifiedDo where nodeCommentsHsExpr :: HsExpr GhcPs -> NodeComments nodeCommentsHsExpr HsVar {} = emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsExpr (HsUnboundVar x _) = fromMaybe mempty $ fmap nodeComments x -#else -nodeCommentsHsExpr (HsUnboundVar x _) = nodeComments x -#endif -#if !MIN_VERSION_ghc_lib_parser(9, 4, 1) -nodeCommentsHsExpr HsConLikeOut {} = emptyNodeComments -nodeCommentsHsExpr HsRecFld {} = emptyNodeComments -#endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsExpr HsOverLabel {} = emptyNodeComments -#elif MIN_VERSION_ghc_lib_parser(9, 6, 1) -nodeCommentsHsExpr (HsOverLabel x _ _) = nodeComments x -#else -nodeCommentsHsExpr (HsOverLabel x _) = nodeComments x -#endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsExpr HsIPVar {} = emptyNodeComments -#else -nodeCommentsHsExpr (HsIPVar x _) = nodeComments x -#endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsExpr HsOverLit {} = emptyNodeComments -#else -nodeCommentsHsExpr (HsOverLit x _) = nodeComments x -#endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsExpr HsLit {} = emptyNodeComments -#else -nodeCommentsHsExpr (HsLit x _) = nodeComments x -#endif nodeCommentsHsExpr HsLam {} = emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) --- No `HsLamCase` since 9.10.1. -#elif MIN_VERSION_ghc_lib_parser(9, 4, 1) -nodeCommentsHsExpr (HsLamCase x _ _) = nodeComments x -#else -nodeCommentsHsExpr (HsLamCase x _) = nodeComments x -#endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsExpr HsApp {} = emptyNodeComments -#else -nodeCommentsHsExpr (HsApp x _ _) = nodeComments x -#endif nodeCommentsHsExpr HsAppType {} = emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsExpr (OpApp x _ _ _) = mconcat $ fmap nodeComments x -#else -nodeCommentsHsExpr (OpApp x _ _ _) = nodeComments x -#endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsExpr (NegApp x _ _) = mconcat $ fmap nodeComments x -#else -nodeCommentsHsExpr (NegApp x _ _) = nodeComments x -#endif nodeCommentsHsExpr (ExplicitSum x _ _ _) = nodeComments x nodeCommentsHsExpr (HsCase x _ _) = nodeComments x nodeCommentsHsExpr (HsIf x _ _ _) = nodeComments x @@ -178,6 +125,7 @@ nodeCommentsHsExpr (HsTypedBracket x _) = nodeComments x nodeCommentsHsExpr (HsUntypedBracket x _) = nodeComments x nodeCommentsHsExpr (HsLet x _ _ _ _) = nodeComments x nodeCommentsHsExpr (HsPar x _ _ _) = nodeComments x +nodeCommentsHsExpr (HsLamCase x _ _) = nodeComments x #else nodeCommentsHsExpr HsTick {} = emptyNodeComments nodeCommentsHsExpr HsBinTick {} = emptyNodeComments @@ -186,15 +134,21 @@ nodeCommentsHsExpr HsRnBracketOut {} = notUsedInParsedStage nodeCommentsHsExpr HsTcBracketOut {} = notUsedInParsedStage nodeCommentsHsExpr (HsLet x _ _) = nodeComments x nodeCommentsHsExpr (HsPar x _) = nodeComments x +nodeCommentsHsExpr (HsLamCase x _) = nodeComments x +nodeCommentsHsExpr HsConLikeOut {} = emptyNodeComments +nodeCommentsHsExpr HsRecFld {} = emptyNodeComments #endif #if MIN_VERSION_ghc_lib_parser(9, 10, 1) nodeCommentsHsExpr (HsTypedSplice x _) = mconcat $ fmap nodeComments x nodeCommentsHsExpr HsUntypedSplice {} = emptyNodeComments +nodeCommentsHsExpr HsOverLabel {} = emptyNodeComments #elif MIN_VERSION_ghc_lib_parser(9, 6, 1) nodeCommentsHsExpr (HsTypedSplice (x, y) _) = nodeComments x <> nodeComments y nodeCommentsHsExpr (HsUntypedSplice x _) = nodeComments x +nodeCommentsHsExpr (HsOverLabel x _ _) = nodeComments x #else nodeCommentsHsExpr (HsSpliceE x _) = nodeComments x +nodeCommentsHsExpr (HsOverLabel x _) = nodeComments x #endif #if MIN_VERSION_ghc_lib_parser(9, 10, 1) nodeCommentsHsExpr (HsStatic x _) = mconcat $ fmap nodeComments x @@ -208,6 +162,13 @@ nodeCommentsHsExpr (HsMultiIf x _) = mconcat $ fmap nodeComments x nodeCommentsHsExpr (ExplicitTuple x _ _) = mconcat $ fmap nodeComments x nodeCommentsHsExpr SectionR {} = emptyNodeComments nodeCommentsHsExpr SectionL {} = emptyNodeComments +nodeCommentsHsExpr (NegApp x _ _) = mconcat $ fmap nodeComments x +nodeCommentsHsExpr (OpApp x _ _ _) = mconcat $ fmap nodeComments x +nodeCommentsHsExpr HsApp {} = emptyNodeComments +nodeCommentsHsExpr HsLit {} = emptyNodeComments +nodeCommentsHsExpr HsOverLit {} = emptyNodeComments +nodeCommentsHsExpr HsIPVar {} = emptyNodeComments +nodeCommentsHsExpr (HsUnboundVar x _) = fromMaybe mempty $ fmap nodeComments x #else nodeCommentsHsExpr (HsStatic x _) = nodeComments x nodeCommentsHsExpr (HsProc x _ _) = nodeComments x @@ -220,6 +181,13 @@ nodeCommentsHsExpr (HsMultiIf x _) = nodeComments x nodeCommentsHsExpr (ExplicitTuple x _ _) = nodeComments x nodeCommentsHsExpr (SectionR x _ _) = nodeComments x nodeCommentsHsExpr (SectionL x _ _) = nodeComments x +nodeCommentsHsExpr (NegApp x _ _) = nodeComments x +nodeCommentsHsExpr (OpApp x _ _ _) = nodeComments x +nodeCommentsHsExpr (HsApp x _ _) = nodeComments x +nodeCommentsHsExpr (HsLit x _) = nodeComments x +nodeCommentsHsExpr (HsOverLit x _) = nodeComments x +nodeCommentsHsExpr (HsIPVar x _) = nodeComments x +nodeCommentsHsExpr (HsUnboundVar x _) = nodeComments x #endif instance CommentExtraction (HsSigType GhcPs) where nodeComments HsSig {} = emptyNodeComments From 45adf3feafaa0f135a51a0786e293a4eb22fead6 Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 14:01:30 +0900 Subject: [PATCH 08/40] wip --- src/HIndent/Pretty/NodeComments.hs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index ceef21a8b..d06cce343 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -195,15 +195,6 @@ instance CommentExtraction (HsSigType GhcPs) where instance CommentExtraction HsSigType' where nodeComments (HsSigType' _ _ HsSig {}) = emptyNodeComments #if MIN_VERSION_ghc_lib_parser(9, 10, 1) -instance CommentExtraction (ConDecl GhcPs) where - nodeComments ConDeclGADT {..} = mconcat $ fmap nodeComments $ snd con_g_ext - nodeComments ConDeclH98 {..} = mconcat $ fmap nodeComments con_ext -#else -instance CommentExtraction (ConDecl GhcPs) where - nodeComments ConDeclGADT {..} = nodeComments con_g_ext - nodeComments ConDeclH98 {..} = nodeComments con_ext -#endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) instance CommentExtraction (Match GhcPs a) where nodeComments Match {..} = mconcat $ fmap nodeComments m_ext #else From 7dc4da4fc6b52cc1f87f539cd5d2693a1ea8eedd Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 14:29:05 +0900 Subject: [PATCH 09/40] wip --- src/HIndent/Pretty/NodeComments.hs | 47 +++++++++++++++--------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index d06cce343..8bab84f3f 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -194,36 +194,37 @@ instance CommentExtraction (HsSigType GhcPs) where instance CommentExtraction HsSigType' where nodeComments (HsSigType' _ _ HsSig {}) = emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) + instance CommentExtraction (Match GhcPs a) where - nodeComments Match {..} = mconcat $ fmap nodeComments m_ext + nodeComments = nodeCommentsMatch + +nodeCommentsMatch :: Match GhcPs a -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsMatch Match {..} = mconcat $ fmap nodeComments m_ext #else -instance CommentExtraction (Match GhcPs a) where - nodeComments Match {..} = nodeComments m_ext +nodeCommentsMatch Match {..} = nodeComments m_ext #endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) instance CommentExtraction (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))) where - nodeComments LastStmt {} = emptyNodeComments - nodeComments (BindStmt x _ _) = mconcat $ fmap nodeComments x - nodeComments ApplicativeStmt {} = emptyNodeComments - nodeComments BodyStmt {} = emptyNodeComments - nodeComments (LetStmt x _) = mconcat $ fmap nodeComments x - nodeComments ParStmt {} = emptyNodeComments - nodeComments TransStmt {..} = mconcat $ fmap nodeComments trS_ext - nodeComments RecStmt {..} = nodeComments recS_ext + nodeComments = nodeCommentsStmtLRExpr + +nodeCommentsStmtLRExpr :: + StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)) -> NodeComments +nodeCommentsStmtLRExpr LastStmt {} = emptyNodeComments +nodeCommentsStmtLRExpr ApplicativeStmt {} = emptyNodeComments +nodeCommentsStmtLRExpr BodyStmt {} = emptyNodeComments +nodeCommentsStmtLRExpr ParStmt {} = emptyNodeComments +nodeCommentsStmtLRExpr RecStmt {..} = nodeComments recS_ext +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsStmtLRExpr (BindStmt x _ _) = mconcat $ fmap nodeComments x +nodeCommentsStmtLRExpr (LetStmt x _) = mconcat $ fmap nodeComments x +nodeCommentsStmtLRExpr TransStmt {..} = mconcat $ fmap nodeComments trS_ext #else -instance CommentExtraction - (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))) where - nodeComments LastStmt {} = emptyNodeComments - nodeComments (BindStmt x _ _) = nodeComments x - nodeComments ApplicativeStmt {} = emptyNodeComments - nodeComments BodyStmt {} = emptyNodeComments - nodeComments (LetStmt x _) = nodeComments x - nodeComments ParStmt {} = emptyNodeComments - nodeComments TransStmt {..} = nodeComments trS_ext - nodeComments RecStmt {..} = nodeComments recS_ext +nodeCommentsStmtLRExpr (BindStmt x _ _) = nodeComments x +nodeCommentsStmtLRExpr (LetStmt x _) = nodeComments x +nodeCommentsStmtLRExpr TransStmt {..} = nodeComments trS_ext #endif + #if MIN_VERSION_ghc_lib_parser(9, 10, 1) instance CommentExtraction (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsCmd GhcPs))) where From 1115d384578b90b02a545800dfbe85375d431d3c Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 14:30:56 +0900 Subject: [PATCH 10/40] wip --- src/HIndent/Pretty/NodeComments.hs | 56 ++++++++---------------------- 1 file changed, 15 insertions(+), 41 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index 8bab84f3f..612ca2ff3 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -204,49 +204,23 @@ nodeCommentsMatch Match {..} = mconcat $ fmap nodeComments m_ext #else nodeCommentsMatch Match {..} = nodeComments m_ext #endif -instance CommentExtraction - (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))) where - nodeComments = nodeCommentsStmtLRExpr - -nodeCommentsStmtLRExpr :: - StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)) -> NodeComments -nodeCommentsStmtLRExpr LastStmt {} = emptyNodeComments -nodeCommentsStmtLRExpr ApplicativeStmt {} = emptyNodeComments -nodeCommentsStmtLRExpr BodyStmt {} = emptyNodeComments -nodeCommentsStmtLRExpr ParStmt {} = emptyNodeComments -nodeCommentsStmtLRExpr RecStmt {..} = nodeComments recS_ext +instance CommentExtraction (StmtLR GhcPs GhcPs a) where + nodeComments = nodeCommentsStmtLR + +nodeCommentsStmtLR :: StmtLR GhcPs GhcPs a -> NodeComments +nodeCommentsStmtLR LastStmt {} = emptyNodeComments +nodeCommentsStmtLR ApplicativeStmt {} = emptyNodeComments +nodeCommentsStmtLR BodyStmt {} = emptyNodeComments +nodeCommentsStmtLR ParStmt {} = emptyNodeComments +nodeCommentsStmtLR RecStmt {..} = nodeComments recS_ext #if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsStmtLRExpr (BindStmt x _ _) = mconcat $ fmap nodeComments x -nodeCommentsStmtLRExpr (LetStmt x _) = mconcat $ fmap nodeComments x -nodeCommentsStmtLRExpr TransStmt {..} = mconcat $ fmap nodeComments trS_ext +nodeCommentsStmtLR (BindStmt x _ _) = mconcat $ fmap nodeComments x +nodeCommentsStmtLR (LetStmt x _) = mconcat $ fmap nodeComments x +nodeCommentsStmtLR TransStmt {..} = mconcat $ fmap nodeComments trS_ext #else -nodeCommentsStmtLRExpr (BindStmt x _ _) = nodeComments x -nodeCommentsStmtLRExpr (LetStmt x _) = nodeComments x -nodeCommentsStmtLRExpr TransStmt {..} = nodeComments trS_ext -#endif - -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -instance CommentExtraction - (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsCmd GhcPs))) where - nodeComments LastStmt {} = emptyNodeComments - nodeComments (BindStmt x _ _) = mconcat $ fmap nodeComments x - nodeComments ApplicativeStmt {} = emptyNodeComments - nodeComments BodyStmt {} = emptyNodeComments - nodeComments (LetStmt x _) = mconcat $ fmap nodeComments x - nodeComments ParStmt {} = emptyNodeComments - nodeComments TransStmt {..} = mconcat $ fmap nodeComments trS_ext - nodeComments RecStmt {..} = nodeComments recS_ext -#else -instance CommentExtraction - (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsCmd GhcPs))) where - nodeComments LastStmt {} = emptyNodeComments - nodeComments (BindStmt x _ _) = nodeComments x - nodeComments ApplicativeStmt {} = emptyNodeComments - nodeComments BodyStmt {} = emptyNodeComments - nodeComments (LetStmt x _) = nodeComments x - nodeComments ParStmt {} = emptyNodeComments - nodeComments TransStmt {..} = nodeComments trS_ext - nodeComments RecStmt {..} = nodeComments recS_ext +nodeCommentsStmtLR (BindStmt x _ _) = nodeComments x +nodeCommentsStmtLR (LetStmt x _) = nodeComments x +nodeCommentsStmtLR TransStmt {..} = nodeComments trS_ext #endif instance CommentExtraction StmtLRInsideVerticalList where nodeComments (StmtLRInsideVerticalList x) = nodeComments x From 85cf2839e8bd25ae849b41c887b03aead122e561 Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 14:39:38 +0900 Subject: [PATCH 11/40] wip --- src/HIndent/Pretty/NodeComments.hs | 88 +++++++++++++----------------- 1 file changed, 37 insertions(+), 51 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index 612ca2ff3..ecd0b33ba 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -236,60 +236,46 @@ instance CommentExtraction nodeComments HsRecFields {} = emptyNodeComments instance CommentExtraction (HsType GhcPs) where - nodeComments = nodeComments . HsType' HsTypeForNormalDecl HsTypeNoDir + nodeComments = nodeCommentsHsType + +nodeCommentsHsType :: HsType GhcPs -> NodeComments +nodeCommentsHsType HsForAllTy {} = emptyNodeComments +nodeCommentsHsType HsQualTy {} = emptyNodeComments +nodeCommentsHsType HsAppTy {} = emptyNodeComments +nodeCommentsHsType HsAppKindTy {} = emptyNodeComments +nodeCommentsHsType (HsListTy x _) = nodeComments x +nodeCommentsHsType (HsTupleTy x _ _) = nodeComments x +nodeCommentsHsType (HsSumTy x _) = nodeComments x +nodeCommentsHsType HsOpTy {} = emptyNodeComments +nodeCommentsHsType (HsParTy x _) = nodeComments x +nodeCommentsHsType HsStarTy {} = emptyNodeComments +nodeCommentsHsType HsSpliceTy {} = emptyNodeComments +nodeCommentsHsType (HsRecTy x _) = nodeComments x +nodeCommentsHsType HsTyLit {} = emptyNodeComments +nodeCommentsHsType HsWildCardTy {} = emptyNodeComments +nodeCommentsHsType XHsType {} = emptyNodeComments #if MIN_VERSION_ghc_lib_parser(9, 10, 1) -instance CommentExtraction HsType' where - nodeComments (HsType' _ _ HsForAllTy {}) = emptyNodeComments - nodeComments (HsType' _ _ HsQualTy {}) = emptyNodeComments - nodeComments (HsType' _ _ (HsTyVar x _ _)) = mconcat $ fmap nodeComments x - nodeComments (HsType' _ _ HsAppTy {}) = emptyNodeComments - nodeComments (HsType' _ _ HsAppKindTy {}) = emptyNodeComments - nodeComments (HsType' _ _ HsFunTy {}) = emptyNodeComments - nodeComments (HsType' _ _ (HsListTy x _)) = nodeComments x - nodeComments (HsType' _ _ (HsTupleTy x _ _)) = nodeComments x - nodeComments (HsType' _ _ (HsSumTy x _)) = nodeComments x - nodeComments (HsType' _ _ HsOpTy {}) = emptyNodeComments - nodeComments (HsType' _ _ (HsParTy x _)) = nodeComments x - nodeComments (HsType' _ _ (HsIParamTy x _ _)) = mconcat $ fmap nodeComments x - nodeComments (HsType' _ _ HsStarTy {}) = emptyNodeComments - nodeComments (HsType' _ _ (HsKindSig x _ _)) = mconcat $ fmap nodeComments x - nodeComments (HsType' _ _ HsSpliceTy {}) = emptyNodeComments - nodeComments (HsType' _ _ (HsDocTy x _ _)) = mconcat $ fmap nodeComments x - nodeComments (HsType' _ _ (HsBangTy x _ _)) = mconcat $ fmap nodeComments x - nodeComments (HsType' _ _ (HsRecTy x _)) = nodeComments x - nodeComments (HsType' _ _ (HsExplicitListTy x _ _)) = - mconcat $ fmap nodeComments x - nodeComments (HsType' _ _ (HsExplicitTupleTy x _)) = - mconcat $ fmap nodeComments x - nodeComments (HsType' _ _ HsTyLit {}) = emptyNodeComments - nodeComments (HsType' _ _ HsWildCardTy {}) = emptyNodeComments - nodeComments (HsType' _ _ XHsType {}) = emptyNodeComments +nodeCommentsHsType (HsTyVar x _ _) = mconcat $ fmap nodeComments x +nodeCommentsHsType HsFunTy {} = emptyNodeComments +nodeCommentsHsType (HsIParamTy x _ _) = mconcat $ fmap nodeComments x +nodeCommentsHsType (HsKindSig x _ _) = mconcat $ fmap nodeComments x +nodeCommentsHsType (HsDocTy x _ _) = mconcat $ fmap nodeComments x +nodeCommentsHsType (HsBangTy x _ _) = mconcat $ fmap nodeComments x +nodeCommentsHsType (HsExplicitListTy x _ _) = mconcat $ fmap nodeComments x +nodeCommentsHsType (HsExplicitTupleTy x _) = mconcat $ fmap nodeComments x #else -instance CommentExtraction HsType' where - nodeComments (HsType' _ _ HsForAllTy {}) = emptyNodeComments - nodeComments (HsType' _ _ HsQualTy {}) = emptyNodeComments - nodeComments (HsType' _ _ (HsTyVar x _ _)) = nodeComments x - nodeComments (HsType' _ _ HsAppTy {}) = emptyNodeComments - nodeComments (HsType' _ _ HsAppKindTy {}) = emptyNodeComments - nodeComments (HsType' _ _ (HsFunTy x _ _ _)) = nodeComments x - nodeComments (HsType' _ _ (HsListTy x _)) = nodeComments x - nodeComments (HsType' _ _ (HsTupleTy x _ _)) = nodeComments x - nodeComments (HsType' _ _ (HsSumTy x _)) = nodeComments x - nodeComments (HsType' _ _ HsOpTy {}) = emptyNodeComments - nodeComments (HsType' _ _ (HsParTy x _)) = nodeComments x - nodeComments (HsType' _ _ (HsIParamTy x _ _)) = nodeComments x - nodeComments (HsType' _ _ HsStarTy {}) = emptyNodeComments - nodeComments (HsType' _ _ (HsKindSig x _ _)) = nodeComments x - nodeComments (HsType' _ _ HsSpliceTy {}) = emptyNodeComments - nodeComments (HsType' _ _ (HsDocTy x _ _)) = nodeComments x - nodeComments (HsType' _ _ (HsBangTy x _ _)) = nodeComments x - nodeComments (HsType' _ _ (HsRecTy x _)) = nodeComments x - nodeComments (HsType' _ _ (HsExplicitListTy x _ _)) = nodeComments x - nodeComments (HsType' _ _ (HsExplicitTupleTy x _)) = nodeComments x - nodeComments (HsType' _ _ HsTyLit {}) = emptyNodeComments - nodeComments (HsType' _ _ HsWildCardTy {}) = emptyNodeComments - nodeComments (HsType' _ _ XHsType {}) = emptyNodeComments +nodeCommentsHsType (HsTyVar x _ _) = nodeComments x +nodeCommentsHsType (HsFunTy x _ _ _) = nodeComments x +nodeCommentsHsType (HsIParamTy x _ _) = nodeComments x +nodeCommentsHsType (HsKindSig x _ _) = nodeComments x +nodeCommentsHsType (HsDocTy x _ _) = nodeComments x +nodeCommentsHsType (HsBangTy x _ _) = nodeComments x +nodeCommentsHsType (HsExplicitListTy x _ _) = nodeComments x +nodeCommentsHsType (HsExplicitTupleTy x _) = nodeComments x #endif +instance CommentExtraction HsType' where + nodeComments HsType' {..} = nodeComments hsType + instance CommentExtraction (GRHSs GhcPs a) where nodeComments GRHSs {..} = NodeComments {..} where From d330b1307eb38e59d09675ebb144789bbbd06845 Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 14:45:56 +0900 Subject: [PATCH 12/40] wip --- src/HIndent/Pretty/NodeComments.hs | 33 ++++++++---------------------- 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index ecd0b33ba..57e74cbf6 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -288,13 +288,18 @@ instance CommentExtraction GRHSsExpr where #if MIN_VERSION_ghc_lib_parser(9, 10, 1) instance CommentExtraction (HsMatchContext (GenLocated SrcSpanAnnN RdrName)) where nodeComments = nodeCommentsMatchContext +#else +instance CommentExtraction (HsMatchContext GhcPs) where + nodeComments = nodeCommentsMatchContext +#endif +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) nodeCommentsMatchContext :: HsMatchContext (GenLocated SrcSpanAnnN RdrName) -> NodeComments -nodeCommentsMatchContext FunRhs {} = emptyNodeComments -#if !MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsMatchContext LambdaExpr {} = emptyNodeComments +#else +nodeCommentsMatchContext :: HsMatchContext GhcPs -> NodeComments #endif +nodeCommentsMatchContext FunRhs {} = emptyNodeComments nodeCommentsMatchContext CaseAlt {} = emptyNodeComments nodeCommentsMatchContext IfAlt {} = emptyNodeComments nodeCommentsMatchContext ArrowMatchCtxt {} = emptyNodeComments @@ -305,32 +310,12 @@ nodeCommentsMatchContext StmtCtxt {} = emptyNodeComments nodeCommentsMatchContext ThPatSplice {} = emptyNodeComments nodeCommentsMatchContext ThPatQuote {} = emptyNodeComments nodeCommentsMatchContext PatSyn {} = emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9,4,1) && !MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsMatchContext LamCaseAlt {} = emptyNodeComments -#endif -#else -instance CommentExtraction (HsMatchContext GhcPs) where - nodeComments = nodeCommentsMatchContext - -nodeCommentsMatchContext :: HsMatchContext GhcPs -> NodeComments -nodeCommentsMatchContext FunRhs {} = emptyNodeComments #if !MIN_VERSION_ghc_lib_parser(9, 10, 1) nodeCommentsMatchContext LambdaExpr {} = emptyNodeComments #endif -nodeCommentsMatchContext CaseAlt {} = emptyNodeComments -nodeCommentsMatchContext IfAlt {} = emptyNodeComments -nodeCommentsMatchContext ArrowMatchCtxt {} = emptyNodeComments -nodeCommentsMatchContext PatBindRhs {} = emptyNodeComments -nodeCommentsMatchContext PatBindGuards {} = emptyNodeComments -nodeCommentsMatchContext RecUpd {} = emptyNodeComments -nodeCommentsMatchContext StmtCtxt {} = emptyNodeComments -nodeCommentsMatchContext ThPatSplice {} = emptyNodeComments -nodeCommentsMatchContext ThPatQuote {} = emptyNodeComments -nodeCommentsMatchContext PatSyn {} = emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9,4,1) && !MIN_VERSION_ghc_lib_parser(9, 10, 1) +#if MIN_VERSION_ghc_lib_parser(9, 4, 1) nodeCommentsMatchContext LamCaseAlt {} = emptyNodeComments #endif -#endif instance CommentExtraction (ParStmtBlock GhcPs GhcPs) where nodeComments ParStmtBlock {} = emptyNodeComments From a1a2d4ec1acb8b1e314802952ff2cbc4d91a51fa Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 14:46:18 +0900 Subject: [PATCH 13/40] wip --- src/HIndent/Pretty/NodeComments.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index 57e74cbf6..9d2551b9f 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -342,7 +342,7 @@ instance CommentExtraction EpaCommentTok where instance CommentExtraction (SpliceDecl GhcPs) where nodeComments SpliceDecl {} = emptyNodeComments -#if !MIN_VERSION_ghc_lib_parser(9,6,1) +#if !MIN_VERSION_ghc_lib_parser(9, 6, 1) instance CommentExtraction (HsSplice GhcPs) where nodeComments (HsTypedSplice x _ _ _) = nodeComments x nodeComments (HsUntypedSplice x _ _ _) = nodeComments x From 720a1930ced81dbdb8a7b693e88d37395d8743d1 Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 14:50:08 +0900 Subject: [PATCH 14/40] wip --- src/HIndent/Pretty/NodeComments.hs | 50 ++++++++++-------------------- 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index 9d2551b9f..ca080c7f8 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -358,10 +358,17 @@ instance CommentExtraction PatInsidePatDecl where nodeCommentsPat :: Pat GhcPs -> NodeComments nodeCommentsPat WildPat {} = emptyNodeComments nodeCommentsPat VarPat {} = emptyNodeComments +nodeCommentsPat (ListPat x _) = nodeComments x +nodeCommentsPat (SumPat x _ _ _) = nodeComments x +nodeCommentsPat SplicePat {} = emptyNodeComments +nodeCommentsPat LitPat {} = emptyNodeComments +nodeCommentsPat (NPlusKPat x _ _ _ _ _) = nodeComments x #if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsPat (LazyPat x _) = mconcat $ fmap nodeComments x +nodeCommentsPat ParPat {} = emptyNodeComments +#elif MIN_VERSION_ghc_lib_parser(9, 4, 1) +nodeCommentsPat (ParPat x _ _ _) = nodeComments x #else -nodeCommentsPat (LazyPat x _) = nodeComments x +nodeCommentsPat (ParPat x _) = nodeComments x #endif #if MIN_VERSION_ghc_lib_parser(9, 10, 1) nodeCommentsPat AsPat {} = emptyNodeComments @@ -371,45 +378,20 @@ nodeCommentsPat (AsPat x _ _ _) = nodeComments x nodeCommentsPat (AsPat x _ _) = nodeComments x #endif #if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsPat ParPat {} = emptyNodeComments -#elif MIN_VERSION_ghc_lib_parser(9, 4, 1) -nodeCommentsPat (ParPat x _ _ _) = nodeComments x -#else -nodeCommentsPat (ParPat x _) = nodeComments x -#endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsPat (LazyPat x _) = mconcat $ fmap nodeComments x nodeCommentsPat (BangPat x _) = mconcat $ fmap nodeComments x -#else -nodeCommentsPat (BangPat x _) = nodeComments x -#endif -nodeCommentsPat (ListPat x _) = nodeComments x -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) nodeCommentsPat (TuplePat x _ _) = mconcat $ fmap nodeComments x -#else -nodeCommentsPat (TuplePat x _ _) = nodeComments x -#endif -nodeCommentsPat (SumPat x _ _ _) = nodeComments x -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) nodeCommentsPat ConPat {..} = mconcat $ fmap nodeComments pat_con_ext -#else -nodeCommentsPat ConPat {..} = nodeComments pat_con_ext -#endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) nodeCommentsPat (ViewPat x _ _) = mconcat $ fmap nodeComments x -#else -nodeCommentsPat (ViewPat x _ _) = nodeComments x -#endif -nodeCommentsPat SplicePat {} = emptyNodeComments -nodeCommentsPat LitPat {} = emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) nodeCommentsPat (NPat x _ _ _) = mconcat $ fmap nodeComments x -#else -nodeCommentsPat (NPat x _ _ _) = nodeComments x -#endif -nodeCommentsPat (NPlusKPat x _ _ _ _ _) = nodeComments x -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) nodeCommentsPat (SigPat x _ _) = mconcat $ fmap nodeComments x #else +nodeCommentsPat (LazyPat x _) = nodeComments x +nodeCommentsPat (BangPat x _) = nodeComments x +nodeCommentsPat (TuplePat x _ _) = nodeComments x +nodeCommentsPat ConPat {..} = nodeComments pat_con_ext +nodeCommentsPat (ViewPat x _ _) = nodeComments x +nodeCommentsPat (NPat x _ _ _) = nodeComments x nodeCommentsPat (SigPat x _ _) = nodeComments x #endif instance CommentExtraction RecConPat where From 4abb5650a7f6eb576fee7d4c6fcd21d4d79d2634 Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 15:22:53 +0900 Subject: [PATCH 15/40] wip --- src/HIndent/Pretty/NodeComments.hs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index ca080c7f8..451ba7da0 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -455,15 +455,17 @@ instance CommentExtraction (HsLocalBindsLR GhcPs GhcPs) where instance CommentExtraction (HsValBindsLR GhcPs GhcPs) where nodeComments ValBinds {} = emptyNodeComments nodeComments XValBindsLR {} = notUsedInParsedStage -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) + instance CommentExtraction (HsTupArg GhcPs) where - nodeComments Present {} = emptyNodeComments - nodeComments (Missing x) = nodeComments x + nodeComments = nodeCommentsHsTupArg + +nodeCommentsHsTupArg :: HsTupArg GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsHsTupArg Present {} = emptyNodeComments #else -instance CommentExtraction (HsTupArg GhcPs) where - nodeComments (Present x _) = nodeComments x - nodeComments (Missing x) = nodeComments x +nodeCommentsHsTupArg (Present x _) = nodeComments x #endif +nodeCommentsHsTupArg (Missing x) = nodeComments x #if MIN_VERSION_ghc_lib_parser(9, 4, 1) instance CommentExtraction RecConField where nodeComments (RecConField x) = nodeComments x From 2b487c8109238f00108ec4c8d39be5dbe4f0fd7d Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 15:24:52 +0900 Subject: [PATCH 16/40] wip --- src/HIndent/Pretty/NodeComments.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index 451ba7da0..d237fc3db 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -313,7 +313,7 @@ nodeCommentsMatchContext PatSyn {} = emptyNodeComments #if !MIN_VERSION_ghc_lib_parser(9, 10, 1) nodeCommentsMatchContext LambdaExpr {} = emptyNodeComments #endif -#if MIN_VERSION_ghc_lib_parser(9, 4, 1) +#if MIN_VERSION_ghc_lib_parser(9, 4, 1) && !MIN_VERSION_ghc_lib_parser(9, 10, 1) nodeCommentsMatchContext LamCaseAlt {} = emptyNodeComments #endif instance CommentExtraction (ParStmtBlock GhcPs GhcPs) where From dddb0bdcd88bdca6421b59d024a82b809934d7b2 Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 15:27:43 +0900 Subject: [PATCH 17/40] wip --- src/HIndent/Pretty/NodeComments.hs | 34 ++++++++---------------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index d237fc3db..4658610d2 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -480,32 +480,16 @@ instance CommentExtraction (HsRecField' (FieldOcc GhcPs) (GenLocated SrcSpanAnnA (HsExpr GhcPs))) where nodeComments HsRecField {..} = nodeComments hsRecFieldAnn #endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -instance CommentExtraction - (HsFieldBind - (GenLocated SrcSpanAnnA (FieldOcc GhcPs)) - (GenLocated SrcSpanAnnA (Pat GhcPs))) where - nodeComments HsFieldBind {..} = mconcat $ fmap nodeComments hfbAnn - -instance CommentExtraction - (HsFieldBind - (GenLocated SrcSpanAnnA (FieldOcc GhcPs)) - (GenLocated SrcSpanAnnA (HsExpr GhcPs))) where - nodeComments HsFieldBind {..} = mconcat $ fmap nodeComments hfbAnn -#elif MIN_VERSION_ghc_lib_parser(9, 4, 1) --- | For pattern matchings against records. -instance CommentExtraction - (HsFieldBind - (GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcPs)) - (GenLocated SrcSpanAnnA (Pat GhcPs))) where - nodeComments HsFieldBind {..} = nodeComments hfbAnn +#if MIN_VERSION_ghc_lib_parser(9, 4, 1) +instance CommentExtraction (HsFieldBind a b) where + nodeComments = nodeCommentsHsFieldBind --- | For record updates. -instance CommentExtraction - (HsFieldBind - (GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcPs)) - (GenLocated SrcSpanAnnA (HsExpr GhcPs))) where - nodeComments HsFieldBind {..} = nodeComments hfbAnn +nodeCommentsHsFieldBind :: HsFieldBind a b -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsHsFieldBind HsFieldBind {..} = mconcat $ fmap nodeComments hfbAnn +#else +nodeCommentsHsFieldBind HsFieldBind {..} = nodeComments hfbAnn +#endif #else instance CommentExtraction RecConField where nodeComments (RecConField x) = nodeComments x From d1d895139fc59a2e936a913bf4daffcbf2bd4b9b Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 15:28:23 +0900 Subject: [PATCH 18/40] wip --- src/HIndent/Pretty/NodeComments.hs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index 4658610d2..137dddb54 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -494,13 +494,9 @@ nodeCommentsHsFieldBind HsFieldBind {..} = nodeComments hfbAnn instance CommentExtraction RecConField where nodeComments (RecConField x) = nodeComments x #endif -#if MIN_VERSION_ghc_lib_parser(9,4,1) -instance CommentExtraction (FieldOcc GhcPs) where - nodeComments FieldOcc {} = emptyNodeComments -#else instance CommentExtraction (FieldOcc GhcPs) where nodeComments FieldOcc {} = emptyNodeComments -#endif + -- HsConDeclH98Details instance CommentExtraction (HsConDetails From d9309b8a45a05cb1d3249e4b507b6ff88cbc2400 Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 15:29:15 +0900 Subject: [PATCH 19/40] wip --- src/HIndent/Pretty/NodeComments.hs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index 137dddb54..3ac59aa19 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -511,12 +511,16 @@ instance CommentExtraction instance CommentExtraction (HsScaled GhcPs a) where nodeComments HsScaled {} = emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) + instance CommentExtraction (ConDeclField GhcPs) where - nodeComments ConDeclField {..} = mconcat $ fmap nodeComments cd_fld_ext + nodeComments = nodeCommentsConDeclField + +nodeCommentsConDeclField :: ConDeclField GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsConDeclField ConDeclField {..} = + mconcat $ fmap nodeComments cd_fld_ext #else -instance CommentExtraction (ConDeclField GhcPs) where - nodeComments ConDeclField {..} = nodeComments cd_fld_ext +nodeCommentsConDeclField ConDeclField {..} = nodeComments cd_fld_ext #endif instance CommentExtraction InfixExpr where nodeComments (InfixExpr x) = nodeComments x From b0b220b3e42da0072fa3633a8e44251a04197114 Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 15:30:20 +0900 Subject: [PATCH 20/40] wip --- src/HIndent/Pretty/NodeComments.hs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index 3ac59aa19..ef51cb8de 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -543,17 +543,20 @@ instance CommentExtraction (AmbiguousFieldOcc GhcPs) where instance CommentExtraction (ImportDecl GhcPs) where nodeComments ImportDecl {..} = nodeComments ideclExt -#if MIN_VERSION_ghc_lib_parser(9,6,1) +#if MIN_VERSION_ghc_lib_parser(9, 6, 1) instance CommentExtraction XImportDeclPass where nodeComments XImportDeclPass {..} = nodeComments ideclAnn #endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) instance CommentExtraction (HsDerivingClause GhcPs) where - nodeComments HsDerivingClause {..} = - mconcat $ fmap nodeComments deriv_clause_ext + nodeComments = nodeCommentsHsDerivingClause + +nodeCommentsHsDerivingClause :: HsDerivingClause GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsHsDerivingClause HsDerivingClause {..} = + mconcat $ fmap nodeComments deriv_clause_ext #else -instance CommentExtraction (HsDerivingClause GhcPs) where - nodeComments HsDerivingClause {..} = nodeComments deriv_clause_ext +nodeCommentsHsDerivingClause HsDerivingClause {..} = + nodeComments deriv_clause_ext #endif instance CommentExtraction (DerivClauseTys GhcPs) where nodeComments DctSingle {} = emptyNodeComments From f27a59cde3b45892570c1ccd2468a587af5c216d Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 15:32:18 +0900 Subject: [PATCH 21/40] wip --- src/HIndent/Pretty/NodeComments.hs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index ef51cb8de..1f652af23 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -571,14 +571,16 @@ instance CommentExtraction OverlapMode where instance CommentExtraction StringLiteral where nodeComments StringLiteral {} = emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) + -- | This instance is for type family declarations inside a class declaration. instance CommentExtraction (FamilyDecl GhcPs) where - nodeComments FamilyDecl {..} = mconcat $ fmap nodeComments fdExt + nodeComments = nodeCommentsFamilyDecl + +nodeCommentsFamilyDecl :: FamilyDecl GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsFamilyDecl FamilyDecl {..} = mconcat $ fmap nodeComments fdExt #else --- | This instance is for type family declarations inside a class declaration. -instance CommentExtraction (FamilyDecl GhcPs) where - nodeComments FamilyDecl {..} = nodeComments fdExt +nodeCommentsFamilyDecl FamilyDecl {..} = nodeComments fdExt #endif instance CommentExtraction (FamilyResultSig GhcPs) where nodeComments NoSig {} = emptyNodeComments From 174c940598343257b1e675badce2efc63db7959e Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 15:33:28 +0900 Subject: [PATCH 22/40] wip --- src/HIndent/Pretty/NodeComments.hs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index 1f652af23..c5903d54a 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -586,15 +586,19 @@ instance CommentExtraction (FamilyResultSig GhcPs) where nodeComments NoSig {} = emptyNodeComments nodeComments KindSig {} = emptyNodeComments nodeComments TyVarSig {} = emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) + instance CommentExtraction (HsTyVarBndr a GhcPs) where - nodeComments (UserTyVar x _ _) = mconcat $ fmap nodeComments x - nodeComments (KindedTyVar x _ _ _) = mconcat $ fmap nodeComments x + nodeComments = nodeCommentsHsTyVarBndr + +nodeCommentsHsTyVarBndr :: HsTyVarBndr a GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsHsTyVarBndr (UserTyVar x _ _) = mconcat $ fmap nodeComments x +nodeCommentsHsTyVarBndr (KindedTyVar x _ _ _) = mconcat $ fmap nodeComments x #else -instance CommentExtraction (HsTyVarBndr a GhcPs) where - nodeComments (UserTyVar x _ _) = nodeComments x - nodeComments (KindedTyVar x _ _ _) = nodeComments x +nodeCommentsHsTyVarBndr (UserTyVar x _ _) = nodeComments x +nodeCommentsHsTyVarBndr (KindedTyVar x _ _ _) = nodeComments x #endif + #if MIN_VERSION_ghc_lib_parser(9, 10, 1) instance CommentExtraction (InjectivityAnn GhcPs) where nodeComments (InjectivityAnn x _ _) = mconcat $ fmap nodeComments x From ed1c39595322ec8752a1d013e11d517b87fad2fe Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 15:34:28 +0900 Subject: [PATCH 23/40] wip --- src/HIndent/Pretty/NodeComments.hs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index c5903d54a..858738710 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -598,13 +598,15 @@ nodeCommentsHsTyVarBndr (KindedTyVar x _ _ _) = mconcat $ fmap nodeComments x nodeCommentsHsTyVarBndr (UserTyVar x _ _) = nodeComments x nodeCommentsHsTyVarBndr (KindedTyVar x _ _ _) = nodeComments x #endif +instance CommentExtraction (InjectivityAnn GhcPs) where + nodeComments = nodeCommentsInjectivityAnn +nodeCommentsInjectivityAnn :: InjectivityAnn GhcPs -> NodeComments #if MIN_VERSION_ghc_lib_parser(9, 10, 1) -instance CommentExtraction (InjectivityAnn GhcPs) where - nodeComments (InjectivityAnn x _ _) = mconcat $ fmap nodeComments x +nodeCommentsInjectivityAnn (InjectivityAnn x _ _) = + mconcat $ fmap nodeComments x #else -instance CommentExtraction (InjectivityAnn GhcPs) where - nodeComments (InjectivityAnn x _ _) = nodeComments x +nodeCommentsInjectivityAnn (InjectivityAnn x _ _) = nodeComments x #endif instance CommentExtraction (ArithSeqInfo GhcPs) where nodeComments From {} = emptyNodeComments From a4a49e245d071ce82916a35072b7fae27c1ee482 Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 15:35:11 +0900 Subject: [PATCH 24/40] wip --- src/HIndent/Pretty/NodeComments.hs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index 858738710..5923998b9 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -598,16 +598,6 @@ nodeCommentsHsTyVarBndr (KindedTyVar x _ _ _) = mconcat $ fmap nodeComments x nodeCommentsHsTyVarBndr (UserTyVar x _ _) = nodeComments x nodeCommentsHsTyVarBndr (KindedTyVar x _ _ _) = nodeComments x #endif -instance CommentExtraction (InjectivityAnn GhcPs) where - nodeComments = nodeCommentsInjectivityAnn - -nodeCommentsInjectivityAnn :: InjectivityAnn GhcPs -> NodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsInjectivityAnn (InjectivityAnn x _ _) = - mconcat $ fmap nodeComments x -#else -nodeCommentsInjectivityAnn (InjectivityAnn x _ _) = nodeComments x -#endif instance CommentExtraction (ArithSeqInfo GhcPs) where nodeComments From {} = emptyNodeComments nodeComments FromThen {} = emptyNodeComments From 9da58569d2b59f85769a8609d000d56a21af1d8e Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 15:36:37 +0900 Subject: [PATCH 25/40] wip --- src/HIndent/Pretty/NodeComments.hs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index 5923998b9..be5b0e7fe 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -616,19 +616,13 @@ instance CommentExtraction PrefixOp where instance CommentExtraction Context where nodeComments Context {} = emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9,4,1) -instance CommentExtraction HorizontalContext where - nodeComments HorizontalContext {} = emptyNodeComments -instance CommentExtraction VerticalContext where - nodeComments VerticalContext {} = emptyNodeComments -#else instance CommentExtraction HorizontalContext where nodeComments HorizontalContext {} = emptyNodeComments instance CommentExtraction VerticalContext where nodeComments VerticalContext {} = emptyNodeComments -#endif + -- Wrap a value of this type with 'ModulenameWithPrefix' to print it with -- the "module " prefix. instance CommentExtraction ModuleName where From 7aedab93f72395d38b93a10e6048ae5d65ea1581 Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 15:37:59 +0900 Subject: [PATCH 26/40] wip --- src/HIndent/Pretty/NodeComments.hs | 58 +++++++++++++++--------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index be5b0e7fe..c313edcb6 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -630,37 +630,39 @@ instance CommentExtraction ModuleName where instance CommentExtraction ModuleNameWithPrefix where nodeComments ModuleNameWithPrefix {} = emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) + instance CommentExtraction (IE GhcPs) where - nodeComments IEVar {} = emptyNodeComments - nodeComments (IEThingAbs _ x _) = nodeComments x - nodeComments (IEThingAll _ x _) = nodeComments x - nodeComments (IEThingWith _ x _ _ _) = nodeComments x - nodeComments (IEModuleContents (x, y) _) = - mconcat $ maybeToList (fmap nodeComments x) <> fmap nodeComments y - nodeComments IEGroup {} = emptyNodeComments - nodeComments IEDoc {} = emptyNodeComments - nodeComments IEDocNamed {} = emptyNodeComments + nodeComments = nodeCommentsIE + +nodeCommentsIE :: IE GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsIE IEVar {} = emptyNodeComments +nodeCommentsIE (IEThingAbs _ x _) = nodeComments x +nodeCommentsIE (IEThingAll _ x _) = nodeComments x +nodeCommentsIE (IEThingWith _ x _ _ _) = nodeComments x +nodeCommentsIE (IEModuleContents (x, y) _) = + mconcat $ maybeToList (fmap nodeComments x) <> fmap nodeComments y +nodeCommentsIE IEGroup {} = emptyNodeComments +nodeCommentsIE IEDoc {} = emptyNodeComments +nodeCommentsIE IEDocNamed {} = emptyNodeComments #elif MIN_VERSION_ghc_lib_parser(9, 8, 1) -instance CommentExtraction (IE GhcPs) where - nodeComments IEVar {} = emptyNodeComments - nodeComments (IEThingAbs (_, x) _) = nodeComments x - nodeComments (IEThingAll (_, x) _) = nodeComments x - nodeComments (IEThingWith (_, x) _ _ _) = nodeComments x - nodeComments (IEModuleContents (_, x) _) = nodeComments x - nodeComments IEGroup {} = emptyNodeComments - nodeComments IEDoc {} = emptyNodeComments - nodeComments IEDocNamed {} = emptyNodeComments +nodeCommentsIE IEVar {} = emptyNodeComments +nodeCommentsIE (IEThingAbs (_, x) _) = nodeComments x +nodeCommentsIE (IEThingAll (_, x) _) = nodeComments x +nodeCommentsIE (IEThingWith (_, x) _ _ _) = nodeComments x +nodeCommentsIE (IEModuleContents (_, x) _) = nodeComments x +nodeCommentsIE IEGroup {} = emptyNodeComments +nodeCommentsIE IEDoc {} = emptyNodeComments +nodeCommentsIE IEDocNamed {} = emptyNodeComments #else -instance CommentExtraction (IE GhcPs) where - nodeComments IEVar {} = emptyNodeComments - nodeComments (IEThingAbs x _) = nodeComments x - nodeComments (IEThingAll x _) = nodeComments x - nodeComments (IEThingWith x _ _ _) = nodeComments x - nodeComments (IEModuleContents x _) = nodeComments x - nodeComments IEGroup {} = emptyNodeComments - nodeComments IEDoc {} = emptyNodeComments - nodeComments IEDocNamed {} = emptyNodeComments +nodeCommentsIE IEVar {} = emptyNodeComments +nodeCommentsIE (IEThingAbs x _) = nodeComments x +nodeCommentsIE (IEThingAll x _) = nodeComments x +nodeCommentsIE (IEThingWith x _ _ _) = nodeComments x +nodeCommentsIE (IEModuleContents x _) = nodeComments x +nodeCommentsIE IEGroup {} = emptyNodeComments +nodeCommentsIE IEDoc {} = emptyNodeComments +nodeCommentsIE IEDocNamed {} = emptyNodeComments #endif #if MIN_VERSION_ghc_lib_parser(9, 10, 1) instance CommentExtraction From 66523398e1fe225da54171ae86f98e4209cf9523 Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 15:39:39 +0900 Subject: [PATCH 27/40] wip --- src/HIndent/Pretty/NodeComments.hs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index c313edcb6..7c878ed26 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -635,34 +635,26 @@ instance CommentExtraction (IE GhcPs) where nodeComments = nodeCommentsIE nodeCommentsIE :: IE GhcPs -> NodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) nodeCommentsIE IEVar {} = emptyNodeComments +nodeCommentsIE IEGroup {} = emptyNodeComments +nodeCommentsIE IEDoc {} = emptyNodeComments +nodeCommentsIE IEDocNamed {} = emptyNodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) nodeCommentsIE (IEThingAbs _ x _) = nodeComments x nodeCommentsIE (IEThingAll _ x _) = nodeComments x nodeCommentsIE (IEThingWith _ x _ _ _) = nodeComments x nodeCommentsIE (IEModuleContents (x, y) _) = mconcat $ maybeToList (fmap nodeComments x) <> fmap nodeComments y -nodeCommentsIE IEGroup {} = emptyNodeComments -nodeCommentsIE IEDoc {} = emptyNodeComments -nodeCommentsIE IEDocNamed {} = emptyNodeComments #elif MIN_VERSION_ghc_lib_parser(9, 8, 1) -nodeCommentsIE IEVar {} = emptyNodeComments nodeCommentsIE (IEThingAbs (_, x) _) = nodeComments x nodeCommentsIE (IEThingAll (_, x) _) = nodeComments x nodeCommentsIE (IEThingWith (_, x) _ _ _) = nodeComments x nodeCommentsIE (IEModuleContents (_, x) _) = nodeComments x -nodeCommentsIE IEGroup {} = emptyNodeComments -nodeCommentsIE IEDoc {} = emptyNodeComments -nodeCommentsIE IEDocNamed {} = emptyNodeComments #else -nodeCommentsIE IEVar {} = emptyNodeComments nodeCommentsIE (IEThingAbs x _) = nodeComments x nodeCommentsIE (IEThingAll x _) = nodeComments x nodeCommentsIE (IEThingWith x _ _ _) = nodeComments x nodeCommentsIE (IEModuleContents x _) = nodeComments x -nodeCommentsIE IEGroup {} = emptyNodeComments -nodeCommentsIE IEDoc {} = emptyNodeComments -nodeCommentsIE IEDocNamed {} = emptyNodeComments #endif #if MIN_VERSION_ghc_lib_parser(9, 10, 1) instance CommentExtraction From 148587a445f0f91ee32df3d1b90a931f4879fd14 Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 16:11:11 +0900 Subject: [PATCH 28/40] wip --- src/HIndent/Pretty/NodeComments.hs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index 7c878ed26..6d4874b02 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -656,14 +656,16 @@ nodeCommentsIE (IEThingAll x _) = nodeComments x nodeCommentsIE (IEThingWith x _ _ _) = nodeComments x nodeCommentsIE (IEModuleContents x _) = nodeComments x #endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) instance CommentExtraction (FamEqn GhcPs (GenLocated SrcSpanAnnA (HsType GhcPs))) where - nodeComments FamEqn {..} = mconcat $ fmap nodeComments feqn_ext + nodeComments = nodeCommentsFamEqn + +nodeCommentsFamEqn :: + FamEqn GhcPs (GenLocated SrcSpanAnnA (HsType GhcPs)) -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsFamEqn FamEqn {..} = mconcat $ fmap nodeComments feqn_ext #else -instance CommentExtraction - (FamEqn GhcPs (GenLocated SrcSpanAnnA (HsType GhcPs))) where - nodeComments FamEqn {..} = nodeComments feqn_ext +nodeCommentsFamEqn FamEqn {..} = nodeComments feqn_ext #endif instance CommentExtraction FamEqn' where nodeComments FamEqn' {..} = nodeComments famEqn From 454a8a07fbaa54fa35250ae9847e5d38e5b09fc6 Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 16:12:56 +0900 Subject: [PATCH 29/40] wip --- src/HIndent/Pretty/NodeComments.hs | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index 6d4874b02..a4081c785 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -656,12 +656,10 @@ nodeCommentsIE (IEThingAll x _) = nodeComments x nodeCommentsIE (IEThingWith x _ _ _) = nodeComments x nodeCommentsIE (IEModuleContents x _) = nodeComments x #endif -instance CommentExtraction - (FamEqn GhcPs (GenLocated SrcSpanAnnA (HsType GhcPs))) where +instance CommentExtraction (FamEqn GhcPs a) where nodeComments = nodeCommentsFamEqn -nodeCommentsFamEqn :: - FamEqn GhcPs (GenLocated SrcSpanAnnA (HsType GhcPs)) -> NodeComments +nodeCommentsFamEqn :: FamEqn GhcPs a -> NodeComments #if MIN_VERSION_ghc_lib_parser(9, 10, 1) nodeCommentsFamEqn FamEqn {..} = mconcat $ fmap nodeComments feqn_ext #else @@ -669,15 +667,6 @@ nodeCommentsFamEqn FamEqn {..} = nodeComments feqn_ext #endif instance CommentExtraction FamEqn' where nodeComments FamEqn' {..} = nodeComments famEqn -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) --- | Pretty-print a data instance. -instance CommentExtraction (FamEqn GhcPs (HsDataDefn GhcPs)) where - nodeComments FamEqn {..} = mconcat $ fmap nodeComments feqn_ext -#else --- | Pretty-print a data instance. -instance CommentExtraction (FamEqn GhcPs (HsDataDefn GhcPs)) where - nodeComments FamEqn {..} = nodeComments feqn_ext -#endif -- | HsArg (LHsType GhcPs) (LHsType GhcPs) #if MIN_VERSION_ghc_lib_parser(9,8,1) instance CommentExtraction From 8584828594a0888a50100c8a26cfcef9c736dd41 Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 16:17:18 +0900 Subject: [PATCH 30/40] wip --- src/HIndent/Pretty/NodeComments.hs | 40 +++++++++++++----------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index a4081c785..9210d1bff 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -668,7 +668,7 @@ nodeCommentsFamEqn FamEqn {..} = nodeComments feqn_ext instance CommentExtraction FamEqn' where nodeComments FamEqn' {..} = nodeComments famEqn -- | HsArg (LHsType GhcPs) (LHsType GhcPs) -#if MIN_VERSION_ghc_lib_parser(9,8,1) +#if MIN_VERSION_ghc_lib_parser(9, 8, 1) instance CommentExtraction (HsArg GhcPs @@ -686,7 +686,7 @@ instance CommentExtraction nodeComments HsTypeArg {} = emptyNodeComments nodeComments HsArgPar {} = emptyNodeComments #endif -#if MIN_VERSION_ghc_lib_parser(9,4,1) +#if MIN_VERSION_ghc_lib_parser(9, 4, 1) instance CommentExtraction (HsQuote GhcPs) where nodeComments ExpBr {} = emptyNodeComments nodeComments PatBr {} = emptyNodeComments @@ -695,41 +695,35 @@ instance CommentExtraction (HsQuote GhcPs) where nodeComments TypBr {} = emptyNodeComments nodeComments VarBr {} = emptyNodeComments #endif +instance CommentExtraction (WarnDecls GhcPs) where + nodeComments = nodeCommentsWarnDecls +nodeCommentsWarnDecls :: WarnDecls GhcPs -> NodeComments #if MIN_VERSION_ghc_lib_parser(9, 10, 1) -instance CommentExtraction (WarnDecls GhcPs) where - nodeComments Warnings {..} = mconcat $ fmap nodeComments $ fst wd_ext +nodeCommentsWarnDecls Warnings {..} = mconcat $ fmap nodeComments $ fst wd_ext #elif MIN_VERSION_ghc_lib_parser(9, 6, 1) -instance CommentExtraction (WarnDecls GhcPs) where - nodeComments Warnings {..} = nodeComments $ fst wd_ext +nodeCommentsWarnDecls Warnings {..} = nodeComments $ fst wd_ext #else -instance CommentExtraction (WarnDecls GhcPs) where - nodeComments Warnings {..} = nodeComments wd_ext +nodeCommentsWarnDecls Warnings {..} = nodeComments wd_ext #endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) instance CommentExtraction (WarnDecl GhcPs) where - nodeComments (Warning (_, x) _ _) = mconcat $ fmap nodeComments x + nodeComments = nodeCommentsWarnDecl + +nodeCommentsWarnDecl :: WarnDecl GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsWarnDecl (Warning (_, x) _ _) = mconcat $ fmap nodeComments x #else -instance CommentExtraction (WarnDecl GhcPs) where - nodeComments (Warning x _ _) = nodeComments x +nodeCommentsWarnDecl (Warning x _ _) = nodeComments x #endif -#if MIN_VERSION_ghc_lib_parser(9,4,1) +#if MIN_VERSION_ghc_lib_parser(9, 4, 1) instance CommentExtraction (WithHsDocIdentifiers StringLiteral GhcPs) where nodeComments WithHsDocIdentifiers {} = emptyNodeComments #endif -#if MIN_VERSION_ghc_lib_parser(9,6,1) -instance CommentExtraction (IEWrappedName GhcPs) where - nodeComments IEName {} = emptyNodeComments - nodeComments IEPattern {} = emptyNodeComments - nodeComments IEType {} = emptyNodeComments -#else --- | 'Pretty' for 'LIEWrappedName (IdP GhcPs)' -instance CommentExtraction (IEWrappedName RdrName) where +instance CommentExtraction (IEWrappedName a) where nodeComments IEName {} = emptyNodeComments nodeComments IEPattern {} = emptyNodeComments nodeComments IEType {} = emptyNodeComments -#endif -#if MIN_VERSION_ghc_lib_parser(9,4,1) +#if MIN_VERSION_ghc_lib_parser(9, 4, 1) instance CommentExtraction (DotFieldOcc GhcPs) where nodeComments DotFieldOcc {..} = nodeComments dfoExt #else From 7cdc86164900f5a0055f017dfc83dfc3cf3f9200 Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 16:19:51 +0900 Subject: [PATCH 31/40] wip --- src/HIndent/Pretty/NodeComments.hs | 34 +++++++++++++++++------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index 9210d1bff..b6ca75b12 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -730,34 +730,38 @@ instance CommentExtraction (DotFieldOcc GhcPs) where instance CommentExtraction (HsFieldLabel GhcPs) where nodeComments HsFieldLabel {..} = nodeComments hflExt #endif +instance CommentExtraction (RuleDecls GhcPs) where + nodeComments = nodeCommentsRuleDecls +nodeCommentsRuleDecls :: RuleDecls GhcPs -> NodeComments #if MIN_VERSION_ghc_lib_parser(9, 10, 1) -instance CommentExtraction (RuleDecls GhcPs) where - nodeComments HsRules {..} = mconcat $ fmap nodeComments $ fst rds_ext +nodeCommentsRuleDecls HsRules {..} = mconcat $ fmap nodeComments $ fst rds_ext #elif MIN_VERSION_ghc_lib_parser(9, 6, 1) -instance CommentExtraction (RuleDecls GhcPs) where - nodeComments HsRules {..} = nodeComments $ fst rds_ext +nodeCommentsRuleDecls HsRules {..} = nodeComments $ fst rds_ext #else -instance CommentExtraction (RuleDecls GhcPs) where - nodeComments HsRules {..} = nodeComments rds_ext +nodeCommentsRuleDecls HsRules {..} = nodeComments rds_ext #endif +instance CommentExtraction (RuleDecl GhcPs) where + nodeComments = nodeCommentsRuleDecl +nodeCommentsRuleDecl :: RuleDecl GhcPs -> NodeComments #if MIN_VERSION_ghc_lib_parser(9, 6, 1) -instance CommentExtraction (RuleDecl GhcPs) where - nodeComments HsRule {..} = nodeComments $ fst rd_ext +nodeCommentsRuleDecl HsRule {..} = nodeComments $ fst rd_ext #else -instance CommentExtraction (RuleDecl GhcPs) where - nodeComments HsRule {..} = nodeComments rd_ext +nodeCommentsRuleDecl HsRule {..} = nodeComments rd_ext #endif instance CommentExtraction OccName where nodeComments = const emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) + instance CommentExtraction (DerivDecl GhcPs) where - nodeComments DerivDecl {deriv_ext = (x, xs)} = - mconcat $ maybeToList (fmap nodeComments x) <> fmap nodeComments xs + nodeComments = nodeCommentsDerivDecl + +nodeCommentsDerivDecl :: DerivDecl GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsDerivDecl DerivDecl {deriv_ext = (x, xs)} = + mconcat $ maybeToList (fmap nodeComments x) <> fmap nodeComments xs #else -instance CommentExtraction (DerivDecl GhcPs) where - nodeComments DerivDecl {..} = nodeComments deriv_ext +nodeCommentsDerivDecl DerivDecl {..} = nodeComments deriv_ext #endif -- | 'Pretty' for 'LHsSigWcType GhcPs'. instance CommentExtraction From 172b00e9e97c8ca6dd5aeaf43aeb174ec25b10a9 Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 16:22:04 +0900 Subject: [PATCH 32/40] wip --- src/HIndent/Pretty/NodeComments.hs | 39 +++++++++++++++++++----------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index b6ca75b12..15e6900c3 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -772,29 +772,40 @@ instance CommentExtraction instance CommentExtraction (HsWildCardBndrs GhcPs (GenLocated SrcSpanAnnA (HsType GhcPs))) where nodeComments HsWC {} = emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) + instance CommentExtraction (StandaloneKindSig GhcPs) where - nodeComments (StandaloneKindSig x _ _) = mconcat $ fmap nodeComments x + nodeComments = nodeCommentsStandaloneKindSig + +nodeCommentsStandaloneKindSig :: StandaloneKindSig GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsStandaloneKindSig (StandaloneKindSig x _ _) = + mconcat $ fmap nodeComments x #else -instance CommentExtraction (StandaloneKindSig GhcPs) where - nodeComments (StandaloneKindSig x _ _) = nodeComments x +nodeCommentsStandaloneKindSig (StandaloneKindSig x _ _) = nodeComments x #endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) instance CommentExtraction (DefaultDecl GhcPs) where - nodeComments (DefaultDecl x _) = mconcat $ fmap nodeComments x + nodeComments = nodeCommentsDefaultDecl + +nodeCommentsDefaultDecl :: DefaultDecl GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsDefaultDecl (DefaultDecl x _) = mconcat $ fmap nodeComments x #else -instance CommentExtraction (DefaultDecl GhcPs) where - nodeComments (DefaultDecl x _) = nodeComments x +nodeCommentsDefaultDecl (DefaultDecl x _) = nodeComments x #endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) instance CommentExtraction (ForeignDecl GhcPs) where - nodeComments ForeignImport {..} = mconcat $ fmap nodeComments fd_i_ext - nodeComments ForeignExport {..} = mconcat $ fmap nodeComments fd_e_ext + nodeComments = nodeCommentsForeignDecl + +nodeCommentsForeignDecl :: ForeignDecl GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsForeignDecl ForeignImport {..} = + mconcat $ fmap nodeComments fd_i_ext +nodeCommentsForeignDecl ForeignExport {..} = + mconcat $ fmap nodeComments fd_e_ext #else -instance CommentExtraction (ForeignDecl GhcPs) where - nodeComments ForeignImport {..} = nodeComments fd_i_ext - nodeComments ForeignExport {..} = nodeComments fd_e_ext +nodeCommentsForeignDecl ForeignImport {..} = nodeComments fd_i_ext +nodeCommentsForeignDecl ForeignExport {..} = nodeComments fd_e_ext #endif + #if MIN_VERSION_ghc_lib_parser(9, 6, 1) instance CommentExtraction (ForeignImport GhcPs) where nodeComments CImport {} = emptyNodeComments From dccc5411ff04cd955c1ab954507054c9081acf29 Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 16:24:08 +0900 Subject: [PATCH 33/40] wip --- src/HIndent/Pretty/NodeComments.hs | 41 +++++++++++++++++------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index 15e6900c3..1c1f729f4 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -809,15 +809,13 @@ nodeCommentsForeignDecl ForeignExport {..} = nodeComments fd_e_ext #if MIN_VERSION_ghc_lib_parser(9, 6, 1) instance CommentExtraction (ForeignImport GhcPs) where nodeComments CImport {} = emptyNodeComments -#else -instance CommentExtraction ForeignImport where - nodeComments CImport {} = emptyNodeComments -#endif -#if MIN_VERSION_ghc_lib_parser(9,6,1) instance CommentExtraction (ForeignExport GhcPs) where nodeComments CExport {} = emptyNodeComments #else +instance CommentExtraction ForeignImport where + nodeComments CImport {} = emptyNodeComments + instance CommentExtraction ForeignExport where nodeComments CExport {} = emptyNodeComments #endif @@ -828,30 +826,39 @@ instance CommentExtraction Safety where nodeComments PlaySafe = emptyNodeComments nodeComments PlayInterruptible = emptyNodeComments nodeComments PlayRisky = emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9,6,1) + instance CommentExtraction (AnnDecl GhcPs) where - nodeComments (HsAnnotation (x, _) _ _) = nodeComments x + nodeComments = nodeCommentsAnnDecl + +nodeCommentsAnnDecl :: AnnDecl GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 6, 1) +nodeCommentsAnnDecl (HsAnnotation (x, _) _ _) = nodeComments x #else -instance CommentExtraction (AnnDecl GhcPs) where - nodeComments (HsAnnotation x _ _ _) = nodeComments x +nodeCommentsAnnDecl (HsAnnotation x _ _ _) = nodeComments x #endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) instance CommentExtraction (RoleAnnotDecl GhcPs) where - nodeComments (RoleAnnotDecl x _ _) = mconcat $ fmap nodeComments x + nodeComments = nodeCommentsRoleAnnotDecl + +nodeCommentsRoleAnnotDecl :: RoleAnnotDecl GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsRoleAnnotDecl (RoleAnnotDecl x _ _) = mconcat $ fmap nodeComments x #else -instance CommentExtraction (RoleAnnotDecl GhcPs) where - nodeComments (RoleAnnotDecl x _ _) = nodeComments x +nodeCommentsRoleAnnotDecl (RoleAnnotDecl x _ _) = nodeComments x #endif instance CommentExtraction Role where nodeComments Nominal = emptyNodeComments nodeComments Representational = emptyNodeComments nodeComments Phantom = emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) + instance CommentExtraction (TyFamInstDecl GhcPs) where - nodeComments TyFamInstDecl {..} = mconcat $ fmap nodeComments tfid_xtn + nodeComments = nodeCommentsTyFamInstDecl + +nodeCommentsTyFamInstDecl :: TyFamInstDecl GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsTyFamInstDecl TyFamInstDecl {..} = + mconcat $ fmap nodeComments tfid_xtn #else -instance CommentExtraction (TyFamInstDecl GhcPs) where - nodeComments TyFamInstDecl {..} = nodeComments tfid_xtn +nodeCommentsTyFamInstDecl TyFamInstDecl {..} = nodeComments tfid_xtn #endif instance CommentExtraction TopLevelTyFamInstDecl where nodeComments (TopLevelTyFamInstDecl x) = nodeComments x From 46ea9d4ee6c9c2e5b9c2c099cff54d38a6af709e Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 17:45:36 +0900 Subject: [PATCH 34/40] wip --- src/HIndent/Pretty/NodeComments.hs | 103 +++++++++++++++++------------ 1 file changed, 61 insertions(+), 42 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index 1c1f729f4..725d36ddf 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -868,12 +868,15 @@ instance CommentExtraction (DataFamInstDecl GhcPs) where instance CommentExtraction DataFamInstDecl' where nodeComments DataFamInstDecl' {..} = nodeComments dataFamInstDecl -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) + instance CommentExtraction (PatSynBind GhcPs GhcPs) where - nodeComments PSB {..} = mconcat $ fmap nodeComments psb_ext + nodeComments = nodeCommentsPatSynBind + +nodeCommentsPatSynBind :: PatSynBind GhcPs GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsPatSynBind PSB {..} = mconcat $ fmap nodeComments psb_ext #else -instance CommentExtraction (PatSynBind GhcPs GhcPs) where - nodeComments PSB {..} = nodeComments psb_ext +nodeCommentsPatSynBind PSB {..} = nodeComments psb_ext #endif -- | 'Pretty' for 'HsPatSynDetails'. instance CommentExtraction @@ -907,7 +910,7 @@ nodeCommentsInlineSpec Inline {} = emptyNodeComments nodeCommentsInlineSpec Inlinable {} = emptyNodeComments nodeCommentsInlineSpec NoInline {} = emptyNodeComments nodeCommentsInlineSpec NoUserInlinePrag {} = emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9,4,1) +#if MIN_VERSION_ghc_lib_parser(9, 4, 1) nodeCommentsInlineSpec Opaque {} = emptyNodeComments #endif instance CommentExtraction (HsPatSynDir GhcPs) where @@ -943,16 +946,19 @@ instance CommentExtraction (HsLit GhcPs) where nodeComments HsRat {} = emptyNodeComments nodeComments HsFloatPrim {} = emptyNodeComments nodeComments HsDoublePrim {} = emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9,6,1) + instance CommentExtraction (HsPragE GhcPs) where - nodeComments (HsPragSCC (x, _) _) = nodeComments x + nodeComments = nodeCommentsHsPragE + +nodeCommentsHsPragE :: HsPragE GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 6, 1) +nodeCommentsHsPragE (HsPragSCC (x, _) _) = nodeComments x #else -instance CommentExtraction (HsPragE GhcPs) where - nodeComments (HsPragSCC x _ _) = nodeComments x +nodeCommentsHsPragE (HsPragSCC x _) = nodeComments x #endif instance CommentExtraction HsIPName where nodeComments HsIPName {} = emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9,6,1) +#if MIN_VERSION_ghc_lib_parser(9, 6, 1) instance CommentExtraction (HsTyLit GhcPs) where nodeComments HsNumTy {} = emptyNodeComments nodeComments HsStrTy {} = emptyNodeComments @@ -968,32 +974,38 @@ instance CommentExtraction (HsPatSigType GhcPs) where instance CommentExtraction (HsIPBinds GhcPs) where nodeComments IPBinds {} = emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) + instance CommentExtraction (IPBind GhcPs) where - nodeComments (IPBind x _ _) = mconcat $ fmap nodeComments x + nodeComments = nodeCommentsIPBind + +nodeCommentsIPBind :: IPBind GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsIPBind (IPBind x _ _) = mconcat $ fmap nodeComments x #else -instance CommentExtraction (IPBind GhcPs) where - nodeComments (IPBind x _ _) = nodeComments x +nodeCommentsIPBind (IPBind x _ _) = nodeComments x #endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) instance CommentExtraction (DerivStrategy GhcPs) where - nodeComments (StockStrategy x) = mconcat $ fmap nodeComments x - nodeComments (AnyclassStrategy x) = mconcat $ fmap nodeComments x - nodeComments (NewtypeStrategy x) = mconcat $ fmap nodeComments x - nodeComments (ViaStrategy x) = nodeComments x + nodeComments = nodeCommentsDerivStrategy + +nodeCommentsDerivStrategy :: DerivStrategy GhcPs -> NodeComments +nodeCommentsDerivStrategy (ViaStrategy x) = nodeComments x +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsDerivStrategy (StockStrategy x) = mconcat $ fmap nodeComments x +nodeCommentsDerivStrategy (AnyclassStrategy x) = mconcat $ fmap nodeComments x +nodeCommentsDerivStrategy (NewtypeStrategy x) = mconcat $ fmap nodeComments x #else -instance CommentExtraction (DerivStrategy GhcPs) where - nodeComments (StockStrategy x) = nodeComments x - nodeComments (AnyclassStrategy x) = nodeComments x - nodeComments (NewtypeStrategy x) = nodeComments x - nodeComments (ViaStrategy x) = nodeComments x +nodeCommentsDerivStrategy (StockStrategy x) = nodeComments x +nodeCommentsDerivStrategy (AnyclassStrategy x) = nodeComments x +nodeCommentsDerivStrategy (NewtypeStrategy x) = nodeComments x #endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) instance CommentExtraction XViaStrategyPs where - nodeComments (XViaStrategyPs x _) = mconcat $ fmap nodeComments x + nodeComments = nodeCommentsXViaStrategyPs + +nodeCommentsXViaStrategyPs :: XViaStrategyPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsXViaStrategyPs (XViaStrategyPs x _) = mconcat $ fmap nodeComments x #else -instance CommentExtraction XViaStrategyPs where - nodeComments (XViaStrategyPs x _) = nodeComments x +nodeCommentsXViaStrategyPs (XViaStrategyPs x _) = nodeComments x #endif instance CommentExtraction (RecordPatSynField GhcPs) where nodeComments RecordPatSynField {} = emptyNodeComments @@ -1046,14 +1058,17 @@ instance CommentExtraction DoExpression where instance CommentExtraction LetIn where nodeComments LetIn {} = emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) + instance CommentExtraction (RuleBndr GhcPs) where - nodeComments (RuleBndr x _) = mconcat $ fmap nodeComments x - nodeComments (RuleBndrSig x _ _) = mconcat $ fmap nodeComments x + nodeComments = nodeCommentsRuleBndr + +nodeCommentsRuleBndr :: RuleBndr GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsRuleBndr (RuleBndr x _) = mconcat $ fmap nodeComments x +nodeCommentsRuleBndr (RuleBndrSig x _ _) = mconcat $ fmap nodeComments x #else -instance CommentExtraction (RuleBndr GhcPs) where - nodeComments (RuleBndr x _) = nodeComments x - nodeComments (RuleBndrSig x _ _) = nodeComments x +nodeCommentsRuleBndr (RuleBndr x _) = nodeComments x +nodeCommentsRuleBndr (RuleBndrSig x _ _) = nodeComments x #endif instance CommentExtraction CCallConv where nodeComments = const emptyNodeComments @@ -1079,17 +1094,21 @@ instance CommentExtraction FieldLabelString where nodeComments = const emptyNodeComments #endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -instance CommentExtraction (HsUntypedSplice GhcPs) where - nodeComments (HsUntypedSpliceExpr x _) = mconcat $ fmap nodeComments x - nodeComments HsQuasiQuote {} = emptyNodeComments -#elif MIN_VERSION_ghc_lib_parser(9, 6, 1) +#if MIN_VERSION_ghc_lib_parser(9, 6, 1) instance CommentExtraction (HsUntypedSplice GhcPs) where - nodeComments (HsUntypedSpliceExpr x _) = nodeComments x - nodeComments HsQuasiQuote {} = emptyNodeComments + nodeComments = nodeCommentsHsUntypedSplice + +nodeCommentsHsUntypedSplice :: HsUntypedSplice GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsHsUntypedSplice (HsUntypedSpliceExpr x _) = + mconcat $ fmap nodeComments x +#else +nodeCommentsHsUntypedSplice (HsUntypedSpliceExpr x) = nodeComments x +#endif +nodeCommentsHsUntypedSplice HsQuasiQuote {} = emptyNodeComments #endif -#if MIN_VERSION_ghc_lib_parser(9,8,1) +#if MIN_VERSION_ghc_lib_parser(9, 8, 1) instance CommentExtraction (LHsRecUpdFields GhcPs) where nodeComments RegularRecUpdFields {} = emptyNodeComments nodeComments OverloadedRecUpdFields {} = emptyNodeComments From 7c08458b197849b2df74c42085aab4f1eeee6b8e Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 18:20:05 +0900 Subject: [PATCH 35/40] wip --- src/HIndent/Pretty/NodeComments.hs | 139 +++++++++++++---------------- 1 file changed, 64 insertions(+), 75 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index 725d36ddf..252b06396 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -1019,37 +1019,27 @@ instance CommentExtraction (HsCmd GhcPs) where nodeCommentsHsCmd :: HsCmd GhcPs -> NodeComments nodeCommentsHsCmd (HsCmdArrApp x _ _ _ _) = nodeComments x nodeCommentsHsCmd (HsCmdArrForm x _ _ _ _) = nodeComments x +nodeCommentsHsCmd HsCmdLam {} = emptyNodeComments +nodeCommentsHsCmd (HsCmdCase x _ _) = nodeComments x +nodeCommentsHsCmd (HsCmdIf x _ _ _ _) = nodeComments x +nodeCommentsHsCmd (HsCmdDo x _) = nodeComments x #if MIN_VERSION_ghc_lib_parser(9, 10, 1) nodeCommentsHsCmd HsCmdApp {} = emptyNodeComments #else nodeCommentsHsCmd (HsCmdApp x _ _) = nodeComments x #endif -nodeCommentsHsCmd HsCmdLam {} = emptyNodeComments #if MIN_VERSION_ghc_lib_parser(9, 10, 1) nodeCommentsHsCmd HsCmdPar {} = emptyNodeComments +nodeCommentsHsCmd HsCmdLet {} = emptyNodeComments #elif MIN_VERSION_ghc_lib_parser(9, 4, 1) nodeCommentsHsCmd (HsCmdPar x _ _ _) = nodeComments x -#else -nodeCommentsHsCmd (HsCmdPar x _) = nodeComments x -#endif -nodeCommentsHsCmd (HsCmdCase x _ _) = nodeComments x -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) --- No HsCmdLamCase since 9.10.1. -#elif MIN_VERSION_ghc_lib_parser(9, 4, 1) nodeCommentsHsCmd (HsCmdLamCase x _ _) = nodeComments x -#else -nodeCommentsHsCmd (HsCmdLamCase x _) = nodeComments x -#endif -nodeCommentsHsCmd (HsCmdIf x _ _ _ _) = nodeComments x -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsCmd HsCmdLet {} = emptyNodeComments -#elif MIN_VERSION_ghc_lib_parser(9, 4, 1) nodeCommentsHsCmd (HsCmdLet x _ _ _ _) = nodeComments x #else +nodeCommentsHsCmd (HsCmdPar x _) = nodeComments x +nodeCommentsHsCmd (HsCmdLamCase x _) = nodeComments x nodeCommentsHsCmd (HsCmdLet x _ _) = nodeComments x #endif -nodeCommentsHsCmd (HsCmdDo x _) = nodeComments x - instance CommentExtraction ListComprehension where nodeComments ListComprehension {} = emptyNodeComments @@ -1059,17 +1049,6 @@ instance CommentExtraction DoExpression where instance CommentExtraction LetIn where nodeComments LetIn {} = emptyNodeComments -instance CommentExtraction (RuleBndr GhcPs) where - nodeComments = nodeCommentsRuleBndr - -nodeCommentsRuleBndr :: RuleBndr GhcPs -> NodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsRuleBndr (RuleBndr x _) = mconcat $ fmap nodeComments x -nodeCommentsRuleBndr (RuleBndrSig x _ _) = mconcat $ fmap nodeComments x -#else -nodeCommentsRuleBndr (RuleBndr x _) = nodeComments x -nodeCommentsRuleBndr (RuleBndrSig x _ _) = nodeComments x -#endif instance CommentExtraction CCallConv where nodeComments = const emptyNodeComments @@ -1089,41 +1068,14 @@ instance CommentExtraction SrcStrictness where instance CommentExtraction (HsOuterSigTyVarBndrs GhcPs) where nodeComments HsOuterImplicit {} = emptyNodeComments nodeComments HsOuterExplicit {..} = nodeComments hso_xexplicit -#if MIN_VERSION_ghc_lib_parser(9, 6, 1) -instance CommentExtraction FieldLabelString where - nodeComments = const emptyNodeComments -#endif - -#if MIN_VERSION_ghc_lib_parser(9, 6, 1) -instance CommentExtraction (HsUntypedSplice GhcPs) where - nodeComments = nodeCommentsHsUntypedSplice - -nodeCommentsHsUntypedSplice :: HsUntypedSplice GhcPs -> NodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsUntypedSplice (HsUntypedSpliceExpr x _) = - mconcat $ fmap nodeComments x -#else -nodeCommentsHsUntypedSplice (HsUntypedSpliceExpr x) = nodeComments x -#endif -nodeCommentsHsUntypedSplice HsQuasiQuote {} = emptyNodeComments -#endif -#if MIN_VERSION_ghc_lib_parser(9, 8, 1) -instance CommentExtraction (LHsRecUpdFields GhcPs) where - nodeComments RegularRecUpdFields {} = emptyNodeComments - nodeComments OverloadedRecUpdFields {} = emptyNodeComments -#endif instance CommentExtraction AddEpAnn where nodeComments (AddEpAnn _ x) = nodeComments x instance CommentExtraction EpaLocation where nodeComments EpaSpan {} = emptyNodeComments nodeComments (EpaDelta _ x) = mconcat $ fmap nodeComments x -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -instance CommentExtraction (EpaLocation' NoComments) where - nodeComments EpaSpan {} = emptyNodeComments - nodeComments EpaDelta {} = emptyNodeComments -#endif + instance CommentExtraction AnnPragma where nodeComments AnnPragma {..} = mconcat $ fmap nodeComments $ apr_open : apr_close : apr_rest @@ -1145,26 +1097,7 @@ instance CommentExtraction EpAnnSumPat where $ fmap nodeComments sumPatParens <> fmap nodeComments sumPatVbarsBefore <> fmap nodeComments sumPatVbarsAfter -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -instance CommentExtraction AnnList where - nodeComments AnnList {..} = mconcat [a, b, c, d, e] - where - a = maybe mempty nodeComments al_anchor - b = maybe mempty nodeComments al_open - c = maybe mempty nodeComments al_close - d = mconcat $ fmap nodeComments al_rest - e = mconcat $ fmap nodeComments al_trailing - -instance CommentExtraction TrailingAnn where - nodeComments AddSemiAnn {..} = nodeComments ta_location - nodeComments AddCommaAnn {..} = nodeComments ta_location - nodeComments AddVbarAnn {..} = nodeComments ta_location - nodeComments AddDarrowAnn {..} = nodeComments ta_location - nodeComments AddDarrowUAnn {..} = nodeComments ta_location -instance CommentExtraction AnnParen where - nodeComments AnnParen {..} = mconcat $ fmap nodeComments [ap_open, ap_close] -#endif instance CommentExtraction AnnProjection where nodeComments AnnProjection {..} = mconcat $ fmap nodeComments [apOpen, apClose] @@ -1201,6 +1134,62 @@ instance CommentExtraction EpAnnUnboundVar where instance CommentExtraction AnnSig where nodeComments AnnSig {..} = mconcat $ fmap nodeComments $ asDcolon : asRest +instance CommentExtraction (RuleBndr GhcPs) where + nodeComments = nodeCommentsRuleBndr + +nodeCommentsRuleBndr :: RuleBndr GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsRuleBndr (RuleBndr x _) = mconcat $ fmap nodeComments x +nodeCommentsRuleBndr (RuleBndrSig x _ _) = mconcat $ fmap nodeComments x +#else +nodeCommentsRuleBndr (RuleBndr x _) = nodeComments x +nodeCommentsRuleBndr (RuleBndrSig x _ _) = nodeComments x +#endif +#if MIN_VERSION_ghc_lib_parser(9, 6, 1) +instance CommentExtraction FieldLabelString where + nodeComments = const emptyNodeComments + +instance CommentExtraction (HsUntypedSplice GhcPs) where + nodeComments = nodeCommentsHsUntypedSplice + +nodeCommentsHsUntypedSplice :: HsUntypedSplice GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsHsUntypedSplice (HsUntypedSpliceExpr x _) = + mconcat $ fmap nodeComments x +#else +nodeCommentsHsUntypedSplice (HsUntypedSpliceExpr x) = nodeComments x +#endif +nodeCommentsHsUntypedSplice HsQuasiQuote {} = emptyNodeComments +#endif +#if MIN_VERSION_ghc_lib_parser(9, 8, 1) +instance CommentExtraction (LHsRecUpdFields GhcPs) where + nodeComments RegularRecUpdFields {} = emptyNodeComments + nodeComments OverloadedRecUpdFields {} = emptyNodeComments +#endif +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +instance CommentExtraction (EpaLocation' NoComments) where + nodeComments EpaSpan {} = emptyNodeComments + nodeComments EpaDelta {} = emptyNodeComments + +instance CommentExtraction AnnList where + nodeComments AnnList {..} = mconcat [a, b, c, d, e] + where + a = maybe mempty nodeComments al_anchor + b = maybe mempty nodeComments al_open + c = maybe mempty nodeComments al_close + d = mconcat $ fmap nodeComments al_rest + e = mconcat $ fmap nodeComments al_trailing + +instance CommentExtraction TrailingAnn where + nodeComments AddSemiAnn {..} = nodeComments ta_location + nodeComments AddCommaAnn {..} = nodeComments ta_location + nodeComments AddVbarAnn {..} = nodeComments ta_location + nodeComments AddDarrowAnn {..} = nodeComments ta_location + nodeComments AddDarrowUAnn {..} = nodeComments ta_location + +instance CommentExtraction AnnParen where + nodeComments AnnParen {..} = mconcat $ fmap nodeComments [ap_open, ap_close] +#endif -- | Marks an AST node as never appearing in the AST. -- -- Some AST node types are only used in the renaming or type-checking phase. From cfb7098e6016a3d9cfa7717a07781369f33f8383 Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 18:28:55 +0900 Subject: [PATCH 36/40] wip --- src/HIndent/Pretty/NodeComments.hs | 702 ++++++++++++++--------------- 1 file changed, 349 insertions(+), 353 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index 252b06396..57aa6d62d 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -480,20 +480,6 @@ instance CommentExtraction (HsRecField' (FieldOcc GhcPs) (GenLocated SrcSpanAnnA (HsExpr GhcPs))) where nodeComments HsRecField {..} = nodeComments hsRecFieldAnn #endif -#if MIN_VERSION_ghc_lib_parser(9, 4, 1) -instance CommentExtraction (HsFieldBind a b) where - nodeComments = nodeCommentsHsFieldBind - -nodeCommentsHsFieldBind :: HsFieldBind a b -> NodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsFieldBind HsFieldBind {..} = mconcat $ fmap nodeComments hfbAnn -#else -nodeCommentsHsFieldBind HsFieldBind {..} = nodeComments hfbAnn -#endif -#else -instance CommentExtraction RecConField where - nodeComments (RecConField x) = nodeComments x -#endif instance CommentExtraction (FieldOcc GhcPs) where nodeComments FieldOcc {} = emptyNodeComments @@ -512,16 +498,6 @@ instance CommentExtraction instance CommentExtraction (HsScaled GhcPs a) where nodeComments HsScaled {} = emptyNodeComments -instance CommentExtraction (ConDeclField GhcPs) where - nodeComments = nodeCommentsConDeclField - -nodeCommentsConDeclField :: ConDeclField GhcPs -> NodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsConDeclField ConDeclField {..} = - mconcat $ fmap nodeComments cd_fld_ext -#else -nodeCommentsConDeclField ConDeclField {..} = nodeComments cd_fld_ext -#endif instance CommentExtraction InfixExpr where nodeComments (InfixExpr x) = nodeComments x @@ -543,21 +519,7 @@ instance CommentExtraction (AmbiguousFieldOcc GhcPs) where instance CommentExtraction (ImportDecl GhcPs) where nodeComments ImportDecl {..} = nodeComments ideclExt -#if MIN_VERSION_ghc_lib_parser(9, 6, 1) -instance CommentExtraction XImportDeclPass where - nodeComments XImportDeclPass {..} = nodeComments ideclAnn -#endif -instance CommentExtraction (HsDerivingClause GhcPs) where - nodeComments = nodeCommentsHsDerivingClause -nodeCommentsHsDerivingClause :: HsDerivingClause GhcPs -> NodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsDerivingClause HsDerivingClause {..} = - mconcat $ fmap nodeComments deriv_clause_ext -#else -nodeCommentsHsDerivingClause HsDerivingClause {..} = - nodeComments deriv_clause_ext -#endif instance CommentExtraction (DerivClauseTys GhcPs) where nodeComments DctSingle {} = emptyNodeComments nodeComments DctMulti {} = emptyNodeComments @@ -572,32 +534,11 @@ instance CommentExtraction OverlapMode where instance CommentExtraction StringLiteral where nodeComments StringLiteral {} = emptyNodeComments --- | This instance is for type family declarations inside a class declaration. -instance CommentExtraction (FamilyDecl GhcPs) where - nodeComments = nodeCommentsFamilyDecl - -nodeCommentsFamilyDecl :: FamilyDecl GhcPs -> NodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsFamilyDecl FamilyDecl {..} = mconcat $ fmap nodeComments fdExt -#else -nodeCommentsFamilyDecl FamilyDecl {..} = nodeComments fdExt -#endif instance CommentExtraction (FamilyResultSig GhcPs) where nodeComments NoSig {} = emptyNodeComments nodeComments KindSig {} = emptyNodeComments nodeComments TyVarSig {} = emptyNodeComments -instance CommentExtraction (HsTyVarBndr a GhcPs) where - nodeComments = nodeCommentsHsTyVarBndr - -nodeCommentsHsTyVarBndr :: HsTyVarBndr a GhcPs -> NodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsTyVarBndr (UserTyVar x _ _) = mconcat $ fmap nodeComments x -nodeCommentsHsTyVarBndr (KindedTyVar x _ _ _) = mconcat $ fmap nodeComments x -#else -nodeCommentsHsTyVarBndr (UserTyVar x _ _) = nodeComments x -nodeCommentsHsTyVarBndr (KindedTyVar x _ _ _) = nodeComments x -#endif instance CommentExtraction (ArithSeqInfo GhcPs) where nodeComments From {} = emptyNodeComments nodeComments FromThen {} = emptyNodeComments @@ -631,138 +572,17 @@ instance CommentExtraction ModuleName where instance CommentExtraction ModuleNameWithPrefix where nodeComments ModuleNameWithPrefix {} = emptyNodeComments -instance CommentExtraction (IE GhcPs) where - nodeComments = nodeCommentsIE - -nodeCommentsIE :: IE GhcPs -> NodeComments -nodeCommentsIE IEVar {} = emptyNodeComments -nodeCommentsIE IEGroup {} = emptyNodeComments -nodeCommentsIE IEDoc {} = emptyNodeComments -nodeCommentsIE IEDocNamed {} = emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsIE (IEThingAbs _ x _) = nodeComments x -nodeCommentsIE (IEThingAll _ x _) = nodeComments x -nodeCommentsIE (IEThingWith _ x _ _ _) = nodeComments x -nodeCommentsIE (IEModuleContents (x, y) _) = - mconcat $ maybeToList (fmap nodeComments x) <> fmap nodeComments y -#elif MIN_VERSION_ghc_lib_parser(9, 8, 1) -nodeCommentsIE (IEThingAbs (_, x) _) = nodeComments x -nodeCommentsIE (IEThingAll (_, x) _) = nodeComments x -nodeCommentsIE (IEThingWith (_, x) _ _ _) = nodeComments x -nodeCommentsIE (IEModuleContents (_, x) _) = nodeComments x -#else -nodeCommentsIE (IEThingAbs x _) = nodeComments x -nodeCommentsIE (IEThingAll x _) = nodeComments x -nodeCommentsIE (IEThingWith x _ _ _) = nodeComments x -nodeCommentsIE (IEModuleContents x _) = nodeComments x -#endif -instance CommentExtraction (FamEqn GhcPs a) where - nodeComments = nodeCommentsFamEqn - -nodeCommentsFamEqn :: FamEqn GhcPs a -> NodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsFamEqn FamEqn {..} = mconcat $ fmap nodeComments feqn_ext -#else -nodeCommentsFamEqn FamEqn {..} = nodeComments feqn_ext -#endif instance CommentExtraction FamEqn' where nodeComments FamEqn' {..} = nodeComments famEqn --- | HsArg (LHsType GhcPs) (LHsType GhcPs) -#if MIN_VERSION_ghc_lib_parser(9, 8, 1) -instance CommentExtraction - (HsArg - GhcPs - (GenLocated SrcSpanAnnA (HsType GhcPs)) - (GenLocated SrcSpanAnnA (HsType GhcPs))) where - nodeComments HsValArg {} = emptyNodeComments - nodeComments HsTypeArg {} = emptyNodeComments - nodeComments HsArgPar {} = emptyNodeComments -#else -instance CommentExtraction - (HsArg - (GenLocated SrcSpanAnnA (HsType GhcPs)) - (GenLocated SrcSpanAnnA (HsType GhcPs))) where - nodeComments HsValArg {} = emptyNodeComments - nodeComments HsTypeArg {} = emptyNodeComments - nodeComments HsArgPar {} = emptyNodeComments -#endif -#if MIN_VERSION_ghc_lib_parser(9, 4, 1) -instance CommentExtraction (HsQuote GhcPs) where - nodeComments ExpBr {} = emptyNodeComments - nodeComments PatBr {} = emptyNodeComments - nodeComments DecBrL {} = emptyNodeComments - nodeComments DecBrG {} = emptyNodeComments - nodeComments TypBr {} = emptyNodeComments - nodeComments VarBr {} = emptyNodeComments -#endif -instance CommentExtraction (WarnDecls GhcPs) where - nodeComments = nodeCommentsWarnDecls - -nodeCommentsWarnDecls :: WarnDecls GhcPs -> NodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsWarnDecls Warnings {..} = mconcat $ fmap nodeComments $ fst wd_ext -#elif MIN_VERSION_ghc_lib_parser(9, 6, 1) -nodeCommentsWarnDecls Warnings {..} = nodeComments $ fst wd_ext -#else -nodeCommentsWarnDecls Warnings {..} = nodeComments wd_ext -#endif -instance CommentExtraction (WarnDecl GhcPs) where - nodeComments = nodeCommentsWarnDecl -nodeCommentsWarnDecl :: WarnDecl GhcPs -> NodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsWarnDecl (Warning (_, x) _ _) = mconcat $ fmap nodeComments x -#else -nodeCommentsWarnDecl (Warning x _ _) = nodeComments x -#endif -#if MIN_VERSION_ghc_lib_parser(9, 4, 1) -instance CommentExtraction (WithHsDocIdentifiers StringLiteral GhcPs) where - nodeComments WithHsDocIdentifiers {} = emptyNodeComments -#endif instance CommentExtraction (IEWrappedName a) where nodeComments IEName {} = emptyNodeComments nodeComments IEPattern {} = emptyNodeComments nodeComments IEType {} = emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9, 4, 1) -instance CommentExtraction (DotFieldOcc GhcPs) where - nodeComments DotFieldOcc {..} = nodeComments dfoExt -#else -instance CommentExtraction (HsFieldLabel GhcPs) where - nodeComments HsFieldLabel {..} = nodeComments hflExt -#endif -instance CommentExtraction (RuleDecls GhcPs) where - nodeComments = nodeCommentsRuleDecls - -nodeCommentsRuleDecls :: RuleDecls GhcPs -> NodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsRuleDecls HsRules {..} = mconcat $ fmap nodeComments $ fst rds_ext -#elif MIN_VERSION_ghc_lib_parser(9, 6, 1) -nodeCommentsRuleDecls HsRules {..} = nodeComments $ fst rds_ext -#else -nodeCommentsRuleDecls HsRules {..} = nodeComments rds_ext -#endif -instance CommentExtraction (RuleDecl GhcPs) where - nodeComments = nodeCommentsRuleDecl -nodeCommentsRuleDecl :: RuleDecl GhcPs -> NodeComments -#if MIN_VERSION_ghc_lib_parser(9, 6, 1) -nodeCommentsRuleDecl HsRule {..} = nodeComments $ fst rd_ext -#else -nodeCommentsRuleDecl HsRule {..} = nodeComments rd_ext -#endif instance CommentExtraction OccName where nodeComments = const emptyNodeComments -instance CommentExtraction (DerivDecl GhcPs) where - nodeComments = nodeCommentsDerivDecl - -nodeCommentsDerivDecl :: DerivDecl GhcPs -> NodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsDerivDecl DerivDecl {deriv_ext = (x, xs)} = - mconcat $ maybeToList (fmap nodeComments x) <> fmap nodeComments xs -#else -nodeCommentsDerivDecl DerivDecl {..} = nodeComments deriv_ext -#endif -- | 'Pretty' for 'LHsSigWcType GhcPs'. instance CommentExtraction (HsWildCardBndrs GhcPs (GenLocated SrcSpanAnnA (HsSigType GhcPs))) where @@ -773,52 +593,6 @@ instance CommentExtraction (HsWildCardBndrs GhcPs (GenLocated SrcSpanAnnA (HsType GhcPs))) where nodeComments HsWC {} = emptyNodeComments -instance CommentExtraction (StandaloneKindSig GhcPs) where - nodeComments = nodeCommentsStandaloneKindSig - -nodeCommentsStandaloneKindSig :: StandaloneKindSig GhcPs -> NodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsStandaloneKindSig (StandaloneKindSig x _ _) = - mconcat $ fmap nodeComments x -#else -nodeCommentsStandaloneKindSig (StandaloneKindSig x _ _) = nodeComments x -#endif -instance CommentExtraction (DefaultDecl GhcPs) where - nodeComments = nodeCommentsDefaultDecl - -nodeCommentsDefaultDecl :: DefaultDecl GhcPs -> NodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsDefaultDecl (DefaultDecl x _) = mconcat $ fmap nodeComments x -#else -nodeCommentsDefaultDecl (DefaultDecl x _) = nodeComments x -#endif -instance CommentExtraction (ForeignDecl GhcPs) where - nodeComments = nodeCommentsForeignDecl - -nodeCommentsForeignDecl :: ForeignDecl GhcPs -> NodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsForeignDecl ForeignImport {..} = - mconcat $ fmap nodeComments fd_i_ext -nodeCommentsForeignDecl ForeignExport {..} = - mconcat $ fmap nodeComments fd_e_ext -#else -nodeCommentsForeignDecl ForeignImport {..} = nodeComments fd_i_ext -nodeCommentsForeignDecl ForeignExport {..} = nodeComments fd_e_ext -#endif - -#if MIN_VERSION_ghc_lib_parser(9, 6, 1) -instance CommentExtraction (ForeignImport GhcPs) where - nodeComments CImport {} = emptyNodeComments - -instance CommentExtraction (ForeignExport GhcPs) where - nodeComments CExport {} = emptyNodeComments -#else -instance CommentExtraction ForeignImport where - nodeComments CImport {} = emptyNodeComments - -instance CommentExtraction ForeignExport where - nodeComments CExport {} = emptyNodeComments -#endif instance CommentExtraction CExportSpec where nodeComments CExportStatic {} = emptyNodeComments @@ -827,39 +601,11 @@ instance CommentExtraction Safety where nodeComments PlayInterruptible = emptyNodeComments nodeComments PlayRisky = emptyNodeComments -instance CommentExtraction (AnnDecl GhcPs) where - nodeComments = nodeCommentsAnnDecl - -nodeCommentsAnnDecl :: AnnDecl GhcPs -> NodeComments -#if MIN_VERSION_ghc_lib_parser(9, 6, 1) -nodeCommentsAnnDecl (HsAnnotation (x, _) _ _) = nodeComments x -#else -nodeCommentsAnnDecl (HsAnnotation x _ _ _) = nodeComments x -#endif -instance CommentExtraction (RoleAnnotDecl GhcPs) where - nodeComments = nodeCommentsRoleAnnotDecl - -nodeCommentsRoleAnnotDecl :: RoleAnnotDecl GhcPs -> NodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsRoleAnnotDecl (RoleAnnotDecl x _ _) = mconcat $ fmap nodeComments x -#else -nodeCommentsRoleAnnotDecl (RoleAnnotDecl x _ _) = nodeComments x -#endif instance CommentExtraction Role where nodeComments Nominal = emptyNodeComments nodeComments Representational = emptyNodeComments nodeComments Phantom = emptyNodeComments -instance CommentExtraction (TyFamInstDecl GhcPs) where - nodeComments = nodeCommentsTyFamInstDecl - -nodeCommentsTyFamInstDecl :: TyFamInstDecl GhcPs -> NodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsTyFamInstDecl TyFamInstDecl {..} = - mconcat $ fmap nodeComments tfid_xtn -#else -nodeCommentsTyFamInstDecl TyFamInstDecl {..} = nodeComments tfid_xtn -#endif instance CommentExtraction TopLevelTyFamInstDecl where nodeComments (TopLevelTyFamInstDecl x) = nodeComments x @@ -869,15 +615,6 @@ instance CommentExtraction (DataFamInstDecl GhcPs) where instance CommentExtraction DataFamInstDecl' where nodeComments DataFamInstDecl' {..} = nodeComments dataFamInstDecl -instance CommentExtraction (PatSynBind GhcPs GhcPs) where - nodeComments = nodeCommentsPatSynBind - -nodeCommentsPatSynBind :: PatSynBind GhcPs GhcPs -> NodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsPatSynBind PSB {..} = mconcat $ fmap nodeComments psb_ext -#else -nodeCommentsPatSynBind PSB {..} = nodeComments psb_ext -#endif -- | 'Pretty' for 'HsPatSynDetails'. instance CommentExtraction (HsConDetails @@ -902,17 +639,6 @@ instance CommentExtraction FixityDirection where instance CommentExtraction InlinePragma where nodeComments InlinePragma {} = emptyNodeComments -instance CommentExtraction InlineSpec where - nodeComments = nodeCommentsInlineSpec - -nodeCommentsInlineSpec :: InlineSpec -> NodeComments -nodeCommentsInlineSpec Inline {} = emptyNodeComments -nodeCommentsInlineSpec Inlinable {} = emptyNodeComments -nodeCommentsInlineSpec NoInline {} = emptyNodeComments -nodeCommentsInlineSpec NoUserInlinePrag {} = emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9, 4, 1) -nodeCommentsInlineSpec Opaque {} = emptyNodeComments -#endif instance CommentExtraction (HsPatSynDir GhcPs) where nodeComments Unidirectional = emptyNodeComments nodeComments ImplicitBidirectional = emptyNodeComments @@ -947,99 +673,21 @@ instance CommentExtraction (HsLit GhcPs) where nodeComments HsFloatPrim {} = emptyNodeComments nodeComments HsDoublePrim {} = emptyNodeComments -instance CommentExtraction (HsPragE GhcPs) where - nodeComments = nodeCommentsHsPragE - -nodeCommentsHsPragE :: HsPragE GhcPs -> NodeComments -#if MIN_VERSION_ghc_lib_parser(9, 6, 1) -nodeCommentsHsPragE (HsPragSCC (x, _) _) = nodeComments x -#else -nodeCommentsHsPragE (HsPragSCC x _) = nodeComments x -#endif instance CommentExtraction HsIPName where nodeComments HsIPName {} = emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9, 6, 1) -instance CommentExtraction (HsTyLit GhcPs) where - nodeComments HsNumTy {} = emptyNodeComments - nodeComments HsStrTy {} = emptyNodeComments - nodeComments HsCharTy {} = emptyNodeComments -#else -instance CommentExtraction HsTyLit where - nodeComments HsNumTy {} = emptyNodeComments - nodeComments HsStrTy {} = emptyNodeComments - nodeComments HsCharTy {} = emptyNodeComments -#endif + instance CommentExtraction (HsPatSigType GhcPs) where nodeComments HsPS {..} = nodeComments hsps_ext instance CommentExtraction (HsIPBinds GhcPs) where nodeComments IPBinds {} = emptyNodeComments -instance CommentExtraction (IPBind GhcPs) where - nodeComments = nodeCommentsIPBind - -nodeCommentsIPBind :: IPBind GhcPs -> NodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsIPBind (IPBind x _ _) = mconcat $ fmap nodeComments x -#else -nodeCommentsIPBind (IPBind x _ _) = nodeComments x -#endif -instance CommentExtraction (DerivStrategy GhcPs) where - nodeComments = nodeCommentsDerivStrategy - -nodeCommentsDerivStrategy :: DerivStrategy GhcPs -> NodeComments -nodeCommentsDerivStrategy (ViaStrategy x) = nodeComments x -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsDerivStrategy (StockStrategy x) = mconcat $ fmap nodeComments x -nodeCommentsDerivStrategy (AnyclassStrategy x) = mconcat $ fmap nodeComments x -nodeCommentsDerivStrategy (NewtypeStrategy x) = mconcat $ fmap nodeComments x -#else -nodeCommentsDerivStrategy (StockStrategy x) = nodeComments x -nodeCommentsDerivStrategy (AnyclassStrategy x) = nodeComments x -nodeCommentsDerivStrategy (NewtypeStrategy x) = nodeComments x -#endif -instance CommentExtraction XViaStrategyPs where - nodeComments = nodeCommentsXViaStrategyPs - -nodeCommentsXViaStrategyPs :: XViaStrategyPs -> NodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsXViaStrategyPs (XViaStrategyPs x _) = mconcat $ fmap nodeComments x -#else -nodeCommentsXViaStrategyPs (XViaStrategyPs x _) = nodeComments x -#endif instance CommentExtraction (RecordPatSynField GhcPs) where nodeComments RecordPatSynField {} = emptyNodeComments instance CommentExtraction (HsCmdTop GhcPs) where nodeComments HsCmdTop {} = emptyNodeComments -instance CommentExtraction (HsCmd GhcPs) where - nodeComments = nodeCommentsHsCmd - -nodeCommentsHsCmd :: HsCmd GhcPs -> NodeComments -nodeCommentsHsCmd (HsCmdArrApp x _ _ _ _) = nodeComments x -nodeCommentsHsCmd (HsCmdArrForm x _ _ _ _) = nodeComments x -nodeCommentsHsCmd HsCmdLam {} = emptyNodeComments -nodeCommentsHsCmd (HsCmdCase x _ _) = nodeComments x -nodeCommentsHsCmd (HsCmdIf x _ _ _ _) = nodeComments x -nodeCommentsHsCmd (HsCmdDo x _) = nodeComments x -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsCmd HsCmdApp {} = emptyNodeComments -#else -nodeCommentsHsCmd (HsCmdApp x _ _) = nodeComments x -#endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsCmd HsCmdPar {} = emptyNodeComments -nodeCommentsHsCmd HsCmdLet {} = emptyNodeComments -#elif MIN_VERSION_ghc_lib_parser(9, 4, 1) -nodeCommentsHsCmd (HsCmdPar x _ _ _) = nodeComments x -nodeCommentsHsCmd (HsCmdLamCase x _ _) = nodeComments x -nodeCommentsHsCmd (HsCmdLet x _ _ _ _) = nodeComments x -#else -nodeCommentsHsCmd (HsCmdPar x _) = nodeComments x -nodeCommentsHsCmd (HsCmdLamCase x _) = nodeComments x -nodeCommentsHsCmd (HsCmdLet x _ _) = nodeComments x -#endif instance CommentExtraction ListComprehension where nodeComments ListComprehension {} = emptyNodeComments @@ -1134,6 +782,280 @@ instance CommentExtraction EpAnnUnboundVar where instance CommentExtraction AnnSig where nodeComments AnnSig {..} = mconcat $ fmap nodeComments $ asDcolon : asRest +instance CommentExtraction (ConDeclField GhcPs) where + nodeComments = nodeCommentsConDeclField + +nodeCommentsConDeclField :: ConDeclField GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsConDeclField ConDeclField {..} = + mconcat $ fmap nodeComments cd_fld_ext +#else +nodeCommentsConDeclField ConDeclField {..} = nodeComments cd_fld_ext +#endif +instance CommentExtraction (HsDerivingClause GhcPs) where + nodeComments = nodeCommentsHsDerivingClause + +nodeCommentsHsDerivingClause :: HsDerivingClause GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsHsDerivingClause HsDerivingClause {..} = + mconcat $ fmap nodeComments deriv_clause_ext +#else +nodeCommentsHsDerivingClause HsDerivingClause {..} = + nodeComments deriv_clause_ext +#endif +-- | This instance is for type family declarations inside a class declaration. +instance CommentExtraction (FamilyDecl GhcPs) where + nodeComments = nodeCommentsFamilyDecl + +nodeCommentsFamilyDecl :: FamilyDecl GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsFamilyDecl FamilyDecl {..} = mconcat $ fmap nodeComments fdExt +#else +nodeCommentsFamilyDecl FamilyDecl {..} = nodeComments fdExt +#endif +instance CommentExtraction (HsTyVarBndr a GhcPs) where + nodeComments = nodeCommentsHsTyVarBndr + +nodeCommentsHsTyVarBndr :: HsTyVarBndr a GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsHsTyVarBndr (UserTyVar x _ _) = mconcat $ fmap nodeComments x +nodeCommentsHsTyVarBndr (KindedTyVar x _ _ _) = mconcat $ fmap nodeComments x +#else +nodeCommentsHsTyVarBndr (UserTyVar x _ _) = nodeComments x +nodeCommentsHsTyVarBndr (KindedTyVar x _ _ _) = nodeComments x +#endif +instance CommentExtraction (IE GhcPs) where + nodeComments = nodeCommentsIE + +nodeCommentsIE :: IE GhcPs -> NodeComments +nodeCommentsIE IEVar {} = emptyNodeComments +nodeCommentsIE IEGroup {} = emptyNodeComments +nodeCommentsIE IEDoc {} = emptyNodeComments +nodeCommentsIE IEDocNamed {} = emptyNodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsIE (IEThingAbs _ x _) = nodeComments x +nodeCommentsIE (IEThingAll _ x _) = nodeComments x +nodeCommentsIE (IEThingWith _ x _ _ _) = nodeComments x +nodeCommentsIE (IEModuleContents (x, y) _) = + mconcat $ maybeToList (fmap nodeComments x) <> fmap nodeComments y +#elif MIN_VERSION_ghc_lib_parser(9, 8, 1) +nodeCommentsIE (IEThingAbs (_, x) _) = nodeComments x +nodeCommentsIE (IEThingAll (_, x) _) = nodeComments x +nodeCommentsIE (IEThingWith (_, x) _ _ _) = nodeComments x +nodeCommentsIE (IEModuleContents (_, x) _) = nodeComments x +#else +nodeCommentsIE (IEThingAbs x _) = nodeComments x +nodeCommentsIE (IEThingAll x _) = nodeComments x +nodeCommentsIE (IEThingWith x _ _ _) = nodeComments x +nodeCommentsIE (IEModuleContents x _) = nodeComments x +#endif +instance CommentExtraction (FamEqn GhcPs a) where + nodeComments = nodeCommentsFamEqn + +nodeCommentsFamEqn :: FamEqn GhcPs a -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsFamEqn FamEqn {..} = mconcat $ fmap nodeComments feqn_ext +#else +nodeCommentsFamEqn FamEqn {..} = nodeComments feqn_ext +#endif +instance CommentExtraction (WarnDecls GhcPs) where + nodeComments = nodeCommentsWarnDecls + +nodeCommentsWarnDecls :: WarnDecls GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsWarnDecls Warnings {..} = mconcat $ fmap nodeComments $ fst wd_ext +#elif MIN_VERSION_ghc_lib_parser(9, 6, 1) +nodeCommentsWarnDecls Warnings {..} = nodeComments $ fst wd_ext +#else +nodeCommentsWarnDecls Warnings {..} = nodeComments wd_ext +#endif +instance CommentExtraction (WarnDecl GhcPs) where + nodeComments = nodeCommentsWarnDecl + +nodeCommentsWarnDecl :: WarnDecl GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsWarnDecl (Warning (_, x) _ _) = mconcat $ fmap nodeComments x +#else +nodeCommentsWarnDecl (Warning x _ _) = nodeComments x +#endif +instance CommentExtraction (RuleDecls GhcPs) where + nodeComments = nodeCommentsRuleDecls + +nodeCommentsRuleDecls :: RuleDecls GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsRuleDecls HsRules {..} = mconcat $ fmap nodeComments $ fst rds_ext +#elif MIN_VERSION_ghc_lib_parser(9, 6, 1) +nodeCommentsRuleDecls HsRules {..} = nodeComments $ fst rds_ext +#else +nodeCommentsRuleDecls HsRules {..} = nodeComments rds_ext +#endif +instance CommentExtraction (RuleDecl GhcPs) where + nodeComments = nodeCommentsRuleDecl + +nodeCommentsRuleDecl :: RuleDecl GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 6, 1) +nodeCommentsRuleDecl HsRule {..} = nodeComments $ fst rd_ext +#else +nodeCommentsRuleDecl HsRule {..} = nodeComments rd_ext +#endif +instance CommentExtraction (DerivDecl GhcPs) where + nodeComments = nodeCommentsDerivDecl + +nodeCommentsDerivDecl :: DerivDecl GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsDerivDecl DerivDecl {deriv_ext = (x, xs)} = + mconcat $ maybeToList (fmap nodeComments x) <> fmap nodeComments xs +#else +nodeCommentsDerivDecl DerivDecl {..} = nodeComments deriv_ext +#endif +instance CommentExtraction (StandaloneKindSig GhcPs) where + nodeComments = nodeCommentsStandaloneKindSig + +nodeCommentsStandaloneKindSig :: StandaloneKindSig GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsStandaloneKindSig (StandaloneKindSig x _ _) = + mconcat $ fmap nodeComments x +#else +nodeCommentsStandaloneKindSig (StandaloneKindSig x _ _) = nodeComments x +#endif +instance CommentExtraction (DefaultDecl GhcPs) where + nodeComments = nodeCommentsDefaultDecl + +nodeCommentsDefaultDecl :: DefaultDecl GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsDefaultDecl (DefaultDecl x _) = mconcat $ fmap nodeComments x +#else +nodeCommentsDefaultDecl (DefaultDecl x _) = nodeComments x +#endif +instance CommentExtraction (ForeignDecl GhcPs) where + nodeComments = nodeCommentsForeignDecl + +nodeCommentsForeignDecl :: ForeignDecl GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsForeignDecl ForeignImport {..} = + mconcat $ fmap nodeComments fd_i_ext +nodeCommentsForeignDecl ForeignExport {..} = + mconcat $ fmap nodeComments fd_e_ext +#else +nodeCommentsForeignDecl ForeignImport {..} = nodeComments fd_i_ext +nodeCommentsForeignDecl ForeignExport {..} = nodeComments fd_e_ext +#endif +instance CommentExtraction (AnnDecl GhcPs) where + nodeComments = nodeCommentsAnnDecl + +nodeCommentsAnnDecl :: AnnDecl GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 6, 1) +nodeCommentsAnnDecl (HsAnnotation (x, _) _ _) = nodeComments x +#else +nodeCommentsAnnDecl (HsAnnotation x _ _ _) = nodeComments x +#endif +instance CommentExtraction (RoleAnnotDecl GhcPs) where + nodeComments = nodeCommentsRoleAnnotDecl + +nodeCommentsRoleAnnotDecl :: RoleAnnotDecl GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsRoleAnnotDecl (RoleAnnotDecl x _ _) = mconcat $ fmap nodeComments x +#else +nodeCommentsRoleAnnotDecl (RoleAnnotDecl x _ _) = nodeComments x +#endif +instance CommentExtraction (TyFamInstDecl GhcPs) where + nodeComments = nodeCommentsTyFamInstDecl + +nodeCommentsTyFamInstDecl :: TyFamInstDecl GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsTyFamInstDecl TyFamInstDecl {..} = + mconcat $ fmap nodeComments tfid_xtn +#else +nodeCommentsTyFamInstDecl TyFamInstDecl {..} = nodeComments tfid_xtn +#endif +instance CommentExtraction (PatSynBind GhcPs GhcPs) where + nodeComments = nodeCommentsPatSynBind + +nodeCommentsPatSynBind :: PatSynBind GhcPs GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsPatSynBind PSB {..} = mconcat $ fmap nodeComments psb_ext +#else +nodeCommentsPatSynBind PSB {..} = nodeComments psb_ext +#endif +instance CommentExtraction InlineSpec where + nodeComments = nodeCommentsInlineSpec + +nodeCommentsInlineSpec :: InlineSpec -> NodeComments +nodeCommentsInlineSpec Inline {} = emptyNodeComments +nodeCommentsInlineSpec Inlinable {} = emptyNodeComments +nodeCommentsInlineSpec NoInline {} = emptyNodeComments +nodeCommentsInlineSpec NoUserInlinePrag {} = emptyNodeComments +#if MIN_VERSION_ghc_lib_parser(9, 4, 1) +nodeCommentsInlineSpec Opaque {} = emptyNodeComments +#endif +instance CommentExtraction (HsPragE GhcPs) where + nodeComments = nodeCommentsHsPragE + +nodeCommentsHsPragE :: HsPragE GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 6, 1) +nodeCommentsHsPragE (HsPragSCC (x, _) _) = nodeComments x +#else +nodeCommentsHsPragE (HsPragSCC x _) = nodeComments x +#endif +instance CommentExtraction (IPBind GhcPs) where + nodeComments = nodeCommentsIPBind + +nodeCommentsIPBind :: IPBind GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsIPBind (IPBind x _ _) = mconcat $ fmap nodeComments x +#else +nodeCommentsIPBind (IPBind x _ _) = nodeComments x +#endif +instance CommentExtraction (DerivStrategy GhcPs) where + nodeComments = nodeCommentsDerivStrategy + +nodeCommentsDerivStrategy :: DerivStrategy GhcPs -> NodeComments +nodeCommentsDerivStrategy (ViaStrategy x) = nodeComments x +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsDerivStrategy (StockStrategy x) = mconcat $ fmap nodeComments x +nodeCommentsDerivStrategy (AnyclassStrategy x) = mconcat $ fmap nodeComments x +nodeCommentsDerivStrategy (NewtypeStrategy x) = mconcat $ fmap nodeComments x +#else +nodeCommentsDerivStrategy (StockStrategy x) = nodeComments x +nodeCommentsDerivStrategy (AnyclassStrategy x) = nodeComments x +nodeCommentsDerivStrategy (NewtypeStrategy x) = nodeComments x +#endif +instance CommentExtraction XViaStrategyPs where + nodeComments = nodeCommentsXViaStrategyPs + +nodeCommentsXViaStrategyPs :: XViaStrategyPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsXViaStrategyPs (XViaStrategyPs x _) = mconcat $ fmap nodeComments x +#else +nodeCommentsXViaStrategyPs (XViaStrategyPs x _) = nodeComments x +#endif +instance CommentExtraction (HsCmd GhcPs) where + nodeComments = nodeCommentsHsCmd + +nodeCommentsHsCmd :: HsCmd GhcPs -> NodeComments +nodeCommentsHsCmd (HsCmdArrApp x _ _ _ _) = nodeComments x +nodeCommentsHsCmd (HsCmdArrForm x _ _ _ _) = nodeComments x +nodeCommentsHsCmd HsCmdLam {} = emptyNodeComments +nodeCommentsHsCmd (HsCmdCase x _ _) = nodeComments x +nodeCommentsHsCmd (HsCmdIf x _ _ _ _) = nodeComments x +nodeCommentsHsCmd (HsCmdDo x _) = nodeComments x +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsHsCmd HsCmdApp {} = emptyNodeComments +#else +nodeCommentsHsCmd (HsCmdApp x _ _) = nodeComments x +#endif +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsHsCmd HsCmdPar {} = emptyNodeComments +nodeCommentsHsCmd HsCmdLet {} = emptyNodeComments +#elif MIN_VERSION_ghc_lib_parser(9, 4, 1) +nodeCommentsHsCmd (HsCmdPar x _ _ _) = nodeComments x +nodeCommentsHsCmd (HsCmdLamCase x _ _) = nodeComments x +nodeCommentsHsCmd (HsCmdLet x _ _ _ _) = nodeComments x +#else +nodeCommentsHsCmd (HsCmdPar x _) = nodeComments x +nodeCommentsHsCmd (HsCmdLamCase x _) = nodeComments x +nodeCommentsHsCmd (HsCmdLet x _ _) = nodeComments x +#endif instance CommentExtraction (RuleBndr GhcPs) where nodeComments = nodeCommentsRuleBndr @@ -1161,10 +1083,84 @@ nodeCommentsHsUntypedSplice (HsUntypedSpliceExpr x) = nodeComments x #endif nodeCommentsHsUntypedSplice HsQuasiQuote {} = emptyNodeComments #endif +#if MIN_VERSION_ghc_lib_parser(9, 4, 1) +instance CommentExtraction (HsQuote GhcPs) where + nodeComments ExpBr {} = emptyNodeComments + nodeComments PatBr {} = emptyNodeComments + nodeComments DecBrL {} = emptyNodeComments + nodeComments DecBrG {} = emptyNodeComments + nodeComments TypBr {} = emptyNodeComments + nodeComments VarBr {} = emptyNodeComments + +instance CommentExtraction (WithHsDocIdentifiers StringLiteral GhcPs) where + nodeComments WithHsDocIdentifiers {} = emptyNodeComments + +instance CommentExtraction (DotFieldOcc GhcPs) where + nodeComments DotFieldOcc {..} = nodeComments dfoExt + +instance CommentExtraction (HsFieldBind a b) where + nodeComments = nodeCommentsHsFieldBind + +nodeCommentsHsFieldBind :: HsFieldBind a b -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsHsFieldBind HsFieldBind {..} = mconcat $ fmap nodeComments hfbAnn +#else +nodeCommentsHsFieldBind HsFieldBind {..} = nodeComments hfbAnn +#endif +#else +instance CommentExtraction (HsFieldLabel GhcPs) where + nodeComments HsFieldLabel {..} = nodeComments hflExt + +instance CommentExtraction RecConField where + nodeComments (RecConField x) = nodeComments x +#endif +#if MIN_VERSION_ghc_lib_parser(9, 6, 1) +instance CommentExtraction XImportDeclPass where + nodeComments XImportDeclPass {..} = nodeComments ideclAnn + +instance CommentExtraction (ForeignImport GhcPs) where + nodeComments CImport {} = emptyNodeComments + +instance CommentExtraction (ForeignExport GhcPs) where + nodeComments CExport {} = emptyNodeComments + +instance CommentExtraction (HsTyLit GhcPs) where + nodeComments HsNumTy {} = emptyNodeComments + nodeComments HsStrTy {} = emptyNodeComments + nodeComments HsCharTy {} = emptyNodeComments +#else +instance CommentExtraction ForeignImport where + nodeComments CImport {} = emptyNodeComments + +instance CommentExtraction ForeignExport where + nodeComments CExport {} = emptyNodeComments + +instance CommentExtraction HsTyLit where + nodeComments HsNumTy {} = emptyNodeComments + nodeComments HsStrTy {} = emptyNodeComments + nodeComments HsCharTy {} = emptyNodeComments +#endif #if MIN_VERSION_ghc_lib_parser(9, 8, 1) +instance CommentExtraction + (HsArg + GhcPs + (GenLocated SrcSpanAnnA (HsType GhcPs)) + (GenLocated SrcSpanAnnA (HsType GhcPs))) where + nodeComments HsValArg {} = emptyNodeComments + nodeComments HsTypeArg {} = emptyNodeComments + nodeComments HsArgPar {} = emptyNodeComments + instance CommentExtraction (LHsRecUpdFields GhcPs) where nodeComments RegularRecUpdFields {} = emptyNodeComments nodeComments OverloadedRecUpdFields {} = emptyNodeComments +#else +instance CommentExtraction + (HsArg + (GenLocated SrcSpanAnnA (HsType GhcPs)) + (GenLocated SrcSpanAnnA (HsType GhcPs))) where + nodeComments HsValArg {} = emptyNodeComments + nodeComments HsTypeArg {} = emptyNodeComments + nodeComments HsArgPar {} = emptyNodeComments #endif #if MIN_VERSION_ghc_lib_parser(9, 10, 1) instance CommentExtraction (EpaLocation' NoComments) where From a60fba0dddba89860f0836317e17601d2076eceb Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 18:32:42 +0900 Subject: [PATCH 37/40] wip --- src/HIndent/Pretty/NodeComments.hs | 643 ++++++++++++++--------------- 1 file changed, 319 insertions(+), 324 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index 57aa6d62d..3e68cf77f 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -91,9 +91,6 @@ instance CommentExtraction (HsDataDefn GhcPs) where instance CommentExtraction (MatchGroup GhcPs a) where nodeComments MG {} = emptyNodeComments -instance CommentExtraction (HsExpr GhcPs) where - nodeComments = nodeCommentsHsExpr - instance CommentExtraction LambdaCase where nodeComments (LambdaCase x _) = nodeComments x @@ -103,125 +100,12 @@ instance CommentExtraction DoOrMdo where instance CommentExtraction QualifiedDo where nodeComments = const emptyNodeComments -nodeCommentsHsExpr :: HsExpr GhcPs -> NodeComments -nodeCommentsHsExpr HsVar {} = emptyNodeComments -nodeCommentsHsExpr HsLam {} = emptyNodeComments -nodeCommentsHsExpr HsAppType {} = emptyNodeComments -nodeCommentsHsExpr (ExplicitSum x _ _ _) = nodeComments x -nodeCommentsHsExpr (HsCase x _ _) = nodeComments x -nodeCommentsHsExpr (HsIf x _ _ _) = nodeComments x -nodeCommentsHsExpr (HsDo x _ _) = nodeComments x -nodeCommentsHsExpr (ExplicitList x _) = nodeComments x -nodeCommentsHsExpr HsProjection {..} = nodeComments proj_ext -nodeCommentsHsExpr HsPragE {} = emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsExpr (HsTypedBracket x _) = mconcat $ fmap nodeComments x -nodeCommentsHsExpr (HsUntypedBracket x _) = mconcat $ fmap nodeComments x -nodeCommentsHsExpr HsLet {} = emptyNodeComments -nodeCommentsHsExpr HsPar {} = emptyNodeComments -#elif MIN_VERSION_ghc_lib_parser(9, 4, 1) -nodeCommentsHsExpr HsRecSel {} = emptyNodeComments -nodeCommentsHsExpr (HsTypedBracket x _) = nodeComments x -nodeCommentsHsExpr (HsUntypedBracket x _) = nodeComments x -nodeCommentsHsExpr (HsLet x _ _ _ _) = nodeComments x -nodeCommentsHsExpr (HsPar x _ _ _) = nodeComments x -nodeCommentsHsExpr (HsLamCase x _ _) = nodeComments x -#else -nodeCommentsHsExpr HsTick {} = emptyNodeComments -nodeCommentsHsExpr HsBinTick {} = emptyNodeComments -nodeCommentsHsExpr (HsBracket x _) = nodeComments x -nodeCommentsHsExpr HsRnBracketOut {} = notUsedInParsedStage -nodeCommentsHsExpr HsTcBracketOut {} = notUsedInParsedStage -nodeCommentsHsExpr (HsLet x _ _) = nodeComments x -nodeCommentsHsExpr (HsPar x _) = nodeComments x -nodeCommentsHsExpr (HsLamCase x _) = nodeComments x -nodeCommentsHsExpr HsConLikeOut {} = emptyNodeComments -nodeCommentsHsExpr HsRecFld {} = emptyNodeComments -#endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsExpr (HsTypedSplice x _) = mconcat $ fmap nodeComments x -nodeCommentsHsExpr HsUntypedSplice {} = emptyNodeComments -nodeCommentsHsExpr HsOverLabel {} = emptyNodeComments -#elif MIN_VERSION_ghc_lib_parser(9, 6, 1) -nodeCommentsHsExpr (HsTypedSplice (x, y) _) = nodeComments x <> nodeComments y -nodeCommentsHsExpr (HsUntypedSplice x _) = nodeComments x -nodeCommentsHsExpr (HsOverLabel x _ _) = nodeComments x -#else -nodeCommentsHsExpr (HsSpliceE x _) = nodeComments x -nodeCommentsHsExpr (HsOverLabel x _) = nodeComments x -#endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsExpr (HsStatic x _) = mconcat $ fmap nodeComments x -nodeCommentsHsExpr (HsProc x _ _) = mconcat $ fmap nodeComments x -nodeCommentsHsExpr (ArithSeq x _ _) = mconcat $ fmap nodeComments x -nodeCommentsHsExpr (ExprWithTySig x _ _) = mconcat $ fmap nodeComments x -nodeCommentsHsExpr HsGetField {} = emptyNodeComments -nodeCommentsHsExpr RecordUpd {..} = mconcat $ fmap nodeComments rupd_ext -nodeCommentsHsExpr RecordCon {..} = mconcat $ fmap nodeComments rcon_ext -nodeCommentsHsExpr (HsMultiIf x _) = mconcat $ fmap nodeComments x -nodeCommentsHsExpr (ExplicitTuple x _ _) = mconcat $ fmap nodeComments x -nodeCommentsHsExpr SectionR {} = emptyNodeComments -nodeCommentsHsExpr SectionL {} = emptyNodeComments -nodeCommentsHsExpr (NegApp x _ _) = mconcat $ fmap nodeComments x -nodeCommentsHsExpr (OpApp x _ _ _) = mconcat $ fmap nodeComments x -nodeCommentsHsExpr HsApp {} = emptyNodeComments -nodeCommentsHsExpr HsLit {} = emptyNodeComments -nodeCommentsHsExpr HsOverLit {} = emptyNodeComments -nodeCommentsHsExpr HsIPVar {} = emptyNodeComments -nodeCommentsHsExpr (HsUnboundVar x _) = fromMaybe mempty $ fmap nodeComments x -#else -nodeCommentsHsExpr (HsStatic x _) = nodeComments x -nodeCommentsHsExpr (HsProc x _ _) = nodeComments x -nodeCommentsHsExpr (ArithSeq x _ _) = nodeComments x -nodeCommentsHsExpr (ExprWithTySig x _ _) = nodeComments x -nodeCommentsHsExpr HsGetField {..} = nodeComments gf_ext -nodeCommentsHsExpr RecordUpd {..} = nodeComments rupd_ext -nodeCommentsHsExpr RecordCon {..} = nodeComments rcon_ext -nodeCommentsHsExpr (HsMultiIf x _) = nodeComments x -nodeCommentsHsExpr (ExplicitTuple x _ _) = nodeComments x -nodeCommentsHsExpr (SectionR x _ _) = nodeComments x -nodeCommentsHsExpr (SectionL x _ _) = nodeComments x -nodeCommentsHsExpr (NegApp x _ _) = nodeComments x -nodeCommentsHsExpr (OpApp x _ _ _) = nodeComments x -nodeCommentsHsExpr (HsApp x _ _) = nodeComments x -nodeCommentsHsExpr (HsLit x _) = nodeComments x -nodeCommentsHsExpr (HsOverLit x _) = nodeComments x -nodeCommentsHsExpr (HsIPVar x _) = nodeComments x -nodeCommentsHsExpr (HsUnboundVar x _) = nodeComments x -#endif instance CommentExtraction (HsSigType GhcPs) where nodeComments HsSig {} = emptyNodeComments instance CommentExtraction HsSigType' where nodeComments (HsSigType' _ _ HsSig {}) = emptyNodeComments -instance CommentExtraction (Match GhcPs a) where - nodeComments = nodeCommentsMatch - -nodeCommentsMatch :: Match GhcPs a -> NodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsMatch Match {..} = mconcat $ fmap nodeComments m_ext -#else -nodeCommentsMatch Match {..} = nodeComments m_ext -#endif -instance CommentExtraction (StmtLR GhcPs GhcPs a) where - nodeComments = nodeCommentsStmtLR - -nodeCommentsStmtLR :: StmtLR GhcPs GhcPs a -> NodeComments -nodeCommentsStmtLR LastStmt {} = emptyNodeComments -nodeCommentsStmtLR ApplicativeStmt {} = emptyNodeComments -nodeCommentsStmtLR BodyStmt {} = emptyNodeComments -nodeCommentsStmtLR ParStmt {} = emptyNodeComments -nodeCommentsStmtLR RecStmt {..} = nodeComments recS_ext -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsStmtLR (BindStmt x _ _) = mconcat $ fmap nodeComments x -nodeCommentsStmtLR (LetStmt x _) = mconcat $ fmap nodeComments x -nodeCommentsStmtLR TransStmt {..} = mconcat $ fmap nodeComments trS_ext -#else -nodeCommentsStmtLR (BindStmt x _ _) = nodeComments x -nodeCommentsStmtLR (LetStmt x _) = nodeComments x -nodeCommentsStmtLR TransStmt {..} = nodeComments trS_ext -#endif instance CommentExtraction StmtLRInsideVerticalList where nodeComments (StmtLRInsideVerticalList x) = nodeComments x @@ -235,44 +119,6 @@ instance CommentExtraction (HsRecFields GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))) where nodeComments HsRecFields {} = emptyNodeComments -instance CommentExtraction (HsType GhcPs) where - nodeComments = nodeCommentsHsType - -nodeCommentsHsType :: HsType GhcPs -> NodeComments -nodeCommentsHsType HsForAllTy {} = emptyNodeComments -nodeCommentsHsType HsQualTy {} = emptyNodeComments -nodeCommentsHsType HsAppTy {} = emptyNodeComments -nodeCommentsHsType HsAppKindTy {} = emptyNodeComments -nodeCommentsHsType (HsListTy x _) = nodeComments x -nodeCommentsHsType (HsTupleTy x _ _) = nodeComments x -nodeCommentsHsType (HsSumTy x _) = nodeComments x -nodeCommentsHsType HsOpTy {} = emptyNodeComments -nodeCommentsHsType (HsParTy x _) = nodeComments x -nodeCommentsHsType HsStarTy {} = emptyNodeComments -nodeCommentsHsType HsSpliceTy {} = emptyNodeComments -nodeCommentsHsType (HsRecTy x _) = nodeComments x -nodeCommentsHsType HsTyLit {} = emptyNodeComments -nodeCommentsHsType HsWildCardTy {} = emptyNodeComments -nodeCommentsHsType XHsType {} = emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsType (HsTyVar x _ _) = mconcat $ fmap nodeComments x -nodeCommentsHsType HsFunTy {} = emptyNodeComments -nodeCommentsHsType (HsIParamTy x _ _) = mconcat $ fmap nodeComments x -nodeCommentsHsType (HsKindSig x _ _) = mconcat $ fmap nodeComments x -nodeCommentsHsType (HsDocTy x _ _) = mconcat $ fmap nodeComments x -nodeCommentsHsType (HsBangTy x _ _) = mconcat $ fmap nodeComments x -nodeCommentsHsType (HsExplicitListTy x _ _) = mconcat $ fmap nodeComments x -nodeCommentsHsType (HsExplicitTupleTy x _) = mconcat $ fmap nodeComments x -#else -nodeCommentsHsType (HsTyVar x _ _) = nodeComments x -nodeCommentsHsType (HsFunTy x _ _ _) = nodeComments x -nodeCommentsHsType (HsIParamTy x _ _) = nodeComments x -nodeCommentsHsType (HsKindSig x _ _) = nodeComments x -nodeCommentsHsType (HsDocTy x _ _) = nodeComments x -nodeCommentsHsType (HsBangTy x _ _) = nodeComments x -nodeCommentsHsType (HsExplicitListTy x _ _) = nodeComments x -nodeCommentsHsType (HsExplicitTupleTy x _) = nodeComments x -#endif instance CommentExtraction HsType' where nodeComments HsType' {..} = nodeComments hsType @@ -285,37 +131,7 @@ instance CommentExtraction (GRHSs GhcPs a) where instance CommentExtraction GRHSsExpr where nodeComments (GRHSsExpr {..}) = nodeComments grhssExpr -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -instance CommentExtraction (HsMatchContext (GenLocated SrcSpanAnnN RdrName)) where - nodeComments = nodeCommentsMatchContext -#else -instance CommentExtraction (HsMatchContext GhcPs) where - nodeComments = nodeCommentsMatchContext -#endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsMatchContext :: - HsMatchContext (GenLocated SrcSpanAnnN RdrName) -> NodeComments -#else -nodeCommentsMatchContext :: HsMatchContext GhcPs -> NodeComments -#endif -nodeCommentsMatchContext FunRhs {} = emptyNodeComments -nodeCommentsMatchContext CaseAlt {} = emptyNodeComments -nodeCommentsMatchContext IfAlt {} = emptyNodeComments -nodeCommentsMatchContext ArrowMatchCtxt {} = emptyNodeComments -nodeCommentsMatchContext PatBindRhs {} = emptyNodeComments -nodeCommentsMatchContext PatBindGuards {} = emptyNodeComments -nodeCommentsMatchContext RecUpd {} = emptyNodeComments -nodeCommentsMatchContext StmtCtxt {} = emptyNodeComments -nodeCommentsMatchContext ThPatSplice {} = emptyNodeComments -nodeCommentsMatchContext ThPatQuote {} = emptyNodeComments -nodeCommentsMatchContext PatSyn {} = emptyNodeComments -#if !MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsMatchContext LambdaExpr {} = emptyNodeComments -#endif -#if MIN_VERSION_ghc_lib_parser(9, 4, 1) && !MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsMatchContext LamCaseAlt {} = emptyNodeComments -#endif instance CommentExtraction (ParStmtBlock GhcPs GhcPs) where nodeComments ParStmtBlock {} = emptyNodeComments @@ -342,70 +158,13 @@ instance CommentExtraction EpaCommentTok where instance CommentExtraction (SpliceDecl GhcPs) where nodeComments SpliceDecl {} = emptyNodeComments -#if !MIN_VERSION_ghc_lib_parser(9, 6, 1) -instance CommentExtraction (HsSplice GhcPs) where - nodeComments (HsTypedSplice x _ _ _) = nodeComments x - nodeComments (HsUntypedSplice x _ _ _) = nodeComments x - nodeComments HsQuasiQuote {} = emptyNodeComments - nodeComments HsSpliced {} = emptyNodeComments -#endif -instance CommentExtraction (Pat GhcPs) where - nodeComments = nodeCommentsPat instance CommentExtraction PatInsidePatDecl where nodeComments (PatInsidePatDecl x) = nodeComments x -nodeCommentsPat :: Pat GhcPs -> NodeComments -nodeCommentsPat WildPat {} = emptyNodeComments -nodeCommentsPat VarPat {} = emptyNodeComments -nodeCommentsPat (ListPat x _) = nodeComments x -nodeCommentsPat (SumPat x _ _ _) = nodeComments x -nodeCommentsPat SplicePat {} = emptyNodeComments -nodeCommentsPat LitPat {} = emptyNodeComments -nodeCommentsPat (NPlusKPat x _ _ _ _ _) = nodeComments x -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsPat ParPat {} = emptyNodeComments -#elif MIN_VERSION_ghc_lib_parser(9, 4, 1) -nodeCommentsPat (ParPat x _ _ _) = nodeComments x -#else -nodeCommentsPat (ParPat x _) = nodeComments x -#endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsPat AsPat {} = emptyNodeComments -#elif MIN_VERSION_ghc_lib_parser(9, 6, 1) -nodeCommentsPat (AsPat x _ _ _) = nodeComments x -#else -nodeCommentsPat (AsPat x _ _) = nodeComments x -#endif -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsPat (LazyPat x _) = mconcat $ fmap nodeComments x -nodeCommentsPat (BangPat x _) = mconcat $ fmap nodeComments x -nodeCommentsPat (TuplePat x _ _) = mconcat $ fmap nodeComments x -nodeCommentsPat ConPat {..} = mconcat $ fmap nodeComments pat_con_ext -nodeCommentsPat (ViewPat x _ _) = mconcat $ fmap nodeComments x -nodeCommentsPat (NPat x _ _ _) = mconcat $ fmap nodeComments x -nodeCommentsPat (SigPat x _ _) = mconcat $ fmap nodeComments x -#else -nodeCommentsPat (LazyPat x _) = nodeComments x -nodeCommentsPat (BangPat x _) = nodeComments x -nodeCommentsPat (TuplePat x _ _) = nodeComments x -nodeCommentsPat ConPat {..} = nodeComments pat_con_ext -nodeCommentsPat (ViewPat x _ _) = nodeComments x -nodeCommentsPat (NPat x _ _ _) = nodeComments x -nodeCommentsPat (SigPat x _ _) = nodeComments x -#endif instance CommentExtraction RecConPat where nodeComments (RecConPat x) = nodeComments x -#if !MIN_VERSION_ghc_lib_parser(9, 4, 1) -instance CommentExtraction (HsBracket GhcPs) where - nodeComments ExpBr {} = emptyNodeComments - nodeComments PatBr {} = emptyNodeComments - nodeComments DecBrL {} = emptyNodeComments - nodeComments DecBrG {} = emptyNodeComments - nodeComments TypBr {} = emptyNodeComments - nodeComments VarBr {} = emptyNodeComments - nodeComments TExpBr {} = emptyNodeComments -#endif + instance CommentExtraction SigBindFamily where nodeComments (Sig x) = nodeComments x nodeComments (Bind x) = nodeComments x @@ -415,38 +174,11 @@ instance CommentExtraction SigBindFamily where instance CommentExtraction EpaComment where nodeComments EpaComment {} = emptyNodeComments -#if !MIN_VERSION_ghc_lib_parser(9, 10, 1) -instance CommentExtraction Anchor where - nodeComments Anchor {} = emptyNodeComments -instance CommentExtraction (SrcAnn a) where - nodeComments (SrcSpanAnn ep _) = nodeComments ep -#endif instance CommentExtraction SrcSpan where nodeComments RealSrcSpan {} = emptyNodeComments nodeComments UnhelpfulSpan {} = emptyNodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -instance CommentExtraction (EpAnn a) where - nodeComments (EpAnn ann _ cs) = NodeComments {..} - where - commentsBefore = priorComments cs - commentsOnSameLine = filter isCommentOnSameLine $ getFollowingComments cs - commentsAfter = - filter (not . isCommentOnSameLine) $ getFollowingComments cs - isCommentOnSameLine (L comAnn _) = - srcSpanEndLine (anchor ann) == srcSpanStartLine (anchor comAnn) -#else -instance CommentExtraction (EpAnn a) where - nodeComments (EpAnn ann _ cs) = NodeComments {..} - where - commentsBefore = priorComments cs - commentsOnSameLine = filter isCommentOnSameLine $ getFollowingComments cs - commentsAfter = - filter (not . isCommentOnSameLine) $ getFollowingComments cs - isCommentOnSameLine (L comAnn _) = - srcSpanEndLine (anchor ann) == srcSpanStartLine (anchor comAnn) - nodeComments EpAnnNotUsed = emptyNodeComments -#endif + instance CommentExtraction (HsLocalBindsLR GhcPs GhcPs) where nodeComments (HsValBinds x _) = nodeComments x nodeComments (HsIPBinds x _) = nodeComments x @@ -456,30 +188,6 @@ instance CommentExtraction (HsValBindsLR GhcPs GhcPs) where nodeComments ValBinds {} = emptyNodeComments nodeComments XValBindsLR {} = notUsedInParsedStage -instance CommentExtraction (HsTupArg GhcPs) where - nodeComments = nodeCommentsHsTupArg - -nodeCommentsHsTupArg :: HsTupArg GhcPs -> NodeComments -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsHsTupArg Present {} = emptyNodeComments -#else -nodeCommentsHsTupArg (Present x _) = nodeComments x -#endif -nodeCommentsHsTupArg (Missing x) = nodeComments x -#if MIN_VERSION_ghc_lib_parser(9, 4, 1) -instance CommentExtraction RecConField where - nodeComments (RecConField x) = nodeComments x -#else --- | For pattern matching against a record. -instance CommentExtraction - (HsRecField' (FieldOcc GhcPs) (GenLocated SrcSpanAnnA (Pat GhcPs))) where - nodeComments HsRecField {..} = nodeComments hsRecFieldAnn - --- | For record updates. -instance CommentExtraction - (HsRecField' (FieldOcc GhcPs) (GenLocated SrcSpanAnnA (HsExpr GhcPs))) where - nodeComments HsRecField {..} = nodeComments hsRecFieldAnn -#endif instance CommentExtraction (FieldOcc GhcPs) where nodeComments FieldOcc {} = emptyNodeComments @@ -746,41 +454,279 @@ instance CommentExtraction EpAnnSumPat where <> fmap nodeComments sumPatVbarsBefore <> fmap nodeComments sumPatVbarsAfter -instance CommentExtraction AnnProjection where - nodeComments AnnProjection {..} = - mconcat $ fmap nodeComments [apOpen, apClose] +instance CommentExtraction AnnProjection where + nodeComments AnnProjection {..} = + mconcat $ fmap nodeComments [apOpen, apClose] + +instance CommentExtraction AnnsIf where + nodeComments AnnsIf {..} = + mconcat + $ fmap nodeComments + $ aiIf + : aiThen + : aiElse + : (maybeToList aiThenSemi <> maybeToList aiElseSemi) + +instance CommentExtraction EpAnnHsCase where + nodeComments EpAnnHsCase {..} = + mconcat + $ nodeComments hsCaseAnnCase + : nodeComments hsCaseAnnOf + : fmap nodeComments hsCaseAnnsRest + +instance CommentExtraction AnnExplicitSum where + nodeComments AnnExplicitSum {..} = + mconcat + $ fmap nodeComments + $ aesOpen : aesBarsBefore <> aesBarsAfter <> [aesClose] + +instance CommentExtraction EpAnnUnboundVar where + nodeComments EpAnnUnboundVar {..} = + mconcat + $ fmap + nodeComments + [fst hsUnboundBackquotes, snd hsUnboundBackquotes, hsUnboundHole] + +instance CommentExtraction AnnSig where + nodeComments AnnSig {..} = mconcat $ fmap nodeComments $ asDcolon : asRest + +instance CommentExtraction (HsExpr GhcPs) where + nodeComments = nodeCommentsHsExpr + +nodeCommentsHsExpr :: HsExpr GhcPs -> NodeComments +nodeCommentsHsExpr HsVar {} = emptyNodeComments +nodeCommentsHsExpr HsLam {} = emptyNodeComments +nodeCommentsHsExpr HsAppType {} = emptyNodeComments +nodeCommentsHsExpr (ExplicitSum x _ _ _) = nodeComments x +nodeCommentsHsExpr (HsCase x _ _) = nodeComments x +nodeCommentsHsExpr (HsIf x _ _ _) = nodeComments x +nodeCommentsHsExpr (HsDo x _ _) = nodeComments x +nodeCommentsHsExpr (ExplicitList x _) = nodeComments x +nodeCommentsHsExpr HsProjection {..} = nodeComments proj_ext +nodeCommentsHsExpr HsPragE {} = emptyNodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsHsExpr (HsTypedBracket x _) = mconcat $ fmap nodeComments x +nodeCommentsHsExpr (HsUntypedBracket x _) = mconcat $ fmap nodeComments x +nodeCommentsHsExpr HsLet {} = emptyNodeComments +nodeCommentsHsExpr HsPar {} = emptyNodeComments +#elif MIN_VERSION_ghc_lib_parser(9, 4, 1) +nodeCommentsHsExpr HsRecSel {} = emptyNodeComments +nodeCommentsHsExpr (HsTypedBracket x _) = nodeComments x +nodeCommentsHsExpr (HsUntypedBracket x _) = nodeComments x +nodeCommentsHsExpr (HsLet x _ _ _ _) = nodeComments x +nodeCommentsHsExpr (HsPar x _ _ _) = nodeComments x +nodeCommentsHsExpr (HsLamCase x _ _) = nodeComments x +#else +nodeCommentsHsExpr HsTick {} = emptyNodeComments +nodeCommentsHsExpr HsBinTick {} = emptyNodeComments +nodeCommentsHsExpr (HsBracket x _) = nodeComments x +nodeCommentsHsExpr HsRnBracketOut {} = notUsedInParsedStage +nodeCommentsHsExpr HsTcBracketOut {} = notUsedInParsedStage +nodeCommentsHsExpr (HsLet x _ _) = nodeComments x +nodeCommentsHsExpr (HsPar x _) = nodeComments x +nodeCommentsHsExpr (HsLamCase x _) = nodeComments x +nodeCommentsHsExpr HsConLikeOut {} = emptyNodeComments +nodeCommentsHsExpr HsRecFld {} = emptyNodeComments +#endif +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsHsExpr (HsTypedSplice x _) = mconcat $ fmap nodeComments x +nodeCommentsHsExpr HsUntypedSplice {} = emptyNodeComments +nodeCommentsHsExpr HsOverLabel {} = emptyNodeComments +#elif MIN_VERSION_ghc_lib_parser(9, 6, 1) +nodeCommentsHsExpr (HsTypedSplice (x, y) _) = nodeComments x <> nodeComments y +nodeCommentsHsExpr (HsUntypedSplice x _) = nodeComments x +nodeCommentsHsExpr (HsOverLabel x _ _) = nodeComments x +#else +nodeCommentsHsExpr (HsSpliceE x _) = nodeComments x +nodeCommentsHsExpr (HsOverLabel x _) = nodeComments x +#endif +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsHsExpr (HsStatic x _) = mconcat $ fmap nodeComments x +nodeCommentsHsExpr (HsProc x _ _) = mconcat $ fmap nodeComments x +nodeCommentsHsExpr (ArithSeq x _ _) = mconcat $ fmap nodeComments x +nodeCommentsHsExpr (ExprWithTySig x _ _) = mconcat $ fmap nodeComments x +nodeCommentsHsExpr HsGetField {} = emptyNodeComments +nodeCommentsHsExpr RecordUpd {..} = mconcat $ fmap nodeComments rupd_ext +nodeCommentsHsExpr RecordCon {..} = mconcat $ fmap nodeComments rcon_ext +nodeCommentsHsExpr (HsMultiIf x _) = mconcat $ fmap nodeComments x +nodeCommentsHsExpr (ExplicitTuple x _ _) = mconcat $ fmap nodeComments x +nodeCommentsHsExpr SectionR {} = emptyNodeComments +nodeCommentsHsExpr SectionL {} = emptyNodeComments +nodeCommentsHsExpr (NegApp x _ _) = mconcat $ fmap nodeComments x +nodeCommentsHsExpr (OpApp x _ _ _) = mconcat $ fmap nodeComments x +nodeCommentsHsExpr HsApp {} = emptyNodeComments +nodeCommentsHsExpr HsLit {} = emptyNodeComments +nodeCommentsHsExpr HsOverLit {} = emptyNodeComments +nodeCommentsHsExpr HsIPVar {} = emptyNodeComments +nodeCommentsHsExpr (HsUnboundVar x _) = fromMaybe mempty $ fmap nodeComments x +#else +nodeCommentsHsExpr (HsStatic x _) = nodeComments x +nodeCommentsHsExpr (HsProc x _ _) = nodeComments x +nodeCommentsHsExpr (ArithSeq x _ _) = nodeComments x +nodeCommentsHsExpr (ExprWithTySig x _ _) = nodeComments x +nodeCommentsHsExpr HsGetField {..} = nodeComments gf_ext +nodeCommentsHsExpr RecordUpd {..} = nodeComments rupd_ext +nodeCommentsHsExpr RecordCon {..} = nodeComments rcon_ext +nodeCommentsHsExpr (HsMultiIf x _) = nodeComments x +nodeCommentsHsExpr (ExplicitTuple x _ _) = nodeComments x +nodeCommentsHsExpr (SectionR x _ _) = nodeComments x +nodeCommentsHsExpr (SectionL x _ _) = nodeComments x +nodeCommentsHsExpr (NegApp x _ _) = nodeComments x +nodeCommentsHsExpr (OpApp x _ _ _) = nodeComments x +nodeCommentsHsExpr (HsApp x _ _) = nodeComments x +nodeCommentsHsExpr (HsLit x _) = nodeComments x +nodeCommentsHsExpr (HsOverLit x _) = nodeComments x +nodeCommentsHsExpr (HsIPVar x _) = nodeComments x +nodeCommentsHsExpr (HsUnboundVar x _) = nodeComments x +#endif +instance CommentExtraction (Match GhcPs a) where + nodeComments = nodeCommentsMatch + +nodeCommentsMatch :: Match GhcPs a -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsMatch Match {..} = mconcat $ fmap nodeComments m_ext +#else +nodeCommentsMatch Match {..} = nodeComments m_ext +#endif +instance CommentExtraction (StmtLR GhcPs GhcPs a) where + nodeComments = nodeCommentsStmtLR -instance CommentExtraction AnnsIf where - nodeComments AnnsIf {..} = - mconcat - $ fmap nodeComments - $ aiIf - : aiThen - : aiElse - : (maybeToList aiThenSemi <> maybeToList aiElseSemi) +nodeCommentsStmtLR :: StmtLR GhcPs GhcPs a -> NodeComments +nodeCommentsStmtLR LastStmt {} = emptyNodeComments +nodeCommentsStmtLR ApplicativeStmt {} = emptyNodeComments +nodeCommentsStmtLR BodyStmt {} = emptyNodeComments +nodeCommentsStmtLR ParStmt {} = emptyNodeComments +nodeCommentsStmtLR RecStmt {..} = nodeComments recS_ext +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsStmtLR (BindStmt x _ _) = mconcat $ fmap nodeComments x +nodeCommentsStmtLR (LetStmt x _) = mconcat $ fmap nodeComments x +nodeCommentsStmtLR TransStmt {..} = mconcat $ fmap nodeComments trS_ext +#else +nodeCommentsStmtLR (BindStmt x _ _) = nodeComments x +nodeCommentsStmtLR (LetStmt x _) = nodeComments x +nodeCommentsStmtLR TransStmt {..} = nodeComments trS_ext +#endif +instance CommentExtraction (HsType GhcPs) where + nodeComments = nodeCommentsHsType -instance CommentExtraction EpAnnHsCase where - nodeComments EpAnnHsCase {..} = - mconcat - $ nodeComments hsCaseAnnCase - : nodeComments hsCaseAnnOf - : fmap nodeComments hsCaseAnnsRest +nodeCommentsHsType :: HsType GhcPs -> NodeComments +nodeCommentsHsType HsForAllTy {} = emptyNodeComments +nodeCommentsHsType HsQualTy {} = emptyNodeComments +nodeCommentsHsType HsAppTy {} = emptyNodeComments +nodeCommentsHsType HsAppKindTy {} = emptyNodeComments +nodeCommentsHsType (HsListTy x _) = nodeComments x +nodeCommentsHsType (HsTupleTy x _ _) = nodeComments x +nodeCommentsHsType (HsSumTy x _) = nodeComments x +nodeCommentsHsType HsOpTy {} = emptyNodeComments +nodeCommentsHsType (HsParTy x _) = nodeComments x +nodeCommentsHsType HsStarTy {} = emptyNodeComments +nodeCommentsHsType HsSpliceTy {} = emptyNodeComments +nodeCommentsHsType (HsRecTy x _) = nodeComments x +nodeCommentsHsType HsTyLit {} = emptyNodeComments +nodeCommentsHsType HsWildCardTy {} = emptyNodeComments +nodeCommentsHsType XHsType {} = emptyNodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsHsType (HsTyVar x _ _) = mconcat $ fmap nodeComments x +nodeCommentsHsType HsFunTy {} = emptyNodeComments +nodeCommentsHsType (HsIParamTy x _ _) = mconcat $ fmap nodeComments x +nodeCommentsHsType (HsKindSig x _ _) = mconcat $ fmap nodeComments x +nodeCommentsHsType (HsDocTy x _ _) = mconcat $ fmap nodeComments x +nodeCommentsHsType (HsBangTy x _ _) = mconcat $ fmap nodeComments x +nodeCommentsHsType (HsExplicitListTy x _ _) = mconcat $ fmap nodeComments x +nodeCommentsHsType (HsExplicitTupleTy x _) = mconcat $ fmap nodeComments x +#else +nodeCommentsHsType (HsTyVar x _ _) = nodeComments x +nodeCommentsHsType (HsFunTy x _ _ _) = nodeComments x +nodeCommentsHsType (HsIParamTy x _ _) = nodeComments x +nodeCommentsHsType (HsKindSig x _ _) = nodeComments x +nodeCommentsHsType (HsDocTy x _ _) = nodeComments x +nodeCommentsHsType (HsBangTy x _ _) = nodeComments x +nodeCommentsHsType (HsExplicitListTy x _ _) = nodeComments x +nodeCommentsHsType (HsExplicitTupleTy x _) = nodeComments x +#endif +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +instance CommentExtraction (HsMatchContext (GenLocated SrcSpanAnnN RdrName)) where + nodeComments = nodeCommentsMatchContext +#else +instance CommentExtraction (HsMatchContext GhcPs) where + nodeComments = nodeCommentsMatchContext +#endif -instance CommentExtraction AnnExplicitSum where - nodeComments AnnExplicitSum {..} = - mconcat - $ fmap nodeComments - $ aesOpen : aesBarsBefore <> aesBarsAfter <> [aesClose] +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsMatchContext :: + HsMatchContext (GenLocated SrcSpanAnnN RdrName) -> NodeComments +#else +nodeCommentsMatchContext :: HsMatchContext GhcPs -> NodeComments +#endif +nodeCommentsMatchContext FunRhs {} = emptyNodeComments +nodeCommentsMatchContext CaseAlt {} = emptyNodeComments +nodeCommentsMatchContext IfAlt {} = emptyNodeComments +nodeCommentsMatchContext ArrowMatchCtxt {} = emptyNodeComments +nodeCommentsMatchContext PatBindRhs {} = emptyNodeComments +nodeCommentsMatchContext PatBindGuards {} = emptyNodeComments +nodeCommentsMatchContext RecUpd {} = emptyNodeComments +nodeCommentsMatchContext StmtCtxt {} = emptyNodeComments +nodeCommentsMatchContext ThPatSplice {} = emptyNodeComments +nodeCommentsMatchContext ThPatQuote {} = emptyNodeComments +nodeCommentsMatchContext PatSyn {} = emptyNodeComments +#if !MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsMatchContext LambdaExpr {} = emptyNodeComments +#endif +#if MIN_VERSION_ghc_lib_parser(9, 4, 1) && !MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsMatchContext LamCaseAlt {} = emptyNodeComments +#endif +instance CommentExtraction (Pat GhcPs) where + nodeComments = nodeCommentsPat -instance CommentExtraction EpAnnUnboundVar where - nodeComments EpAnnUnboundVar {..} = - mconcat - $ fmap - nodeComments - [fst hsUnboundBackquotes, snd hsUnboundBackquotes, hsUnboundHole] +nodeCommentsPat :: Pat GhcPs -> NodeComments +nodeCommentsPat WildPat {} = emptyNodeComments +nodeCommentsPat VarPat {} = emptyNodeComments +nodeCommentsPat (ListPat x _) = nodeComments x +nodeCommentsPat (SumPat x _ _ _) = nodeComments x +nodeCommentsPat SplicePat {} = emptyNodeComments +nodeCommentsPat LitPat {} = emptyNodeComments +nodeCommentsPat (NPlusKPat x _ _ _ _ _) = nodeComments x +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsPat ParPat {} = emptyNodeComments +#elif MIN_VERSION_ghc_lib_parser(9, 4, 1) +nodeCommentsPat (ParPat x _ _ _) = nodeComments x +#else +nodeCommentsPat (ParPat x _) = nodeComments x +#endif +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsPat AsPat {} = emptyNodeComments +#elif MIN_VERSION_ghc_lib_parser(9, 6, 1) +nodeCommentsPat (AsPat x _ _ _) = nodeComments x +#else +nodeCommentsPat (AsPat x _ _) = nodeComments x +#endif +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsPat (LazyPat x _) = mconcat $ fmap nodeComments x +nodeCommentsPat (BangPat x _) = mconcat $ fmap nodeComments x +nodeCommentsPat (TuplePat x _ _) = mconcat $ fmap nodeComments x +nodeCommentsPat ConPat {..} = mconcat $ fmap nodeComments pat_con_ext +nodeCommentsPat (ViewPat x _ _) = mconcat $ fmap nodeComments x +nodeCommentsPat (NPat x _ _ _) = mconcat $ fmap nodeComments x +nodeCommentsPat (SigPat x _ _) = mconcat $ fmap nodeComments x +#else +nodeCommentsPat (LazyPat x _) = nodeComments x +nodeCommentsPat (BangPat x _) = nodeComments x +nodeCommentsPat (TuplePat x _ _) = nodeComments x +nodeCommentsPat ConPat {..} = nodeComments pat_con_ext +nodeCommentsPat (ViewPat x _ _) = nodeComments x +nodeCommentsPat (NPat x _ _ _) = nodeComments x +nodeCommentsPat (SigPat x _ _) = nodeComments x +#endif +instance CommentExtraction (HsTupArg GhcPs) where + nodeComments = nodeCommentsHsTupArg -instance CommentExtraction AnnSig where - nodeComments AnnSig {..} = mconcat $ fmap nodeComments $ asDcolon : asRest +nodeCommentsHsTupArg :: HsTupArg GhcPs -> NodeComments +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsHsTupArg Present {} = emptyNodeComments +#else +nodeCommentsHsTupArg (Present x _) = nodeComments x +#endif +nodeCommentsHsTupArg (Missing x) = nodeComments x instance CommentExtraction (ConDeclField GhcPs) where nodeComments = nodeCommentsConDeclField @@ -1114,6 +1060,22 @@ instance CommentExtraction (HsFieldLabel GhcPs) where instance CommentExtraction RecConField where nodeComments (RecConField x) = nodeComments x #endif +#if MIN_VERSION_ghc_lib_parser(9, 4, 1) +instance CommentExtraction RecConField where + nodeComments (RecConField x) = nodeComments x +#else +instance CommentExtraction (HsBracket GhcPs) where + nodeComments ExpBr {} = emptyNodeComments + nodeComments PatBr {} = emptyNodeComments + nodeComments DecBrL {} = emptyNodeComments + nodeComments DecBrG {} = emptyNodeComments + nodeComments TypBr {} = emptyNodeComments + nodeComments VarBr {} = emptyNodeComments + nodeComments TExpBr {} = emptyNodeComments + +instance CommentExtraction (HsRecField' (FieldOcc GhcPs) a) where + nodeComments HsRecField {..} = nodeComments hsRecFieldAnn +#endif #if MIN_VERSION_ghc_lib_parser(9, 6, 1) instance CommentExtraction XImportDeclPass where nodeComments XImportDeclPass {..} = nodeComments ideclAnn @@ -1129,6 +1091,12 @@ instance CommentExtraction (HsTyLit GhcPs) where nodeComments HsStrTy {} = emptyNodeComments nodeComments HsCharTy {} = emptyNodeComments #else +instance CommentExtraction (HsSplice GhcPs) where + nodeComments (HsTypedSplice x _ _ _) = nodeComments x + nodeComments (HsUntypedSplice x _ _ _) = nodeComments x + nodeComments HsQuasiQuote {} = emptyNodeComments + nodeComments HsSpliced {} = emptyNodeComments + instance CommentExtraction ForeignImport where nodeComments CImport {} = emptyNodeComments @@ -1163,6 +1131,16 @@ instance CommentExtraction nodeComments HsArgPar {} = emptyNodeComments #endif #if MIN_VERSION_ghc_lib_parser(9, 10, 1) +instance CommentExtraction (EpAnn a) where + nodeComments (EpAnn ann _ cs) = NodeComments {..} + where + commentsBefore = priorComments cs + commentsOnSameLine = filter isCommentOnSameLine $ getFollowingComments cs + commentsAfter = + filter (not . isCommentOnSameLine) $ getFollowingComments cs + isCommentOnSameLine (L comAnn _) = + srcSpanEndLine (anchor ann) == srcSpanStartLine (anchor comAnn) + instance CommentExtraction (EpaLocation' NoComments) where nodeComments EpaSpan {} = emptyNodeComments nodeComments EpaDelta {} = emptyNodeComments @@ -1185,6 +1163,23 @@ instance CommentExtraction TrailingAnn where instance CommentExtraction AnnParen where nodeComments AnnParen {..} = mconcat $ fmap nodeComments [ap_open, ap_close] +#else +instance CommentExtraction Anchor where + nodeComments Anchor {} = emptyNodeComments + +instance CommentExtraction (SrcAnn a) where + nodeComments (SrcSpanAnn ep _) = nodeComments ep + +instance CommentExtraction (EpAnn a) where + nodeComments (EpAnn ann _ cs) = NodeComments {..} + where + commentsBefore = priorComments cs + commentsOnSameLine = filter isCommentOnSameLine $ getFollowingComments cs + commentsAfter = + filter (not . isCommentOnSameLine) $ getFollowingComments cs + isCommentOnSameLine (L comAnn _) = + srcSpanEndLine (anchor ann) == srcSpanStartLine (anchor comAnn) + nodeComments EpAnnNotUsed = emptyNodeComments #endif -- | Marks an AST node as never appearing in the AST. -- From 586ac755a74803e67d4a2ce167c9a60462badc5f Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 18:33:33 +0900 Subject: [PATCH 38/40] wip --- src/HIndent/Pretty/NodeComments.hs | 98 +++++++++++++++--------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index 3e68cf77f..c82a07854 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -36,55 +36,6 @@ class CommentExtraction a where instance CommentExtraction l => CommentExtraction (GenLocated l e) where nodeComments (L l _) = nodeComments l -instance CommentExtraction (HsBind GhcPs) where - nodeComments = nodeCommentsHsBind - -nodeCommentsHsBind :: HsBind GhcPs -> NodeComments -nodeCommentsHsBind FunBind {..} = nodeComments fun_id -#if MIN_VERSION_ghc_lib_parser(9, 10, 0) -nodeCommentsHsBind PatBind {} = emptyNodeComments -#else -nodeCommentsHsBind PatBind {..} = nodeComments pat_ext -#endif -nodeCommentsHsBind VarBind {} = emptyNodeComments -#if !MIN_VERSION_ghc_lib_parser(9, 4, 1) -nodeCommentsHsBind AbsBinds {} = emptyNodeComments -#endif -nodeCommentsHsBind PatSynBind {} = emptyNodeComments - -instance CommentExtraction (Sig GhcPs) where - nodeComments = nodeCommentsSig - -nodeCommentsSig :: Sig GhcPs -> NodeComments -nodeCommentsSig (TypeSig x _ _) = nodeComments x -nodeCommentsSig (PatSynSig x _ _) = nodeComments x -nodeCommentsSig (ClassOpSig x _ _ _) = nodeComments x -#if MIN_VERSION_ghc_lib_parser(9, 10, 1) -nodeCommentsSig (FixSig x _) = mconcat $ fmap nodeComments x -nodeCommentsSig (InlineSig x _ _) = mconcat $ fmap nodeComments x -nodeCommentsSig (SpecSig x _ _ _) = mconcat $ fmap nodeComments x -nodeCommentsSig (SpecInstSig (x, _) _) = mconcat $ fmap nodeComments x -nodeCommentsSig (MinimalSig (x, _) _) = mconcat $ fmap nodeComments x -nodeCommentsSig (SCCFunSig (x, _) _ _) = mconcat $ fmap nodeComments x -nodeCommentsSig (CompleteMatchSig (x, _) _ _) = mconcat $ fmap nodeComments x -#elif MIN_VERSION_ghc_lib_parser(9, 6, 1) -nodeCommentsSig (FixSig x _) = nodeComments x -nodeCommentsSig (InlineSig x _ _) = nodeComments x -nodeCommentsSig (SpecSig x _ _ _) = nodeComments x -nodeCommentsSig (SpecInstSig (x, _) _) = nodeComments x -nodeCommentsSig (MinimalSig (x, _) _) = nodeComments x -nodeCommentsSig (SCCFunSig (x, _) _ _) = nodeComments x -nodeCommentsSig (CompleteMatchSig (x, _) _ _) = nodeComments x -#else -nodeCommentsSig (FixSig x _) = nodeComments x -nodeCommentsSig (InlineSig x _ _) = nodeComments x -nodeCommentsSig (SpecSig x _ _ _) = nodeComments x -nodeCommentsSig IdSig {} = emptyNodeComments -nodeCommentsSig (SpecInstSig x _ _) = nodeComments x -nodeCommentsSig (MinimalSig x _ _) = nodeComments x -nodeCommentsSig (SCCFunSig x _ _ _) = nodeComments x -nodeCommentsSig (CompleteMatchSig x _ _ _) = nodeComments x -#endif instance CommentExtraction (HsDataDefn GhcPs) where nodeComments HsDataDefn {} = emptyNodeComments @@ -490,6 +441,55 @@ instance CommentExtraction EpAnnUnboundVar where instance CommentExtraction AnnSig where nodeComments AnnSig {..} = mconcat $ fmap nodeComments $ asDcolon : asRest +instance CommentExtraction (HsBind GhcPs) where + nodeComments = nodeCommentsHsBind + +nodeCommentsHsBind :: HsBind GhcPs -> NodeComments +nodeCommentsHsBind FunBind {..} = nodeComments fun_id +#if MIN_VERSION_ghc_lib_parser(9, 10, 0) +nodeCommentsHsBind PatBind {} = emptyNodeComments +#else +nodeCommentsHsBind PatBind {..} = nodeComments pat_ext +#endif +nodeCommentsHsBind VarBind {} = emptyNodeComments +#if !MIN_VERSION_ghc_lib_parser(9, 4, 1) +nodeCommentsHsBind AbsBinds {} = emptyNodeComments +#endif +nodeCommentsHsBind PatSynBind {} = emptyNodeComments + +instance CommentExtraction (Sig GhcPs) where + nodeComments = nodeCommentsSig + +nodeCommentsSig :: Sig GhcPs -> NodeComments +nodeCommentsSig (TypeSig x _ _) = nodeComments x +nodeCommentsSig (PatSynSig x _ _) = nodeComments x +nodeCommentsSig (ClassOpSig x _ _ _) = nodeComments x +#if MIN_VERSION_ghc_lib_parser(9, 10, 1) +nodeCommentsSig (FixSig x _) = mconcat $ fmap nodeComments x +nodeCommentsSig (InlineSig x _ _) = mconcat $ fmap nodeComments x +nodeCommentsSig (SpecSig x _ _ _) = mconcat $ fmap nodeComments x +nodeCommentsSig (SpecInstSig (x, _) _) = mconcat $ fmap nodeComments x +nodeCommentsSig (MinimalSig (x, _) _) = mconcat $ fmap nodeComments x +nodeCommentsSig (SCCFunSig (x, _) _ _) = mconcat $ fmap nodeComments x +nodeCommentsSig (CompleteMatchSig (x, _) _ _) = mconcat $ fmap nodeComments x +#elif MIN_VERSION_ghc_lib_parser(9, 6, 1) +nodeCommentsSig (FixSig x _) = nodeComments x +nodeCommentsSig (InlineSig x _ _) = nodeComments x +nodeCommentsSig (SpecSig x _ _ _) = nodeComments x +nodeCommentsSig (SpecInstSig (x, _) _) = nodeComments x +nodeCommentsSig (MinimalSig (x, _) _) = nodeComments x +nodeCommentsSig (SCCFunSig (x, _) _ _) = nodeComments x +nodeCommentsSig (CompleteMatchSig (x, _) _ _) = nodeComments x +#else +nodeCommentsSig (FixSig x _) = nodeComments x +nodeCommentsSig (InlineSig x _ _) = nodeComments x +nodeCommentsSig (SpecSig x _ _ _) = nodeComments x +nodeCommentsSig IdSig {} = emptyNodeComments +nodeCommentsSig (SpecInstSig x _ _) = nodeComments x +nodeCommentsSig (MinimalSig x _ _) = nodeComments x +nodeCommentsSig (SCCFunSig x _ _ _) = nodeComments x +nodeCommentsSig (CompleteMatchSig x _ _ _) = nodeComments x +#endif instance CommentExtraction (HsExpr GhcPs) where nodeComments = nodeCommentsHsExpr From 2fe5284e78b395603e1e6a839aa58ddf86280f0d Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 21:33:48 +0900 Subject: [PATCH 39/40] wip --- src/HIndent/Pretty/NodeComments.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index c82a07854..ab26ccd50 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -941,7 +941,7 @@ nodeCommentsHsPragE :: HsPragE GhcPs -> NodeComments #if MIN_VERSION_ghc_lib_parser(9, 6, 1) nodeCommentsHsPragE (HsPragSCC (x, _) _) = nodeComments x #else -nodeCommentsHsPragE (HsPragSCC x _) = nodeComments x +nodeCommentsHsPragE (HsPragSCC x _ _) = nodeComments x #endif instance CommentExtraction (IPBind GhcPs) where nodeComments = nodeCommentsIPBind From b352f3143056b0d4dbaadb65ab77c6f4362f2b80 Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 21:57:20 +0900 Subject: [PATCH 40/40] wip --- src/HIndent/Pretty/NodeComments.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/HIndent/Pretty/NodeComments.hs b/src/HIndent/Pretty/NodeComments.hs index ab26ccd50..ff8dd1955 100644 --- a/src/HIndent/Pretty/NodeComments.hs +++ b/src/HIndent/Pretty/NodeComments.hs @@ -1025,7 +1025,7 @@ nodeCommentsHsUntypedSplice :: HsUntypedSplice GhcPs -> NodeComments nodeCommentsHsUntypedSplice (HsUntypedSpliceExpr x _) = mconcat $ fmap nodeComments x #else -nodeCommentsHsUntypedSplice (HsUntypedSpliceExpr x) = nodeComments x +nodeCommentsHsUntypedSplice (HsUntypedSpliceExpr x _) = nodeComments x #endif nodeCommentsHsUntypedSplice HsQuasiQuote {} = emptyNodeComments #endif