summaryrefslogtreecommitdiff
path: root/ghc
diff options
context:
space:
mode:
authorStefan Holdermans <stefan@holdermans.nl>2020-04-20 21:01:46 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-05-21 12:16:08 -0400
commita8c27cf6eef51adfa6ac9931d4f620645dc24dd3 (patch)
tree98776442314e078f9cc1833a21dfb5870058eb8d /ghc
parentb7a6b2f4c690a9711339462114a538a85dcb7d83 (diff)
downloadhaskell-a8c27cf6eef51adfa6ac9931d4f620645dc24dd3.tar.gz
Allow spaces in GHCi :script file names
This patch updates the user interface of GHCi so that file names passed to the ':script' command may contain spaces escaped with a backslash. For example: :script foo\ bar.script The implementation uses a modified version of 'words' that does not break on escaped spaces. Fixes #18027.
Diffstat (limited to 'ghc')
-rw-r--r--ghc/GHCi/UI.hs15
1 files changed, 14 insertions, 1 deletions
diff --git a/ghc/GHCi/UI.hs b/ghc/GHCi/UI.hs
index e3ebeaf2d2..c1fce215c3 100644
--- a/ghc/GHCi/UI.hs
+++ b/ghc/GHCi/UI.hs
@@ -2263,10 +2263,23 @@ quit _ = return True
scriptCmd :: String -> InputT GHCi ()
scriptCmd ws = do
- case words ws of
+ case words' ws of
[s] -> runScript s
_ -> throwGhcException (CmdLineError "syntax: :script <filename>")
+-- | A version of 'words' that does not break on backslash-escaped spaces.
+-- E.g., 'words\' "lorem\\ ipsum dolor"' yields '["lorem ipsum", "dolor"]'.
+-- Used to scan for file paths in 'scriptCmd'.
+words' :: String -> [String]
+words' s = case dropWhile isSpace s of
+ "" -> []
+ s' -> go id s'
+ where
+ go acc [] = [acc []]
+ go acc ('\\' : c : cs) | isSpace c = go (acc . (c :)) cs
+ go acc (c : cs) | isSpace c = acc [] : words' cs
+ | otherwise = go (acc . (c :)) cs
+
runScript :: String -- ^ filename
-> InputT GHCi ()
runScript filename = do