Improve message produced by eitherResult for Partial#207
Closed
chris-martin wants to merge 1 commit intohaskell:masterfrom
Closed
Improve message produced by eitherResult for Partial#207chris-martin wants to merge 1 commit intohaskell:masterfrom
chris-martin wants to merge 1 commit intohaskell:masterfrom
Conversation
94e345d to
9d3c57d
Compare
Contributor
Author
|
Is this change okay? Is there anything I can do to improve it? |
bgamari
requested changes
Apr 29, 2022
| 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 _" |
Collaborator
There was a problem hiding this comment.
This seems like a less understandable error than the original. Perhaps something like "eitherResult: Partial" would be less ambiguous?
Contributor
Author
There was a problem hiding this comment.
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.
9d3c57d to
a1dad44
Compare
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"
a1dad44 to
5678ad2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a parser result is
Partial, previously theeitherResultfunction showed a generic error message that includes no useful information other than a generic "incomplete input" message.For example, if we let
then
Attoparsec is already capable of generating more informative error information for this example, as we can demonstrate by using
parseOnly:This change brings that same error message to
eitherResultby simply feedingmemptyinto the continuation. With this change,eitherResultnow gives the same output asparseOnly.