-
-
Notifications
You must be signed in to change notification settings - Fork 259
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
Fix error display if pos is after \n #350
Conversation
9e73190
to
d1105a0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! Maybe some of this logic should be behind Span
? I.e. a normalization method that takes care of cases like this.
Maybe! |
Hmm, I think the normalization only makes sense for display purposes, so I left it in the error format code |
Taking a better look at this, maybe a generally better solution would be to have |
Hmm, but wouldn’t that mean that the next line is included in the error display? Wouldn’t the
The honestly best thing I could imagine is this:
with the “␊” in another color |
That's quite a neat solution! Here's an idea for the API: |
OK. So implementing something like #349 in my own crate, I found myself missing public access to the Specifically I wanted to parse a slice of a fn parse_scale(pair: Pair<Rule>) -> Result<u8, Error> {
let input = if pair.as_str().chars().rev().next() == Some('%') {
pair.as_span().start_pos().span(pair.as_span().end_pos().skip_back(1))
} else { pair };
// Pair.parse is supplied via #349, link above
Ok(input.parse().map_err(|e| to_parse_error(input, e)))
} …or something more elegant. How should I go about it? |
Implementing |
You are of course right. And this is probably not the right issue to discuss this. I only mentioned it because I introduced skip_back here, which could be used if it was public: let new_span = span.start_pos().span(span.end_pos().skip_back(1)) |
OK, LF proposal is done! please tell me where I should add comments. |
472c992
to
b1ab8db
Compare
the errors are not mine, they’re caused by clippy on rust 1.31! I also think that this has grown a bit out of proportion for starting as a bugfix, so maybe we should merge this once it’s qualitatively acceptable (if it isn’t already) and then do the cosmetics (e.g. coloring the error display) elsewhere. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for bearing with me. This PR outgrew its purpose and I sure hope I'm dragging this too much. I'm fine with merging this as soon as last few issues are solved, but longer term, Span
should get more functionality like the slicing you mentioned.
487ac98
to
a51773e
Compare
Don’t worry, it’s fine, I’m happy to contribute |
9365521
to
dd4ea20
Compare
It looks like you'll need to run a new |
sure. please make sure to squash-merge this, no need to have the whole mess in the git history. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late review. LGTM!
bors r+
350: Fix error display if pos is after \n r=dragostis a=flying-sheep I had to add an API for moving a position back. An alternative would have been to modify `skip_while` to take a slice of `std::str::pattern::Pattern`s instead of `&[&str]` and add a `skip_back_while` function that does the same but backwards. Then we could have skipped back until we hit a non-newline character. Should I do that instead? Fixes #348 Co-authored-by: Philipp A <[email protected]> Co-authored-by: Dragoș Tiselice <[email protected]>
Build succeeded |
woo! 🎉 |
I had to add an API for moving a position back.
An alternative would have been to modify
skip_while
to take a slice ofstd::str::pattern::Pattern
s instead of&[&str]
and add askip_back_while
function that does the same but backwards. Then we could have skipped back until we hit a non-newline character.Should I do that instead?
Fixes #348