File: Haddock.hs

package info (click to toggle)
lambdabot 4.2.3.2-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 5,584 kB
  • sloc: haskell: 10,102; ansic: 76; makefile: 7
file content (29 lines) | stat: -rw-r--r-- 954 bytes parent folder | download
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
{-# LANGUAGE TemplateHaskell, MultiParamTypeClasses, TypeSynonymInstances, FlexibleInstances #-}
-- | Hackish Haddock module.
module Plugin.Haddock (theModule) where

import Plugin

import qualified Data.Map as M
import qualified Data.ByteString.Char8 as P
import Data.ByteString.Char8 (ByteString,pack)

$(plugin "Haddock")

type HaddockState = M.Map ByteString [ByteString]

instance Module HaddockModule HaddockState where
    moduleCmds      _ = ["index"]
    moduleHelp    _ _ = "index <ident>. Returns the Haskell modules in which <ident> is defined"
    moduleDefState  _ = return M.empty
    moduleSerialize _ = Just (readOnly readPacked)
    fprocess_ _ _ k = readMS >>= \m -> box $ maybe
        (pack "bzzt")
        (P.intercalate (pack ", "))
        (M.lookup (stripPs k) m)

        where
          -- make \@index ($) work.
          stripPs :: ByteString -> ByteString
          stripPs = fst . P.spanEnd (==')') . snd . P.span (=='(')