ghc-mod/Browse.hs

33 lines
932 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
2012-02-14 07:09:53 +00:00
import GHCApi
2010-04-28 06:51:30 +00:00
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
browseModule opt mdlName = convert opt . format <$> browse opt 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
browse :: Options -> String -> IO [String]
browse opt mdlName = withGHC $ do
2012-08-06 00:43:47 +00:00
_ <- initSession0 opt
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)