parsec icon indicating copy to clipboard operation
parsec copied to clipboard

Bad error handling: unhelpful "unexpected" error message when parsing set of strings

Open nd2s opened this issue 9 years ago • 0 comments

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).

nd2s avatar Dec 21 '15 15:12 nd2s