blob: c5198598d103926355b6251562b47cad886cf80d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
{-# LANGUAGE PatternGuards #-}
-----------------------------------------------------------------------------
-- |
-- Module : Haddock.Interface.ExtractFnArgDocs
-- Copyright : (c) Isaac Dupree 2009,
-- License : BSD-like
--
-- Maintainer : haddock@projects.haskell.org
-- Stability : experimental
-- Portability : portable
-----------------------------------------------------------------------------
module Haddock.Interface.ExtractFnArgDocs (
getDeclFnArgDocs, getSigFnArgDocs, getTypeFnArgDocs
) where
import Haddock.Types
import qualified Data.Map as Map
import Data.Map (Map)
import GHC
-- the type of Name doesn't matter, except in 6.10 where
-- HsDocString = HsDoc Name, so we can't just say "HsDecl name" yet.
getDeclFnArgDocs :: HsDecl Name -> Map Int HsDocString
getDeclFnArgDocs (SigD (TypeSig _ ty)) = getTypeFnArgDocs ty
getDeclFnArgDocs (ForD (ForeignImport _ ty _)) = getTypeFnArgDocs ty
getDeclFnArgDocs _ = Map.empty
getSigFnArgDocs :: Sig Name -> Map Int HsDocString
getSigFnArgDocs (TypeSig _ ty) = getTypeFnArgDocs ty
getSigFnArgDocs _ = Map.empty
getTypeFnArgDocs :: LHsType Name -> Map Int HsDocString
getTypeFnArgDocs ty = getLTypeDocs 0 ty
getLTypeDocs :: Int -> LHsType Name -> Map Int HsDocString
getLTypeDocs n (L _ ty) = getTypeDocs n ty
getTypeDocs :: Int -> HsType Name -> Map Int HsDocString
getTypeDocs n (HsForAllTy _ _ _ ty) = getLTypeDocs n ty
getTypeDocs n (HsFunTy (L _ (HsDocTy _arg_type (L _ doc))) res_type) =
Map.insert n doc $ getLTypeDocs (n+1) res_type
getTypeDocs n (HsFunTy _ res_type) = getLTypeDocs (n+1) res_type
getTypeDocs n (HsDocTy _res_type (L _ doc)) = Map.singleton n doc
getTypeDocs _ _res_type = Map.empty
|