A way to capture the span of previous tokens in the error? #920
-
|
So I have a rule that first matches a keyword, and then another parser with matches a list. If the list parser fails, it returns an error but only with the span of the tokens that should have been the list. So when I display the error, the initial keyword is not shown. I currently just manually decrement the span by one when mapping the error, but I was wondering if I could somehow do this automatically / less error prone than just decrementing the span? just(Token::KwAnd)
.ignore_then(match_list.clone())
.map_err(|err| {
ParserError::MatchListAfterLogicalOperator(
(err.span().start - 1..err.span().end).into(),
)
})
.map(ParserMatcher::And) |
Beta Was this translation helpful? Give feedback.
Answered by
filiptrplan
Nov 29, 2025
Replies: 1 comment
-
|
Leaving a solution for anyone that comes across this problem: just(Token::KwAnd)
.ignore_then(match_list.clone())
.map_err_with_state(|err, span, _| {
ParserError::MatchListAfterLogicalOperator(span.union(err.span()))
})
.map(ParserMatcher::And) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
filiptrplan
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Leaving a solution for anyone that comes across this problem: