diff options
Diffstat (limited to 'src/Command.hs')
-rw-r--r-- | src/Command.hs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/Command.hs b/src/Command.hs index 49dc966..55f4466 100644 --- a/src/Command.hs +++ b/src/Command.hs | |||
@@ -16,6 +16,14 @@ data Cmd = PerformAlt Alteration | |||
16 | | ParseError String | 16 | | ParseError String |
17 | | Empty | 17 | | Empty |
18 | 18 | ||
19 | quoteChars, escapeChars :: [Char] | ||
20 | quoteChars = ['"', '\''] | ||
21 | escapeChars = ['\\'] | ||
22 | |||
23 | isQuote, isEscape :: Char -> Bool | ||
24 | isQuote q = q `elem` quoteChars | ||
25 | isEscape e = e `elem` escapeChars | ||
26 | |||
19 | parseCmd :: SequenceM m => String -> m Cmd | 27 | parseCmd :: SequenceM m => String -> m Cmd |
20 | parseCmd = parseCmd' . split | 28 | parseCmd = parseCmd' . split |
21 | where | 29 | where |
@@ -48,8 +56,6 @@ parseCmd = parseCmd' . split | |||
48 | | Nothing <- e | 56 | | Nothing <- e |
49 | , isEscape c = split' ws w q (Just c) cs -- Set escaped flag at unescaped escape char | 57 | , isEscape c = split' ws w q (Just c) cs -- Set escaped flag at unescaped escape char |
50 | | otherwise = split' ws (c : w) q Nothing cs -- Append to word | 58 | | otherwise = split' ws (c : w) q Nothing cs -- Append to word |
51 | isQuote q = q `elem` ['"', '\''] | ||
52 | isEscape e = e == '\\' | ||
53 | 59 | ||
54 | parseCmd' :: SequenceM m => [String] -> m Cmd | 60 | parseCmd' :: SequenceM m => [String] -> m Cmd |
55 | parseCmd' [] = return Empty | 61 | parseCmd' [] = return Empty |