Skip to content

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

Merged
merged 7 commits into from
Oct 28, 2015
Merged

Conversation

nagisa
Copy link
Member

@nagisa nagisa commented Oct 15, 2015

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.

@rust-highfive
Copy link
Contributor

r? @brson

(rust_highfive has picked a reviewer for you, use r? to override)

@nagisa nagisa force-pushed the place-arrow branch 2 times, most recently from 429ad12 to ae2bb9e Compare October 15, 2015 14:39
@nagisa
Copy link
Member Author

nagisa commented Oct 15, 2015

Something I found is that x = 2..3 = y now parses as (x = 2..3) = y while it used to fail before. The expression still fails to compile later with E0070 anyway, though.

Something that doesn’t parse anymore and is a bug is x = ..y and x = ... I’ll tackle these soon.

@brson
Copy link
Contributor

brson commented Oct 15, 2015

r? @pnkfelix

@nagisa
Copy link
Member Author

nagisa commented Oct 15, 2015

Something that also needs to be fixed:

test.rs:45:5: 45:13 warning: unnecessary parentheses around assigned value, #[warn(unused_parens)] on by default
test.rs:45     (x <- y) <- z;
               ^~~~~~~~

@alexcrichton
Copy link
Member

Running a crater build to evaluate these changes

@pnkfelix
Copy link
Member

Something that doesn’t parse anymore and is a bug is x = ..y and x = ... I’ll tackle these soon.

@nagisa So this is now fixed with your latest commit ?

@nagisa
Copy link
Member Author

nagisa commented Oct 16, 2015

I believe it is.
On Oct 16, 2015 1:25 PM, "Felix S Klock II" notifications@github.com
wrote:

Something that doesn’t parse anymore and is a bug is x = ..y and x = ...
I’ll tackle these soon.

@nagisa https://github.com/nagisa So this is now fixed with your latest
commit ?


Reply to this email directly or view it on GitHub
#29072 (comment).

@alexcrichton
Copy link
Member

Crater reports two regressions one of which I believe is spurious and one of which I believe is legitimate.

@nagisa
Copy link
Member Author

nagisa commented Oct 16, 2015

Thanks, @alexcrichton!


Short update on unused_parens lint: it has been fixed by @nrc’s changes to make EarlyPassLint to actually run pre-expansion.

@nagisa
Copy link
Member Author

nagisa commented Oct 16, 2015

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.

@pnkfelix
Copy link
Member

(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;
Copy link
Member Author

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.

@nagisa
Copy link
Member Author

nagisa commented Oct 27, 2015

NB: this still needs changes to src/grammar and I had planned to add more tests for quirky cases such as x..y=z not parsing (it did not parse before, and AFAIR it does not parse after changes).

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
@nagisa
Copy link
Member Author

nagisa commented Oct 27, 2015

I pushed src/grammar change, but honestly have no idea what I’m doing since I’m just following grammar for similarly behaving equalities.

Going from master to after the change, make check-grammar reports 2 less mismatches (from 132 down to 130).

EDIT: ah also, the in PLACE {EXPR} warning is removed in nagisa@58c299f

@pnkfelix
Copy link
Member

EDIT: ah also, the in PLACE {EXPR} warning is removed in nagisa/rust@58c299f

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.

@nagisa
Copy link
Member Author

nagisa commented Oct 27, 2015

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.

@pnkfelix
Copy link
Member

lgtm

@pnkfelix
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Oct 27, 2015

📌 Commit 99f9bb1 has been approved by pnkfelix

@bors
Copy link
Collaborator

bors commented Oct 27, 2015

⌛ Testing commit 99f9bb1 with merge e0e2627...

bors added a commit that referenced this pull request Oct 27, 2015
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.
@bors bors merged commit 99f9bb1 into rust-lang:master Oct 28, 2015
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants