Commit a8c27cf6 authored by Stefan Holdermans's avatar Stefan Holdermans Committed by Marge Bot

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.
parent b7a6b2f4
......@@ -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
......
:script T18027\ SPACE\ IN\ FILE\ NAME.script
......@@ -64,3 +64,4 @@ test('T15633b',
test('T16096', just_ghci, ghci_script, ['T16096.script'])
test('T507', just_ghci, ghci_script, ['T507.script'])
test('T18027', just_ghci, ghci_script, ['T18027.script'])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment