{-# OPTIONS -#include "Linker.h" #-}
-----------------------------------------------------------------------------
--- $Id: InteractiveUI.hs,v 1.143 2003/02/12 15:01:35 simonpj Exp $
+-- $Id: InteractiveUI.hs,v 1.144 2003/02/13 01:50:04 sof Exp $
--
-- GHC Interactive User Interface
--
builtin_commands :: [(String, String -> GHCi Bool)]
builtin_commands = [
- ("add", keepGoing addModule),
+ ("add", keepGoingPaths addModule),
("browse", keepGoing browseCmd),
("cd", keepGoing changeDirectory),
("def", keepGoing defineMacro),
("help", keepGoing help),
("?", keepGoing help),
("info", keepGoing info),
- ("load", keepGoing loadModule),
+ ("load", keepGoingPaths loadModule),
("module", keepGoing setContext),
("reload", keepGoing reloadModule),
("set", keepGoing setCmd),
keepGoing :: (String -> GHCi ()) -> (String -> GHCi Bool)
keepGoing a str = a str >> return False
+keepGoingPaths :: ([FilePath] -> GHCi ()) -> (String -> GHCi Bool)
+keepGoingPaths a str = a (toArgs str) >> return False
+
shortHelpText = "use :? for help.\n"
-- NOTE: spaces at the end of each line to workaround CPP/string gap bug.
-- perform a :load for files given on the GHCi command line
when (not (null paths)) $
ghciHandle showException $
- loadModule (unwords paths)
+ loadModule paths
-- enter the interactive loop
#if defined(mingw32_TARGET_OS)
setCmState cms
return ()
-addModule :: String -> GHCi ()
-addModule str = do
- let files = words str
+addModule :: [FilePath] -> GHCi ()
+addModule files = do
state <- getGHCiState
dflags <- io (getDynFlags)
io (revertCAFs) -- always revert CAFs on load/add.
io (writeIORef commands (filter ((/= macro_name) . fst) cmds))
-loadModule :: String -> GHCi ()
-loadModule str = timeIt (loadModule' str)
+loadModule :: [FilePath] -> GHCi ()
+loadModule fs = timeIt (loadModule' fs)
-loadModule' str = do
- let files = words str
+loadModule' :: [FilePath] -> GHCi ()
+loadModule' files = do
state <- getGHCiState
dflags <- io getDynFlags
-- module names
looksLikeModuleName,
+
+ toArgs
) where
#include "../includes/config.h"
import List ( zipWith4 )
#endif
-import Char ( isUpper, isAlphaNum )
+import Char ( isUpper, isAlphaNum, isSpace )
infixr 9 `thenCmp`
\end{code}
go ('.':cs) = looksLikeModuleName cs
go (c:cs) = (isAlphaNum c || c == '_') && go cs
\end{code}
+
+Akin to @Prelude.words@, but sensitive to dquoted entities treating
+them as single words.
+
+\begin{code}
+toArgs :: String -> [String]
+toArgs "" = []
+toArgs s =
+ case break (\ ch -> isSpace ch || ch == '"') (dropWhile isSpace s) of -- "
+ (w,aft) ->
+ (\ ws -> if null w then ws else w : ws) $
+ case aft of
+ [] -> []
+ (x:xs)
+ | x /= '"' -> toArgs xs
+ | otherwise ->
+ case lex aft of
+ ((str,rs):_) -> stripQuotes str : toArgs rs
+ _ -> [aft]
+ where
+ -- strip away dquotes; assume first and last chars contain quotes.
+ stripQuotes :: String -> String
+ stripQuotes ('"':xs) = init xs
+ stripQuotes xs = xs
+\end{code}