parsec
parsec copied to clipboard
Bad error handling: unhelpful "unexpected" error message when parsing set of strings
A parser like
parser :: GenParser Char st String
parser = choice $ fmap (try . string) ["head", "tail", "tales"]
with malformed input "ta " will produce an error message like unexpected "t"
and point to the first position of the input. Better output would be unexpected " "
(and possibly a list of expected outputs, ["tails", "tales"]
in this case).
Please see this much more detailed StackOverflow answer/analysis written by CR Drost (starting with the second headline).