-
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.
* Create `Warning.hs` * `WithComments` * Do not depend on GHC AST * Remove an unused instance * Remove an unused type * pretty kind * `prettyMsgs` * Separation * Fix * Format * Fix * Fix
- Loading branch information
Showing
7 changed files
with
85 additions
and
40 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,58 @@ | ||
{-# LANGUAGE CPP #-} | ||
{-# LANGUAGE RecordWildCards #-} | ||
|
||
module HIndent.Ast.Module.Warning | ||
( ModuleWarning | ||
, mkModuleWarning | ||
) where | ||
|
||
import HIndent.Ast.Module.Warning.Kind | ||
import HIndent.Ast.NodeComments | ||
import HIndent.Ast.WithComments | ||
import qualified HIndent.GhcLibParserWrapper.GHC.Hs as GHC | ||
import qualified HIndent.GhcLibParserWrapper.GHC.Unit.Module.Warnings as GHC | ||
import HIndent.Pretty | ||
import HIndent.Pretty.Combinators | ||
import HIndent.Pretty.NodeComments | ||
|
||
data ModuleWarning = ModuleWarning | ||
{ messages :: [String] | ||
, kind :: Kind | ||
} | ||
|
||
instance CommentExtraction ModuleWarning where | ||
nodeComments _ = NodeComments [] [] [] | ||
|
||
instance Pretty ModuleWarning where | ||
pretty' ModuleWarning {..} = do | ||
string "{-# " | ||
pretty kind | ||
space | ||
prettyMsgs | ||
string " #-}" | ||
where | ||
prettyMsgs = | ||
case messages of | ||
[x] -> string x | ||
xs -> hList $ fmap string xs | ||
|
||
mkModuleWarning :: GHC.HsModule' -> Maybe (WithComments ModuleWarning) | ||
mkModuleWarning = | ||
fmap (fromGenLocated . fmap fromWarningTxt) . GHC.getDeprecMessage | ||
|
||
fromWarningTxt :: GHC.WarningTxt' -> ModuleWarning | ||
#if MIN_VERSION_ghc_lib_parser(9, 8, 1) | ||
fromWarningTxt (GHC.WarningTxt _ _ s) = ModuleWarning {..} | ||
where | ||
messages = fmap showOutputable s | ||
kind = Warning | ||
#else | ||
fromWarningTxt (GHC.WarningTxt _ s) = ModuleWarning {..} | ||
where | ||
messages = fmap showOutputable s | ||
kind = Warning | ||
#endif | ||
fromWarningTxt (GHC.DeprecatedTxt _ s) = ModuleWarning {..} | ||
where | ||
messages = fmap showOutputable s | ||
kind = Deprecated |
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,19 @@ | ||
module HIndent.Ast.Module.Warning.Kind | ||
( Kind(..) | ||
) where | ||
|
||
import HIndent.Ast.NodeComments | ||
import HIndent.Pretty | ||
import HIndent.Pretty.Combinators | ||
import HIndent.Pretty.NodeComments | ||
|
||
data Kind | ||
= Warning | ||
| Deprecated | ||
|
||
instance CommentExtraction Kind where | ||
nodeComments _ = NodeComments [] [] [] | ||
|
||
instance Pretty Kind where | ||
pretty' Warning = string "WARNING" | ||
pretty' Deprecated = string "DEPRECATED" |
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