-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Generalise associative operator parsing #29072
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
r? @brson (rust_highfive has picked a reviewer for you, use r? to override) |
429ad12
to
ae2bb9e
Compare
Something I found is that Something that doesn’t parse anymore and is a bug is |
r? @pnkfelix |
Something that also needs to be fixed:
|
Running a crater build to evaluate these changes |
@nagisa So this is now fixed with your latest commit ? |
I believe it is.
|
Crater reports two regressions one of which I believe is spurious and one of which I believe is legitimate. |
Thanks, @alexcrichton! Short update on unused_parens lint: it has been fixed by @nrc’s changes to make EarlyPassLint to actually run pre-expansion. |
This PR is now in a pretty good spot, I think. The underlying issue behind the regression was just me forgetting to move restriction filtering over from the old code. This also helped to fix issues I had with semi-statement things I hacked around previously. |
(i won't get to this review until monday; hopefully that's okay.) |
try!(self.bump()); | ||
let opt_end = if self.is_at_start_of_range_notation_rhs() { | ||
// RHS must be parsed with more associativity than DotDot. | ||
let next_prec = AssocOp::from_token(&token::DotDot).unwrap().precedence() + 1; |
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.
NB: this changes the previous bahaviour of ..
from
This has the same precedence as assignment expressions
(much lower than other prefix expressions) to be consistent
// with the postfix-form 'expr..'”
To having more precedence than <-
and =
but still less than any other binary operator.
EDIT: I believe it doesn’t change the semantics of prefix ..
, though, since the operator is not associative.
NB: this still needs changes to Got distracted by university things, sadly. |
This commit generalises parsing of associative operators from left-associative only (with some ugly hacks to support right-associative assignment) to properly left/right-associative operators. Parsing still is not general enough to handle non-associative, non-highest-precedence prefix or non-highest-precedence postfix operators (e.g. `..` range syntax), though. That should be fixed in the future. Lastly, this commit adds support for parsing right-associative `<-` (left arrow) operator with precedence higher than assignment as the operator for placement-in feature.
Also add some (regression) tests for discovered parser oddities
I pushed Going from master to after the change, make check-grammar reports 2 less mismatches (from 132 down to 130). EDIT: ah also, the |
Oh, okay, sorry. Sometimes the commit-by-commit reviewing strategy works well, but I need to learn to look ahead in the queue for things like this. |
I removed it after your comment, just made a note that I fixed it. |
lgtm |
@bors r+ |
📌 Commit 99f9bb1 has been approved by |
This commit generalises parsing of associative operators from left-associative only (with some ugly hacks to support right-associative assignment) to properly left/right-associative operators. Parsing is still is not general enough to handle non-associative, non-highest-precedence prefix or non-highest-precedence postfix operators (e.g. `..` range syntax) and should be made to be. Lastly, this commit adds support for parsing right-associative `<-` (left arrow) operator with precedence higher than assignment as the operator for placement-in feature. --- This PR still needs various non-parser changes (e.g. src/grammar and tests) and I’m still working on these; the meat of the PR can already be reviewed, though, I think. Please review carefully. I made sure that quirks I have discovered so far are preserved (see e.g. #29071) and am looking for more corner cases as I continue to work on tests et al, but there may be something I haven’t noticed or accounted for. EDIT: I’m also not sure I managed to preserve all the semantics with the range operator inside non-trivial expressions since these are a mess at the moment. Crater runs would be nice.
This commit generalises parsing of associative operators from left-associative
only (with some ugly hacks to support right-associative assignment) to properly
left/right-associative operators.
Parsing is still is not general enough to handle non-associative,
non-highest-precedence prefix or non-highest-precedence
postfix operators (e.g.
..
range syntax) and should be made to be.Lastly, this commit adds support for parsing right-associative
<-
(left arrow)operator with precedence higher than assignment as the operator for placement-in
feature.
This PR still needs various non-parser changes (e.g. src/grammar and tests) and I’m still working on these; the meat of the PR can already be reviewed, though, I think.
Please review carefully. I made sure that quirks I have discovered so far are preserved (see e.g. #29071) and am looking for more corner cases as I continue to work on tests et al, but there may be something I haven’t noticed or accounted for.
EDIT: I’m also not sure I managed to preserve all the semantics with the range operator inside non-trivial expressions since these are a mess at the moment. Crater runs would be nice.