| |||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||
| Description | |||||||||||||||||||||||||||||
A parser for commandlines, returns an arg list and expands format strings given in a translation table. Additionally the commandline can end with %< specifying that the command expects input on stdin. Some tests for the parser. formatTable = [('s',"<insert subject here>"),
('a',"<insert author here>")]
testParser :: (Show a, Eq a) => Parser a -> String -> a -> a
testParser p s ok = case parse p "" s of
Left e -> error $ "Parser failed with: " ++ (show e)
Right res -> if res == ok
then res
else error $ "Parser failed: got "
++ (show res) ++ ", expected "
++ (show ok)
testCases = [("a b",(["a","b"], False)),
("a b %<",(["a","b"], True)),
("a b %< ",(["a","b"], True)),
("\"arg0 contains spaces \\\"quotes\\\"\" b",
(["arg0 contains spaces \"quotes\"","b"],False)),
("a %s %<",(["a","<insert subject here>"], True))]
runTests = map (uncurry $ testParser (commandline formatTable)) testCases
| |||||||||||||||||||||||||||||
| Synopsis | |||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||
| Documentation | |||||||||||||||||||||||||||||
| type FTable = [(Char, String)] | |||||||||||||||||||||||||||||
| assoc list mapping characters to strings eg (c,s) means that %c is replaced by s | |||||||||||||||||||||||||||||
| commandline :: FTable -> Parser ([String], Bool) | |||||||||||||||||||||||||||||
| escape :: Parser String | |||||||||||||||||||||||||||||
| format :: FTable -> Parser String | |||||||||||||||||||||||||||||
| quotedArg :: FTable -> Parser String | |||||||||||||||||||||||||||||
| unquotedArg :: FTable -> Parser String | |||||||||||||||||||||||||||||
| quoteContent :: FTable -> Parser String | |||||||||||||||||||||||||||||
| arg :: FTable -> Parser String | |||||||||||||||||||||||||||||
| formatRedir :: Parser Bool | |||||||||||||||||||||||||||||
| consumeAll :: Parser a -> Parser a | |||||||||||||||||||||||||||||
| separator :: Parser () | |||||||||||||||||||||||||||||
| expandFormat :: FTable -> Char -> String | |||||||||||||||||||||||||||||
| parseCmd :: FTable -> String -> Either ParseError ([String], Bool) | |||||||||||||||||||||||||||||
| parse a commandline returning a list of strings (intended to be used as argv) and a bool value which specifies if the command expects input on stdin format specifiers with a mapping in ftable are accepted and replaced by the given strings. E.g. if the ftable is [(s,Some subject)], then %s is replaced by Some subject | |||||||||||||||||||||||||||||
| urlEncode :: String -> String | |||||||||||||||||||||||||||||
| addUrlencoded :: FTable -> FTable | |||||||||||||||||||||||||||||
| for every mapping (c,s), add a mapping with uppercase c and the urlencoded string s | |||||||||||||||||||||||||||||
| Produced by Haddock version 2.4.2 |