8 Aug 2012 21:24
parsec: parserFail & multiple error messages
silly8888 <silly8888 <at> gmail.com>
2012-08-08 19:24:31 GMT
2012-08-08 19:24:31 GMT
I am trying to create a parsec parser that parses an integer and then
checks if that integer has the right size. If not, it generates an
error.
I tried the following:
8<---------------------------------------------------------------
import Text.Parsec
import Text.Parsec.String
integer :: Parser Int
integer = do s <- many1 digit
let n = read s
if n > 65535 then
parserFail "integer overflow"
else
return n
8<---------------------------------------------------------------
The problem is that when I try this
parse integer "" "70000"
I get the following error:
Left (line 1, column 6):
unexpected end of input
expecting digit
integer overflow
ie there are three error messages but I only want the last one. Is
(Continue reading)
RSS Feed