diff --git a/src/GHCMod/Options/ShellParse.hs b/src/GHCMod/Options/ShellParse.hs index 2bcba0c..acd609b 100644 --- a/src/GHCMod/Options/ShellParse.hs +++ b/src/GHCMod/Options/ShellParse.hs @@ -16,6 +16,7 @@ module GHCMod.Options.ShellParse (parseCmdLine) where import Data.Char +import Data.List go :: String -> String -> [String] -> Bool -> [String] -- result @@ -36,6 +37,8 @@ go (c:cl) curarg accargs quotes | otherwise = go cl (c:curarg) accargs quotes parseCmdLine :: String -> [String] -parseCmdLine ('\\':comline) = go comline [] [] False +parseCmdLine comline' + | Just comline <- stripPrefix "ascii-escape " $ dropWhile isSpace comline' + = go (dropWhile isSpace comline) [] [] False parseCmdLine [] = [""] parseCmdLine comline = words comline diff --git a/test/ShellParseSpec.hs b/test/ShellParseSpec.hs index 30274f9..5517a11 100644 --- a/test/ShellParseSpec.hs +++ b/test/ShellParseSpec.hs @@ -10,9 +10,9 @@ spec = describe "parseCmdLine" $ do it "splits arguments" $ do parseCmdLine "test command line" `shouldBe` ["test", "command", "line"] - parseCmdLine "\\test command line" `shouldBe` ["test", "command", "line"] + parseCmdLine "ascii-escape test command line" `shouldBe` ["test", "command", "line"] it "honors quoted segments if turned on" $ - parseCmdLine "\\test command line \STXwith quoted segment\ETX" + parseCmdLine "ascii-escape test command line \STXwith quoted segment\ETX" `shouldBe` ["test", "command", "line", "with quoted segment"] it "doesn't honor quoted segments if turned off" $ parseCmdLine "test command line \STXwith quoted segment\ETX" @@ -20,5 +20,10 @@ spec = it "squashes multiple spaces" $ do parseCmdLine "test command" `shouldBe` ["test", "command"] - parseCmdLine "\\test command" + parseCmdLine "ascii-escape test command" + `shouldBe` ["test", "command"] + it "ingores leading spaces" $ do + parseCmdLine " test command" + `shouldBe` ["test", "command"] + parseCmdLine " ascii-escape test command" `shouldBe` ["test", "command"]