开发者

Raise ParseError in Haskell/Parsec

开发者 https://www.devze.com 2022-12-12 01:34 出处:网络
What is the prefered way to raise errors (ParseError) in Parsec? I got some code inside a parser that 开发者_运维技巧performs a check and if the check fails a ParseError should be returned (i.e. Left

What is the prefered way to raise errors (ParseError) in Parsec? I got some code inside a parser that 开发者_运维技巧performs a check and if the check fails a ParseError should be returned (i.e. Left ParseError when running parse).


You can use Text.ParserCombinators.Parsec.Prim.unexpected and Control.Monad.fail for this. Both take a String argument signifying the error message and will return (in this case) a value of type GenParser tok st a.

For more, see Text.ParserCombinators.Parsec.Error, specifically Message. There you can read which function to use in which case (though both signify a parse error, they are semantically slightly different).

0

精彩评论

暂无评论...
验证码 换一张
取 消