Skip to content

Generalise associative operator parsing - #29072

Merged
bors merged 7 commits into
rust-lang:masterfrom
nagisa:place-arrow
Oct 28, 2015
Merged

bors merged 7 commits into
rust-lang:masterfrom
nagisa:place-arrow

Conversation

@nagisa

@nagisa nagisa commented Oct 15, 2015

Copy link
Copy Markdown
Member

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
Copy Markdown
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

nagisa commented Oct 15, 2015

Copy link
Copy Markdown
Member Author

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

brson commented Oct 15, 2015

Copy link
Copy Markdown
Contributor

r? @pnkfelix

@nagisa

nagisa commented Oct 15, 2015

Copy link
Copy Markdown
Member Author

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
Copy Markdown
Member

Running a crater build to evaluate these changes

@pnkfelix

Copy link
Copy Markdown
Contributor

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

nagisa commented Oct 16, 2015

Copy link
Copy Markdown
Member Author

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
Copy Markdown
Member

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

@nagisa

nagisa commented Oct 16, 2015

Copy link
Copy Markdown
Member Author

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

nagisa commented Oct 16, 2015

Copy link
Copy Markdown
Member Author

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
Copy Markdown
Contributor

(i won't get to this review until monday; hopefully that's okay.)

Copy link
Copy Markdown
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

nagisa commented Oct 27, 2015

Copy link
Copy Markdown
Member Author

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

nagisa commented Oct 27, 2015

Copy link
Copy Markdown
Member Author

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
Copy Markdown
Contributor

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

nagisa commented Oct 27, 2015

Copy link
Copy Markdown
Member Author

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
Copy Markdown
Contributor

lgtm

@pnkfelix

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Oct 27, 2015

Copy link
Copy Markdown
Collaborator

📌 Commit 99f9bb1 has been approved by pnkfelix

@bors

bors commented Oct 27, 2015

Copy link
Copy Markdown
Collaborator

⌛ 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants