diff --git a/src/Data/Attoparsec/Args.hs b/src/Data/Attoparsec/Args.hs index ca3fc21b7f..46e825c3ba 100644 --- a/src/Data/Attoparsec/Args.hs +++ b/src/Data/Attoparsec/Args.hs @@ -28,18 +28,24 @@ parseArgs mode = P.parseOnly (argsParser mode) parseArgsFromString :: EscapingMode -> String -> Either String [String] parseArgsFromString mode = P.parseOnly (argsParser mode) . T.pack --- | A basic argument parser. It supports space-separated text, and --- string quotation with identity escaping: \x -> x. +-- | A basic argument parser. It supports space-separated text, and string +-- quotation with identity escaping: \x -> x. argsParser :: EscapingMode -> P.Parser [String] -argsParser mode = many (P.skipSpace *> (quoted <|> unquoted)) <* - P.skipSpace <* (P.endOfInput "unterminated string") +argsParser mode = + many + ( P.skipSpace + *> (quoted <|> unquoted) + ) + <* P.skipSpace + <* (P.endOfInput "unterminated string") where - unquoted = P.many1 naked quoted = P.char '"' *> str <* P.char '"' - str = many ( case mode of - Escaping -> escaped <|> nonquote - NoEscaping -> nonquote - ) + unquoted = P.many1 naked + str = many + ( case mode of + Escaping -> escaped <|> nonquote + NoEscaping -> nonquote + ) escaped = P.char '\\' *> P.anyChar nonquote = P.satisfy (/= '"') naked = P.satisfy (not . flip elem ("\" " :: String))