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 theContextError
type:Main differences to
ContextError
:pos
field to theLocationContextError
.ParserError.or
will choose the context based on the longest parse. We merge the contexts into a commonVec
in case both errors did reach the same position in the input streamadd_context
will discard context details based on the input locationAlthough
Location.location
returns 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
Location
trait to make the output type configurable yet. Although I think that would improve the usability ofLocationContextError
. This is whyParserError
andAddContext
are implemented forusize
only. 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.