chapter3/parsec.hs: change definition of option

Let (<|>) (which equals option) return all parses of the succeeding parser,
as seems to be implied by the description in the chapter on Parsing.

Example:  parse (empty <|> ((unit 'a') `combine` (unit 'b'))) ""
This commit is contained in:
Christian Sievers 2015-01-30 18:29:15 +01:00
parent ca8b771489
commit 11709255c3

View File

@ -54,9 +54,9 @@ failure = Parser (\cs -> [])
option :: Parser a -> Parser a -> Parser a
option p q = Parser $ \s ->
case parse (mplus p q) s of
[] -> []
(x:xs) -> [x]
case parse p s of
[] -> parse q s
res -> res
satisfy :: (Char -> Bool) -> Parser Char
satisfy p = item `bind` \c ->