You can use the function parse
which will run a Parser
on an input string and return an Either ParseError Expr
. I put a simple usage below where I turn that ParseError
into a string and pass it along
readExpr :: String -> Either String Expr
readExpr input = case parse expr "name for error messages" input of
Left err -> Left $ "Oh noes parsers are failing: " ++ show err -- Handle error
Right a -> Right a -- Handle success
There are a few other functions, such as parseFromFile
, which let you shorthand a few common patterns, to find them, check out the parsec haddock