[Haskell-cafe] parsec: parserFail & multiple error messages
Albert Y. C. Lai
trebla at vex.net
Fri Aug 10 02:15:47 CEST 2012
On 12-08-08 03:24 PM, silly8888 wrote:
> 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
> there something I can do about this?
import Text.Parsec
import Text.Parsec.String
integer :: Parser Int
integer = try integ3r <?> "number at most 65535"
integ3r = do s <- many1 digit
let n = read s
if n > 65535 then
unexpected "number overflow"
else
return n
main = do
parseTest integer "a70000"
parseTest integer "70000"
More information about the Haskell-Cafe
mailing list