Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mpilgrem committed Nov 1, 2023
1 parent 035231a commit 2b7f13d
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/Data/Attoparsec/Args.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit 2b7f13d

Please sign in to comment.