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

Allow GHCi :script file names in double quotes

This patch updates the user interface of GHCi so that file names passed
to the ':script' command can be wrapped in double quotes.

For example:

  :script "foo bar.script"

The implementation uses a modified version of 'words' that treats
character sequences enclosed in double quotes as single words.

Fixes #18027.
parent 82663959
......@@ -2267,12 +2267,15 @@ scriptCmd ws = do
[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"]'.
-- | A version of 'words' that treats sequences enclosed in double quotes as
-- single words and that does not break on backslash-escaped spaces.
-- E.g., 'words\' "\"lorem ipsum\" dolor"' and 'words\' "lorem\\ ipsum dolor"'
-- yield '["lorem ipsum", "dolor"]'.
-- Used to scan for file paths in 'scriptCmd'.
words' :: String -> [String]
words' s = case dropWhile isSpace s of
"" -> []
s'@('\"' : _) | [(w, s'')] <- reads s' -> w : words' s''
s' -> go id s'
where
go acc [] = [acc []]
......
:script T18027\ SPACE\ IN\ FILE\ NAME.script
:script "T18027 SPACE IN FILE NAME.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