From 0cda13304015ac29194f3ce67c767a79432900d2 Mon Sep 17 00:00:00 2001 From: Kazu Yamamoto Date: Thu, 27 Jan 2011 14:29:39 +0900 Subject: [PATCH] -o option to display operators, too. --- Browse.hs | 12 ++++++++++-- GHCMod.hs | 12 ++++++++---- Types.hs | 1 + 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Browse.hs b/Browse.hs index 9b770ef..fce16e2 100644 --- a/Browse.hs +++ b/Browse.hs @@ -10,9 +10,17 @@ import Types ---------------------------------------------------------------- browseModule :: Options -> String -> IO String -browseModule opt mdlName = convert opt . validate <$> browse mdlName +browseModule opt mdlName = convert opt . format <$> browse mdlName where - validate = sort . filter (isAlpha.head) + 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'" browse :: String -> IO [String] browse mdlName = withGHC $ do diff --git a/GHCMod.hs b/GHCMod.hs index 87d0be6..4a9a100 100644 --- a/GHCMod.hs +++ b/GHCMod.hs @@ -23,13 +23,13 @@ import Types usage :: String usage = "ghc-mod version 0.5.1\n" ++ "Usage:\n" - ++ "\t ghc-mod [-l] list\n" - ++ "\t ghc-mod [-l] lang\n" - ++ "\t ghc-mod [-l] browse [ ...]\n" + ++ "\t ghc-mod list [-l]\n" + ++ "\t ghc-mod lang [-l]\n" + ++ "\t ghc-mod browse [-l] [-o] [ ...]\n" ++ "\t ghc-mod check \n" ++ "\t ghc-mod type \n" ++ "\t ghc-mod info \n" - ++ "\t ghc-mod [-h opt] lint \n" + ++ "\t ghc-mod lint [-h opt] \n" ++ "\t ghc-mod boot\n" ++ "\t ghc-mod help\n" @@ -39,6 +39,7 @@ defaultOptions :: Options defaultOptions = Options { convert = toPlain , hlintOpts = [] + , operators = False } argspec :: [OptDescr (Options -> Options)] @@ -48,6 +49,9 @@ argspec = [ Option "l" ["tolisp"] , Option "h" ["hlintOpt"] (ReqArg (\h opts -> opts { hlintOpts = h : hlintOpts opts }) "hlintOpt") "hint to be ignored" + , Option "o" ["operators"] + (NoArg (\opts -> opts { operators = True })) + "print operators, too" ] parseArgs :: [OptDescr (Options -> Options)] -> [String] -> (Options, [String]) diff --git a/Types.hs b/Types.hs index 51ee086..618f241 100644 --- a/Types.hs +++ b/Types.hs @@ -11,6 +11,7 @@ import GHC.Paths (libdir) data Options = Options { convert :: [String] -> String , hlintOpts :: [String] + , operators :: Bool } withGHC :: (MonadPlus m) => Ghc (m a) -> IO (m a)