-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
105 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{-# LANGUAGE CPP #-} | ||
{-# LANGUAGE RecordWildCards #-} | ||
|
||
module HIndent.Ast.Declaration.Warning | ||
( WarningDeclaration | ||
, mkWarningDeclaration | ||
) where | ||
|
||
import qualified GHC.Types.SourceText as GHC | ||
import qualified GHC.Types.SrcLoc as GHC | ||
import HIndent.Ast.Declaration.Warning.Kind | ||
import HIndent.Ast.NodeComments | ||
import qualified HIndent.GhcLibParserWrapper.GHC.Hs as GHC | ||
import qualified HIndent.GhcLibParserWrapper.GHC.Unit.Module.Warnings as GHC | ||
import {-# SOURCE #-} HIndent.Pretty | ||
import HIndent.Pretty.Combinators | ||
import HIndent.Pretty.NodeComments | ||
|
||
data WarningDeclaration = WarningDeclaration | ||
{ names :: [GHC.LIdP GHC.GhcPs] | ||
, kind :: Kind | ||
, reasons :: [GHC.Located GHC.StringLiteral] | ||
} | ||
|
||
instance CommentExtraction WarningDeclaration where | ||
nodeComments _ = NodeComments [] [] [] | ||
|
||
instance Pretty WarningDeclaration where | ||
pretty' WarningDeclaration {..} = do | ||
lined | ||
[ string "{-# " >> pretty kind | ||
, spaced [hCommaSep $ fmap pretty names, hCommaSep $ fmap pretty reasons] | ||
, string " #-}" | ||
] | ||
|
||
mkWarningDeclaration :: GHC.WarnDecl GHC.GhcPs -> WarningDeclaration | ||
#if MIN_VERSION_ghc_lib_parser(9, 8, 1) | ||
mkWarningDeclaration (GHC.Warning _ names (GHC.DeprecatedTxt _ rs)) = | ||
WarningDeclaration {kind = Deprecated, ..} | ||
where | ||
reasons = fmap (fmap GHC.hsDocString) rs | ||
mkWarningDeclaration (GHC.Warning _ names (GHC.WarningTxt _ _ rs)) = | ||
WarningDeclaration {kind = Warning, ..} | ||
where | ||
reasons = fmap (fmap GHC.hsDocString) rs | ||
#elif MIN_VERSION_ghc_lib_parser(9, 4, 1) | ||
mkWarningDeclaration (GHC.Warning _ names (GHC.DeprecatedTxt _ rs)) = | ||
WarningDeclaration {kind = Deprecated, ..} | ||
where | ||
reasons = fmap (fmap GHC.hsDocString) rs | ||
mkWarningDeclaration (GHC.Warning _ names (GHC.WarningTxt _ rs)) = | ||
WarningDeclaration {kind = Warning, ..} | ||
where | ||
reasons = fmap (fmap GHC.hsDocString) rs | ||
#else | ||
mkWarningDeclaration (GHC.Warning _ names (GHC.DeprecatedTxt _ reasons)) = | ||
WarningDeclaration {kind = Deprecated, ..} | ||
mkWarningDeclaration (GHC.Warning _ names (GHC.WarningTxt _ reasons)) = | ||
WarningDeclaration {kind = Warning, ..} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{-# LANGUAGE CPP #-} | ||
|
||
module HIndent.Ast.Declaration.Warning.Collection | ||
( WarningCollection | ||
, mkWarningCollection | ||
) where | ||
|
||
import HIndent.Ast.Declaration.Warning | ||
import HIndent.Ast.NodeComments | ||
import HIndent.Ast.WithComments | ||
import qualified HIndent.GhcLibParserWrapper.GHC.Hs as GHC | ||
import {-# SOURCE #-} HIndent.Pretty | ||
import HIndent.Pretty.Combinators | ||
import HIndent.Pretty.NodeComments | ||
|
||
newtype WarningCollection = | ||
WarningCollection [WithComments WarningDeclaration] | ||
|
||
instance CommentExtraction WarningCollection where | ||
nodeComments WarningCollection {} = NodeComments [] [] [] | ||
|
||
instance Pretty WarningCollection where | ||
pretty' (WarningCollection xs) = lined $ fmap pretty xs | ||
|
||
mkWarningCollection :: GHC.WarnDecls GHC.GhcPs -> WarningCollection | ||
#if MIN_VERSION_ghc_lib_parser(9, 6, 1) | ||
mkWarningCollection (GHC.Warnings _ xs) = | ||
WarningCollection $ fmap (fmap mkWarningDeclaration . fromGenLocated) xs | ||
#else | ||
mkWarningCollection (GHC.Warnings _ _ xs) = | ||
WarningCollection $ fmap (fmap mkWarningDeclaration . fromGenLocated) xs | ||
#endif |
4 changes: 2 additions & 2 deletions
4
src/HIndent/Ast/Module/Warning/Kind.hs → src/HIndent/Ast/Declaration/Warning/Kind.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters