2 module RnHsDoc ( rnHaddock, rnHsDoc, rnLHsDoc, rnMbLHsDoc ) where
5 import TcRnMonad ( RnM )
6 import RnEnv ( dataTcOccs, lookupGreRn_maybe )
9 import RdrName ( RdrName, gre_name )
11 import SrcLoc ( Located(..) )
12 import Outputable ( ppr, defaultUserStyle )
15 rnHaddock :: HaddockModInfo RdrName -> Maybe (HsDoc RdrName)
16 -> TcGblEnv -> RnM TcGblEnv
17 rnHaddock module_info maybe_doc tcg_env
18 = do { rn_module_doc <- rnMbHsDoc maybe_doc ;
20 -- Rename the Haddock module info
21 ; rn_description <- rnMbHsDoc (hmi_description module_info)
22 ; let { rn_module_info = module_info { hmi_description = rn_description } }
24 ; return (tcg_env { tcg_doc = rn_module_doc,
25 tcg_hmi = rn_module_info }) }
27 rnMbHsDoc :: Maybe (HsDoc RdrName) -> RnM (Maybe (HsDoc Name))
28 rnMbHsDoc mb_doc = case mb_doc of
32 Nothing -> return Nothing
34 rnMbLHsDoc :: Maybe (LHsDoc RdrName) -> RnM (Maybe (LHsDoc Name))
35 rnMbLHsDoc mb_doc = case mb_doc of
39 Nothing -> return Nothing
41 rnLHsDoc :: LHsDoc RdrName -> RnM (LHsDoc Name)
42 rnLHsDoc (L pos doc) = do
46 ids2string :: [RdrName] -> String
48 ids2string (x:_) = show $ ppr x defaultUserStyle
50 rnHsDoc :: HsDoc RdrName -> RnM (HsDoc Name)
51 rnHsDoc doc = case doc of
53 DocEmpty -> return DocEmpty
58 return (DocAppend a' b')
60 DocString str -> return (DocString str)
62 DocParagraph doc -> do
64 return (DocParagraph doc')
66 DocIdentifier ids -> do
67 let choices = concatMap dataTcOccs ids
68 mb_gres <- mapM lookupGreRn_maybe choices
69 case [gre_name gre | Just gre <- mb_gres] of
70 [] -> return (DocString (ids2string ids))
71 ids' -> return (DocIdentifier ids')
73 DocModule str -> return (DocModule str)
77 return (DocEmphasis doc')
79 DocMonospaced doc -> do
81 return (DocMonospaced doc')
83 DocUnorderedList docs -> do
84 docs' <- mapM rnHsDoc docs
85 return (DocUnorderedList docs')
87 DocOrderedList docs -> do
88 docs' <- mapM rnHsDoc docs
89 return (DocOrderedList docs')
92 list' <- mapM (\(a,b) -> do
96 return (DocDefList list')
98 DocCodeBlock doc -> do
100 return (DocCodeBlock doc')
102 DocURL str -> return (DocURL str)
104 DocPic str -> return (DocPic str)
106 DocAName str -> return (DocAName str)