haskell / attoparsec

A fast Haskell library for parsing ByteStrings
http://hackage.haskell.org/package/attoparsec
Other
512 stars 93 forks source link

Improve message produced by eitherResult for Partial #207

Open chris-martin opened 2 years ago

chris-martin commented 2 years ago

When a parser result is Partial, previously the eitherResult function showed a generic error message that includes no useful information other than a generic "incomplete input" message.

For example, if we let

p = (,) <$> letter <*> digit <?> "thing"

then

eitherResult (parse p "a") = Left "Result: incomplete input"

Attoparsec is already capable of generating more informative error information for this example, as we can demonstrate by using parseOnly:

parseOnly p "a" = "thing > digit: not enough input"

This change brings that same error message to eitherResult by simply feeding mempty into the continuation. With this change, eitherResult now gives the same output as parseOnly.

eitherResult (parse p "a") = "thing > digit: not enough input"
chris-martin commented 2 years ago

Is this change okay? Is there anything I can do to improve it?