-
Notifications
You must be signed in to change notification settings - Fork 114
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
5 changed files
with
54 additions
and
32 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,45 @@ | ||
{-# LANGUAGE RecordWildCards #-} | ||
|
||
module HIndent.Ast.Declaration.StandAloneDeriving | ||
( StandAloneDeriving | ||
, mkStandAloneDeriving | ||
) where | ||
|
||
import HIndent.Applicative | ||
import HIndent.Ast.Declaration.Data.Deriving.Strategy | ||
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 | ||
|
||
data StandAloneDeriving = StandAloneDeriving | ||
{ strategy :: Maybe (WithComments DerivingStrategy) | ||
, className :: GHC.LHsSigType GHC.GhcPs | ||
} | ||
|
||
instance CommentExtraction StandAloneDeriving where | ||
nodeComments StandAloneDeriving {} = NodeComments [] [] [] | ||
|
||
instance Pretty StandAloneDeriving where | ||
pretty' StandAloneDeriving {strategy = Just strategy, ..} | ||
| isViaStrategy (getNode strategy) = | ||
spaced | ||
[ string "deriving" | ||
, pretty strategy | ||
, string "instance" | ||
, pretty className | ||
] | ||
pretty' StandAloneDeriving {..} = do | ||
string "deriving " | ||
whenJust strategy $ \x -> pretty x >> space | ||
string "instance " | ||
pretty className | ||
|
||
mkStandAloneDeriving :: GHC.DerivDecl GHC.GhcPs -> StandAloneDeriving | ||
mkStandAloneDeriving GHC.DerivDecl {deriv_type = GHC.HsWC {..}, ..} = | ||
StandAloneDeriving {..} | ||
where | ||
strategy = fmap (fmap mkDerivingStrategy . fromGenLocated) deriv_strategy | ||
className = hswc_body |
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