{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleInstances #-}
module HsSyn (
module HsBinds,
module HsDecls,
module HsExpr,
module HsImpExp,
module HsLit,
module HsPat,
module HsTypes,
module HsUtils,
module HsDoc,
module PlaceHolder,
module HsExtension,
Fixity,
HsModule(..),
) where
import GhcPrelude
import HsDecls
import HsBinds
import HsExpr
import HsImpExp
import HsLit
import PlaceHolder
import HsExtension
import HsPat
import HsTypes
import BasicTypes ( Fixity, WarningTxt )
import HsUtils
import HsDoc
import HsInstances ()
import Outputable
import SrcLoc
import Module ( ModuleName )
import Data.Data hiding ( Fixity )
data HsModule pass
= HsModule {
hsmodName :: Maybe (Located ModuleName),
hsmodExports :: Maybe (Located [LIE pass]),
hsmodImports :: [LImportDecl pass],
hsmodDecls :: [LHsDecl pass],
hsmodDeprecMessage :: Maybe (Located WarningTxt),
hsmodHaddockModHeader :: Maybe LHsDocString
}
deriving instance Data (HsModule GhcPs)
deriving instance Data (HsModule GhcRn)
deriving instance Data (HsModule GhcTc)
instance (p ~ GhcPass pass, OutputableBndrId p) => Outputable (HsModule p) where
ppr (HsModule Nothing _ imports decls _ mbDoc)
= pp_mb mbDoc $$ pp_nonnull imports
$$ pp_nonnull decls
ppr (HsModule (Just name) exports imports decls deprec mbDoc)
= vcat [
pp_mb mbDoc,
case exports of
Nothing -> pp_header (text "where")
Just es -> vcat [
pp_header lparen,
nest 8 (fsep (punctuate comma (map ppr (unLoc es)))),
nest 4 (text ") where")
],
pp_nonnull imports,
pp_nonnull decls
]
where
pp_header rest = case deprec of
Nothing -> pp_modname <+> rest
Just d -> vcat [ pp_modname, ppr d, rest ]
pp_modname = text "module" <+> ppr name
pp_mb :: Outputable t => Maybe t -> SDoc
pp_mb (Just x) = ppr x
pp_mb Nothing = empty
pp_nonnull :: Outputable t => [t] -> SDoc
pp_nonnull [] = empty
pp_nonnull xs = vcat (map ppr xs)