Draft
Conversation
Author
|
Update: |
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.
Enhancement Request: #409
This PR implements the
LocationContextError. The implementation follows theContextErrortype:Main differences to
ContextError:posfield to theLocationContextError.ParserError.orwill choose the context based on the longest parse. We merge the contexts into a commonVecin case both errors did reach the same position in the input streamadd_contextwill discard context details based on the input locationAlthough
Location.locationreturns anusize, this type is not always appropriate in all situations. For example in one of my parsers I have a lexer phase and some parse steps that just recognize a sequence of tokens. The actual parsing happens later. For that reason I'm having astruct Span(Range<u32>)as location.In order to make the location type configurable we allow users to set the location type via
L.Note: I didn't want to modify the
Locationtrait to make the output type configurable yet. Although I think that would improve the usability ofLocationContextError. This is whyParserErrorandAddContextare implemented forusizeonly. But their implementations can easily be copied for custom location types. The helper methods to merge/add context information only requireL: Ord.Testing:
I didn't find tests for the other error types. So I didn't add new ones.