Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve message produced by eitherResult for Partial #207

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chris-martin
Copy link
Contributor

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
Copy link
Contributor Author

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

T.Done _ r -> Right r
T.Fail _ [] msg -> Left msg
T.Fail _ ctxs msg -> Left (intercalate " > " ctxs ++ ": " ++ msg)
T.Partial _ -> error "feed result mempty = Partial _"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a less understandable error than the original. Perhaps something like "eitherResult: Partial" would be less ambiguous?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind changing it, but just to make sure we're on the same page - this is not a substitute for the error message that was previously returned when the parse result was partial. This is an error message that will never be seen.

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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants