-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Range expressions: discrepancies between rustc and parser-lalr #28785
Comments
Looking through #20811, I see two more cases where fn rangefrom_compare() {
1.. == (1..); // rustc syntax error, parser-lalr parses as (1..) == (1..)
}
fn compare_rangeto() {
(..1) == ..1; // rustc syntax error, parser-lalr parses as (..1) == (..1)
} |
triage: P-medium This is a backwards incompat issue, but feels like an edge case. Nonetheless we should definitely fix it! |
Can you explain why you think that I would expect On all other examples, I'd say the rustc behavior is correct. The decision in #21374 was: Comparing ranges needs parentheses: the attempt to give Admittedly, having |
Regarding let x = {
{}
-1
} (Rust ignores newlines outside of string-literals, AFAIK.)
@nikomatsakis made some comments to this effect here:
Of course, FWIW, I noticed that the current nightly Rust compiler is now parsing |
That makes sense; I didn't realize we had that rule about It also fits what I wrote in #25119: In a formal grammar, the restrictions around
Is there any way to do this with the |
I think we can reduce the problem to: expr
: DOTDOT
| expr DOT ID
| ID
{}
; We need to reject (Aside: I'm finding Some parser generators (e.g. menhir) allowing parameterizing rules. e.g. Maybe a formal grammar could have a single (Also: I get the impression that the nonparen restriction class might be going away. It's needed only for the placement new |
Actually, I'm starting to think that the rustc behavior might not be ideal: it interacts badly with lambda syntax. Rust currently has 7 non-associative operators: Rustc currently rejects Lambdas have the same "precedence inversion" problem that I tried to avoid for (unary) For example, This gets especially problematic when the programmer assumes the lambda body is an expression, but the expression actually ends earlier. Is One solution would be to parse The other option would be to disallow lambdas from appearing as left-hand-operand of a binary operator (just like we already disallow blocks in such a position). |
I think we should disallow lambdas from appearing as left-hand-operand of a binary operator or as operand of a suffix expression. |
On Thu, Nov 05, 2015 at 09:59:14AM -0800, Ryan Prichard wrote:
Just wanted to point out that LALRPOP supports this sort of |
@nikomatsakis can mentor. Needs investigation into the correct grammar. |
@nikomatsakis Could you either provide some instructions here, or otherwise unmark as E-mentor? |
Triage; is parser-lalr still a thing? is this issue relevant? also, removing e-mentor |
Apparently |
I'd guess that the last test case here is a
rustc
bug, but I don't know about the others.Also see #25119.
The text was updated successfully, but these errors were encountered: