{-# LANGUAGE RecordWildCards #-}
module HIndent.Ast.Declaration.Data.Header
( Header
, mkHeader
) where
import HIndent.Applicative
import HIndent.Ast.Context
import HIndent.Ast.Declaration.Data.NewOrData
import HIndent.Ast.Name.Prefix
import HIndent.Ast.NodeComments
import HIndent.Ast.Type.Variable
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 =
{ Header -> NewOrData
newOrData :: NewOrData
, Header -> WithComments PrefixName
name :: WithComments PrefixName
, Header -> Maybe (WithComments Context)
context :: Maybe (WithComments Context)
, Header -> [WithComments TypeVariable]
typeVariables :: [WithComments TypeVariable]
}
instance CommentExtraction Header where
nodeComments :: Header -> NodeComments
nodeComments Header {} = [LEpaComment] -> [LEpaComment] -> [LEpaComment] -> NodeComments
NodeComments [] [] []
instance Pretty Header where
pretty' :: Header -> Printer ()
pretty' Header {[WithComments TypeVariable]
Maybe (WithComments Context)
WithComments PrefixName
NewOrData
newOrData :: Header -> NewOrData
name :: Header -> WithComments PrefixName
context :: Header -> Maybe (WithComments Context)
typeVariables :: Header -> [WithComments TypeVariable]
newOrData :: NewOrData
name :: WithComments PrefixName
context :: Maybe (WithComments Context)
typeVariables :: [WithComments TypeVariable]
..} = do
(NewOrData -> Printer ()
forall a. Pretty a => a -> Printer ()
pretty NewOrData
newOrData Printer () -> Printer () -> Printer ()
forall a b. Printer a -> Printer b -> Printer b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Printer ()
space) Printer () -> Printer () -> Printer ()
forall a. Printer () -> Printer a -> Printer a
|=> do
Maybe (WithComments Context)
-> (WithComments Context -> Printer ()) -> Printer ()
forall (m :: * -> *) a.
Applicative m =>
Maybe a -> (a -> m ()) -> m ()
whenJust Maybe (WithComments Context)
context ((WithComments Context -> Printer ()) -> Printer ())
-> (WithComments Context -> Printer ()) -> Printer ()
forall a b. (a -> b) -> a -> b
$ \WithComments Context
c -> WithComments Context -> Printer ()
forall a. Pretty a => a -> Printer ()
pretty WithComments Context
c Printer () -> Printer () -> Printer ()
forall a b. Printer a -> Printer b -> Printer b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> HasCallStack => String -> Printer ()
String -> Printer ()
string String
" =>" Printer () -> Printer () -> Printer ()
forall a b. Printer a -> Printer b -> Printer b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Printer ()
newline
WithComments PrefixName -> Printer ()
forall a. Pretty a => a -> Printer ()
pretty WithComments PrefixName
name
[Printer ()] -> Printer ()
spacePrefixed ([Printer ()] -> Printer ()) -> [Printer ()] -> Printer ()
forall a b. (a -> b) -> a -> b
$ (WithComments TypeVariable -> Printer ())
-> [WithComments TypeVariable] -> [Printer ()]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap WithComments TypeVariable -> Printer ()
forall a. Pretty a => a -> Printer ()
pretty [WithComments TypeVariable]
typeVariables
mkHeader :: GHC.TyClDecl GHC.GhcPs -> Maybe Header
GHC.DataDecl {tcdDataDefn :: forall pass. TyClDecl pass -> HsDataDefn pass
tcdDataDefn = defn :: HsDataDefn GhcPs
defn@GHC.HsDataDefn {HsDeriving GhcPs
Maybe (LHsContext GhcPs)
Maybe (XRec GhcPs CType)
Maybe (LHsKind GhcPs)
XCHsDataDefn GhcPs
DataDefnCons (LConDecl GhcPs)
dd_ext :: XCHsDataDefn GhcPs
dd_ctxt :: Maybe (LHsContext GhcPs)
dd_cType :: Maybe (XRec GhcPs CType)
dd_kindSig :: Maybe (LHsKind GhcPs)
dd_cons :: DataDefnCons (LConDecl GhcPs)
dd_derivs :: HsDeriving GhcPs
dd_derivs :: forall pass. HsDataDefn pass -> HsDeriving pass
dd_cons :: forall pass. HsDataDefn pass -> DataDefnCons (LConDecl pass)
dd_kindSig :: forall pass. HsDataDefn pass -> Maybe (LHsKind pass)
dd_cType :: forall pass. HsDataDefn pass -> Maybe (XRec pass CType)
dd_ctxt :: forall pass. HsDataDefn pass -> Maybe (LHsContext pass)
dd_ext :: forall pass. HsDataDefn pass -> XCHsDataDefn pass
..}, XDataDecl GhcPs
LIdP GhcPs
LexicalFixity
LHsQTyVars GhcPs
tcdDExt :: XDataDecl GhcPs
tcdLName :: LIdP GhcPs
tcdTyVars :: LHsQTyVars GhcPs
tcdFixity :: LexicalFixity
tcdFixity :: forall pass. TyClDecl pass -> LexicalFixity
tcdTyVars :: forall pass. TyClDecl pass -> LHsQTyVars pass
tcdLName :: forall pass. TyClDecl pass -> LIdP pass
tcdDExt :: forall pass. TyClDecl pass -> XDataDecl pass
..} =
Header -> Maybe Header
forall a. a -> Maybe a
Just Header {[WithComments TypeVariable]
Maybe (WithComments Context)
WithComments PrefixName
NewOrData
newOrData :: NewOrData
name :: WithComments PrefixName
context :: Maybe (WithComments Context)
typeVariables :: [WithComments TypeVariable]
newOrData :: NewOrData
context :: Maybe (WithComments Context)
name :: WithComments PrefixName
typeVariables :: [WithComments TypeVariable]
..}
where
newOrData :: NewOrData
newOrData = HsDataDefn GhcPs -> NewOrData
mkNewOrData HsDataDefn GhcPs
defn
context :: Maybe (WithComments Context)
context = (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcPs)]
-> WithComments Context)
-> Maybe
(GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcPs)])
-> Maybe (WithComments Context)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (([GenLocated SrcSpanAnnA (HsType GhcPs)] -> Context)
-> WithComments [GenLocated SrcSpanAnnA (HsType GhcPs)]
-> WithComments Context
forall a b. (a -> b) -> WithComments a -> WithComments b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap HsContext GhcPs -> Context
[GenLocated SrcSpanAnnA (HsType GhcPs)] -> Context
mkContext (WithComments [GenLocated SrcSpanAnnA (HsType GhcPs)]
-> WithComments Context)
-> (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcPs)]
-> WithComments [GenLocated SrcSpanAnnA (HsType GhcPs)])
-> GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcPs)]
-> WithComments Context
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcPs)]
-> WithComments [GenLocated SrcSpanAnnA (HsType GhcPs)]
forall l a. CommentExtraction l => GenLocated l a -> WithComments a
fromGenLocated) Maybe (LHsContext GhcPs)
Maybe
(GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcPs)])
dd_ctxt
name :: WithComments PrefixName
name = GenLocated SrcSpanAnnN PrefixName -> WithComments PrefixName
forall l a. CommentExtraction l => GenLocated l a -> WithComments a
fromGenLocated (GenLocated SrcSpanAnnN PrefixName -> WithComments PrefixName)
-> GenLocated SrcSpanAnnN PrefixName -> WithComments PrefixName
forall a b. (a -> b) -> a -> b
$ (RdrName -> PrefixName)
-> GenLocated SrcSpanAnnN RdrName
-> GenLocated SrcSpanAnnN PrefixName
forall a b.
(a -> b) -> GenLocated SrcSpanAnnN a -> GenLocated SrcSpanAnnN b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap RdrName -> PrefixName
mkPrefixName LIdP GhcPs
GenLocated SrcSpanAnnN RdrName
tcdLName
typeVariables :: [WithComments TypeVariable]
typeVariables =
(HsTyVarBndr (HsBndrVis GhcPs) GhcPs -> TypeVariable)
-> WithComments (HsTyVarBndr (HsBndrVis GhcPs) GhcPs)
-> WithComments TypeVariable
forall a b. (a -> b) -> WithComments a -> WithComments b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap HsTyVarBndr (HsBndrVis GhcPs) GhcPs -> TypeVariable
forall a. HsTyVarBndr a GhcPs -> TypeVariable
mkTypeVariable (WithComments (HsTyVarBndr (HsBndrVis GhcPs) GhcPs)
-> WithComments TypeVariable)
-> (GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcPs) GhcPs)
-> WithComments (HsTyVarBndr (HsBndrVis GhcPs) GhcPs))
-> GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcPs) GhcPs)
-> WithComments TypeVariable
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcPs) GhcPs)
-> WithComments (HsTyVarBndr (HsBndrVis GhcPs) GhcPs)
forall l a. CommentExtraction l => GenLocated l a -> WithComments a
fromGenLocated (GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcPs) GhcPs)
-> WithComments TypeVariable)
-> [GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcPs) GhcPs)]
-> [WithComments TypeVariable]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LHsQTyVars GhcPs -> [LHsTyVarBndr (HsBndrVis GhcPs) GhcPs]
forall pass.
LHsQTyVars pass -> [LHsTyVarBndr (HsBndrVis pass) pass]
GHC.hsq_explicit LHsQTyVars GhcPs
tcdTyVars
mkHeader TyClDecl GhcPs
_ = Maybe Header
forall a. Maybe a
Nothing