From 46ea9d4ee6c9c2e5b9c2c099cff54d38a6af709e Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sat, 7 Sep 2024 17:45:36 +0900 Subject: [PATCH] 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