ghc-mod/Browse.hs

32 lines
890 B
Haskell
Raw Normal View History

2010-03-11 10:03:17 +00:00
module Browse (browseModule) where
2010-04-28 06:51:30 +00:00
import Control.Applicative
2010-03-11 10:03:17 +00:00
import Data.Char
import Data.List
2010-04-28 06:51:30 +00:00
import GHC
import Name
2010-04-30 09:36:31 +00:00
import Types
2010-03-11 10:03:17 +00:00
----------------------------------------------------------------
2010-03-11 13:39:07 +00:00
browseModule :: Options -> String -> IO String
2011-01-27 05:29:39 +00:00
browseModule opt mdlName = convert opt . format <$> browse mdlName
2010-03-11 10:03:17 +00:00
where
2011-01-27 05:29:39 +00:00
format
| operators opt = formatOps
| otherwise = removeOps
removeOps = sort . filter (isAlpha.head)
formatOps = sort . map formatOps'
formatOps' x@(s:_)
| isAlpha s = x
| otherwise = '(' : x ++ ")"
formatOps' [] = error "formatOps'"
2010-03-11 10:03:17 +00:00
2010-04-28 06:51:30 +00:00
browse :: String -> IO [String]
2010-04-30 09:36:31 +00:00
browse mdlName = withGHC $ do
initSession0
2010-04-30 07:27:10 +00:00
maybeNamesToStrings <$> lookupModuleInfo
2010-04-27 01:28:00 +00:00
where
lookupModuleInfo = findModule (mkModuleName mdlName) Nothing >>= getModuleInfo
2010-04-28 06:51:30 +00:00
maybeNamesToStrings = maybe [] (map getOccString . modInfoExports)