From 625d4661e7190b7223d2d465976c3e353a01ec48 Mon Sep 17 00:00:00 2001 From: Kazu Yamamoto Date: Wed, 13 Aug 2014 15:21:13 +0900 Subject: [PATCH] fix #295. --- ghc-mod.cabal | 1 + src/GHCModi.hs | 14 ++++++++------ src/Utils.hs | 27 +++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 src/Utils.hs diff --git a/ghc-mod.cabal b/ghc-mod.cabal index 73922a3..1069577 100644 --- a/ghc-mod.cabal +++ b/ghc-mod.cabal @@ -133,6 +133,7 @@ Executable ghc-modi Default-Language: Haskell2010 Main-Is: GHCModi.hs Other-Modules: Paths_ghc_mod + Utils GHC-Options: -Wall -threaded Default-Extensions: ConstraintKinds, FlexibleContexts HS-Source-Dirs: src diff --git a/src/GHCModi.hs b/src/GHCModi.hs index 6276338..c6e2541 100644 --- a/src/GHCModi.hs +++ b/src/GHCModi.hs @@ -39,6 +39,8 @@ import System.Directory (setCurrentDirectory) import System.Environment (getArgs) import System.IO (hFlush,stdout) +import Utils + ---------------------------------------------------------------- type Logger = IO String @@ -231,7 +233,7 @@ showInfo :: IOish m -> FilePath -> GhcModT m (String, Bool, Set FilePath) showInfo set fileArg = do - let [file, expr] = words fileArg + let [file, expr] = splitN 2 fileArg set' <- newFileSet set file ret <- info file expr return (ret, True, set') @@ -241,7 +243,7 @@ showType :: IOish m -> FilePath -> GhcModT m (String, Bool, Set FilePath) showType set fileArg = do - let [file, line, column] = words fileArg + let [file, line, column] = splitN 3 fileArg set' <- newFileSet set file ret <- types file (read line) (read column) return (ret, True, set') @@ -251,7 +253,7 @@ doSplit :: IOish m -> FilePath -> GhcModT m (String, Bool, Set FilePath) doSplit set fileArg = do - let [file, line, column] = words fileArg + let [file, line, column] = splitN 3 fileArg set' <- newFileSet set file ret <- splits file (read line) (read column) return (ret, True, set') @@ -261,7 +263,7 @@ doSig :: IOish m -> FilePath -> GhcModT m (String, Bool, Set FilePath) doSig set fileArg = do - let [file, line, column] = words fileArg + let [file, line, column] = splitN 3 fileArg set' <- newFileSet set file ret <- sig file (read line) (read column) return (ret, True, set') @@ -271,7 +273,7 @@ doRefine :: IOish m -> FilePath -> GhcModT m (String, Bool, Set FilePath) doRefine set fileArg = do - let [file, line, column, expr] = words fileArg + let [file, line, column, expr] = splitN 4 fileArg set' <- newFileSet set file ret <- refine file (read line) (read column) expr return (ret, True, set') @@ -281,7 +283,7 @@ doAuto :: IOish m -> FilePath -> GhcModT m (String, Bool, Set FilePath) doAuto set fileArg = do - let [file, line, column] = words fileArg + let [file, line, column] = splitN 3 fileArg set' <- newFileSet set file ret <- auto file (read line) (read column) return (ret, True, set') diff --git a/src/Utils.hs b/src/Utils.hs new file mode 100644 index 0000000..c91151d --- /dev/null +++ b/src/Utils.hs @@ -0,0 +1,27 @@ +module Utils where + +-- | +-- +-- >>> split "foo bar baz" +-- ["foo","bar baz"] +-- >>> split "foo bar baz" +-- ["foo","bar baz"] +split :: String -> [String] +split xs = [ys, dropWhile isSpace zs] + where + isSpace = (== ' ') + (ys,zs) = break isSpace xs + +-- | +-- +-- >>> splitN 0 "foo bar baz" +-- ["foo","bar baz"] +-- >>> splitN 2 "foo bar baz" +-- ["foo","bar baz"] +-- >>> splitN 3 "foo bar baz" +-- ["foo","bar","baz"] +splitN :: Int -> String -> [String] +splitN n xs + | n <= 2 = split xs + | otherwise = let [ys,zs] = split xs + in ys : splitN (n - 1) zs