mirror of
https://github.com/sdiehl/write-you-a-haskell.git
synced 2024-08-17 07:30:24 +03:00
chapter3/parsec.hs: handle ambigous parses in runParser
The text doesn't mention ambigous parses, and the code didn't handle them. The easiest way to fix the code without necessarily having to write about this case is to hande it as parse error and merge it with the no parse case by replacing the [] pattern with _.
This commit is contained in:
parent
d40f93d884
commit
ca8b771489
@ -13,7 +13,7 @@ runParser m s =
|
||||
case parse m s of
|
||||
[(res, [])] -> res
|
||||
[(_, rs)] -> error "Parser did not consume entire stream."
|
||||
[] -> error "Parser error."
|
||||
_ -> error "Parser error."
|
||||
|
||||
item :: Parser Char
|
||||
item = Parser $ \s ->
|
||||
|
Loading…
Reference in New Issue
Block a user