module Haddock.Types where
import Haddock.DocName
import Data.Map (Map)
import qualified Data.Map as Map
import GHC hiding (NoLink)
import Name
type Decl = LHsDecl Name
type Doc = HsDoc Name
type DeclInfo = (Decl, Maybe Doc, [(Name, Maybe Doc)])
data DocOption
= OptHide
| OptPrune
| OptIgnoreExports
| OptNotHome
deriving (Eq, Show)
data ExportItem name
= ExportDecl {
expItemDecl :: LHsDecl name,
expItemMbDoc :: Maybe (HsDoc name),
expItemSubDocs :: [(name, Maybe (HsDoc name))],
expItemInstances :: [InstHead name]
}
| ExportNoDecl {
expItemName :: name,
expItemSubs :: [name]
}
| ExportGroup {
expItemSectionLevel :: Int,
expItemSectionId :: String,
expItemSectionText :: HsDoc name
}
| ExportDoc (HsDoc name)
| ExportModule Module
type InstHead name = ([HsPred name], name, [HsType name])
type ModuleMap = Map Module Interface
type InstIfaceMap = Map Module InstalledInterface
type DocMap = Map Name (HsDoc DocName)
type LinkEnv = Map Name Module
data GhcModule = GhcModule {
ghcModule :: Module,
ghcFilename :: FilePath,
ghcMbDocOpts :: Maybe String,
ghcHaddockModInfo :: HaddockModInfo Name,
ghcMbDoc :: Maybe (HsDoc Name),
ghcGroup :: HsGroup Name,
ghcMbExports :: Maybe [LIE Name],
ghcExportedNames :: [Name],
ghcDefinedNames :: [Name],
ghcNamesInScope :: [Name],
ghcInstances :: [Instance]
}
data Interface = Interface {
ifaceMod :: Module,
ifaceOrigFilename :: FilePath,
ifaceInfo :: !(HaddockModInfo Name),
ifaceDoc :: !(Maybe (HsDoc Name)),
ifaceRnDoc :: Maybe (HsDoc DocName),
ifaceOptions :: ![DocOption],
ifaceDeclMap :: Map Name DeclInfo,
ifaceRnDocMap :: Map Name (HsDoc DocName),
ifaceSubMap :: Map Name [Name],
ifaceExportItems :: ![ExportItem Name],
ifaceRnExportItems :: [ExportItem DocName],
ifaceLocals :: ![Name],
ifaceExports :: ![Name],
ifaceVisibleExports :: ![Name],
ifaceInstances :: ![Instance]
}
data InstalledInterface = InstalledInterface {
instMod :: Module,
instInfo :: HaddockModInfo Name,
instDocMap :: Map Name (HsDoc DocName),
instExports :: [Name],
instVisibleExports :: [Name],
instOptions :: [DocOption],
instSubMap :: Map Name [Name]
}
toInstalledIface :: Interface -> InstalledInterface
toInstalledIface interface = InstalledInterface {
instMod = ifaceMod interface,
instInfo = ifaceInfo interface,
instDocMap = ifaceRnDocMap interface,
instExports = ifaceExports interface,
instVisibleExports = ifaceVisibleExports interface,
instOptions = ifaceOptions interface,
instSubMap = ifaceSubMap interface
}
data DocMarkup id a = Markup {
markupEmpty :: a,
markupString :: String -> a,
markupParagraph :: a -> a,
markupAppend :: a -> a -> a,
markupIdentifier :: [id] -> a,
markupModule :: String -> a,
markupEmphasis :: a -> a,
markupMonospaced :: a -> a,
markupUnorderedList :: [a] -> a,
markupOrderedList :: [a] -> a,
markupDefList :: [(a,a)] -> a,
markupCodeBlock :: a -> a,
markupURL :: String -> a,
markupAName :: String -> a,
markupPic :: String -> a
}
type ErrMsg = String
newtype ErrMsgM a = Writer { runWriter :: (a, [ErrMsg]) }
instance Monad ErrMsgM where
return a = Writer (a, [])
m >>= k = Writer $ let
(a, w) = runWriter m
(b, w') = runWriter (k a)
in (b, w ++ w')
tell :: [ErrMsg] -> ErrMsgM ()
tell w = Writer ((), w)