diff options
author | Stefan Holdermans <stefan@holdermans.nl> | 2020-04-20 21:01:46 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-05-21 12:16:08 -0400 |
commit | a8c27cf6eef51adfa6ac9931d4f620645dc24dd3 (patch) | |
tree | 98776442314e078f9cc1833a21dfb5870058eb8d | |
parent | b7a6b2f4c690a9711339462114a538a85dcb7d83 (diff) | |
download | haskell-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.
-rw-r--r-- | ghc/GHCi/UI.hs | 15 | ||||
-rw-r--r-- | testsuite/tests/ghci/should_run/T18027 SPACE IN FILE NAME.script | 1 | ||||
-rw-r--r-- | testsuite/tests/ghci/should_run/T18027.script | 1 | ||||
-rw-r--r-- | testsuite/tests/ghci/should_run/T18027.stdout | 1 | ||||
-rw-r--r-- | testsuite/tests/ghci/should_run/all.T | 1 |
5 files changed, 18 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 diff --git a/testsuite/tests/ghci/should_run/T18027 SPACE IN FILE NAME.script b/testsuite/tests/ghci/should_run/T18027 SPACE IN FILE NAME.script new file mode 100644 index 0000000000..d81cc0710e --- /dev/null +++ b/testsuite/tests/ghci/should_run/T18027 SPACE IN FILE NAME.script @@ -0,0 +1 @@ +42 diff --git a/testsuite/tests/ghci/should_run/T18027.script b/testsuite/tests/ghci/should_run/T18027.script new file mode 100644 index 0000000000..fd839d2392 --- /dev/null +++ b/testsuite/tests/ghci/should_run/T18027.script @@ -0,0 +1 @@ +:script T18027\ SPACE\ IN\ FILE\ NAME.script diff --git a/testsuite/tests/ghci/should_run/T18027.stdout b/testsuite/tests/ghci/should_run/T18027.stdout new file mode 100644 index 0000000000..d81cc0710e --- /dev/null +++ b/testsuite/tests/ghci/should_run/T18027.stdout @@ -0,0 +1 @@ +42 diff --git a/testsuite/tests/ghci/should_run/all.T b/testsuite/tests/ghci/should_run/all.T index 4a629350a2..6d39d5794c 100644 --- a/testsuite/tests/ghci/should_run/all.T +++ b/testsuite/tests/ghci/should_run/all.T @@ -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']) |