1 module RnHsDoc ( rnHsDoc, rnLHsDoc, rnMbLHsDoc, rnMbHsDoc ) where
3 import TcRnMonad ( RnM )
4 import RnEnv ( dataTcOccs, lookupGreRn_maybe )
5 import HsDoc ( HsDoc(..) )
7 import RdrName ( RdrName, isRdrDataCon, isRdrTc, gre_name )
9 import SrcLoc ( Located(..) )
10 import Outputable ( ppr, defaultUserStyle )
12 import Data.List ( (\\) )
13 import Debug.Trace ( trace )
15 rnMbHsDoc mb_doc = case mb_doc of
19 Nothing -> return Nothing
21 rnMbLHsDoc mb_doc = case mb_doc of
25 Nothing -> return Nothing
27 rnLHsDoc (L pos doc) = do
32 ids2string (x:_) = show $ ppr x defaultUserStyle
34 rnHsDoc :: HsDoc RdrName -> RnM (HsDoc Name)
35 rnHsDoc doc = case doc of
37 DocEmpty -> return DocEmpty
42 return (DocAppend a' b')
44 DocString str -> return (DocString str)
46 DocParagraph doc -> do
48 return (DocParagraph doc')
50 DocIdentifier ids -> do
51 let choices = concatMap dataTcOccs ids
52 mb_gres <- mapM lookupGreRn_maybe choices
53 case [gre_name gre | Just gre <- mb_gres] of
54 [] -> return (DocString (ids2string ids))
55 ids' -> return (DocIdentifier ids')
57 DocModule str -> return (DocModule str)
61 return (DocEmphasis doc')
63 DocMonospaced doc -> do
65 return (DocMonospaced doc')
67 DocUnorderedList docs -> do
68 docs' <- mapM rnHsDoc docs
69 return (DocUnorderedList docs')
71 DocOrderedList docs -> do
72 docs' <- mapM rnHsDoc docs
73 return (DocOrderedList docs')
76 list' <- mapM (\(a,b) -> do
80 return (DocDefList list')
82 DocCodeBlock doc -> do
84 return (DocCodeBlock doc')
86 DocURL str -> return (DocURL str)
88 DocAName str -> return (DocAName str)