Repository navigation
Parsing inconsistencies (lambda, proc, return) #28784
Description
Activity
/cc @rust-lang/lang , can we disambiguate what's intended here?
- addedA-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an AST
on Oct 6, 2015 I agree with @rprichard's take for the most part. I guess that
return as i32ought to parse...weird as it is.triage: P-medium
- addedT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
on Oct 6, 2015 - addedP-lowLow priorityLow priorityE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.and removedP-mediumMedium priorityMedium priority
on Jul 14, 2016 Probably a good beginner bug for someone familiar with parsing.
Make the rustc parser behavie like parser-lalr, per the op.
I'm reaaonably familiar with parsers and I'd like to take a crack at this bug.
@neunenak You got it!
@nikomatsakis @nrc @pnkfelix Can you confirm the right thing to do here is make libsyntax behave like the reference parser as described in the OP?
It's probably worth addressing any inconsistencies between the parser the reference on an individual basis. I don't have enough faith in the reference to say it is always right.
My opinions on the issues in the OP:
I think
returnstarts a new context, so it is OK to accept a struct literal after it. I don't see a parsing ambiguity there, so I think it is OK. Since the parser and reference agree, I don't think there is anything to do here.returnexpression - I thoughtreturnwas a statement, so I am not qualified to offer an opinion here as my intuition is messed up. Could someone explain why it is an expression not a statement please?agree on the last two points - bugs in the reference.
2 remaining items
- I'm afraid I had more trouble with it than I thought, please go ahead and take a stab.…On Mon, Jan 23, 2017 at 11:54 PM, Taylor Cramer ***@***.***> wrote: @neunenak <https://github.com/neunenak> Are you still interested in this? If not, I'd like to take a stab at it. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#28784 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AATA-WBhZjRJrb3XXKr0Tq2LfLt9RJ7Xks5rVa4jgaJpZM4GG9HU> .
Thanks! I took a look at the parser, and I think the issue with
returnis this match. Many (keyword) identifiers cannot appear at the start of an expression,asbeing just one of these. Should I just coverasfor now, or should I match out all identifiers which cannot be in the start of an expression?Edit: for context, the
can_begin_exprmethod is used by the parser to determine whether or notreturnis returning a value or whether it is just a barereturn(see here).I went ahead and opened #39303 fixing
can_begin_exprfor theascase. Let me know if I should fix it for any other keywords.Moving forward, what's left to do for this issue? Are all the rest just parser-lalr fixes? I don't think the lambda issue can be fixed backward-compatibly, can it? (Since we'd be stopping something from parsing that used to parse.)
Edit: wound up making a new PR handling the remaining
can_begin_exprcases on @petrochenkov's advice.@cramertj a good question. One of my long-standing "to do" items has been to pick up work on rustypop -- in particular adding a test harness -- as a replacement for parser-lalr. When I was porting the LALR grammar, I found a number of irregularities that struck me as wrong -- often holdovers from the early days of Rust -- as well as various things whose meaning were not obvious (e.g., precedence tricks). The LALRPOP port is free of those problems.
Separately, I think we have put off reaching a firm decision on a lot of these questions. This needs some organization and I think no one has had the time.
I would love to find someone who would be interested in collaborating with me on one or both aspects of this project. If you are interesting, please ping me on irc (
nmatsakis) or drop me an e-mail (nmatsakis@mozilla.com).@nikomatsakis Email'd you.
- addedT-langRelevant to the language teamRelevant to the language teamand removed
on Mar 24, 2017 This seems like an interesting fix. I'll take a look at it and see what I can figure out. -- Colin
parser-lalr has been removed in #64896. Closing in favor of the work done by the grammar working group in https://github.com/rust-lang/wg-grammar/.
I found more inconsistencies between
rustcandparser-lalr.I also noticed that Rust allows return expressions and lambda expressions to end with a struct literal, even when they're in a nostruct context. This seems inconsistent to me.
Lambdas (the two parsers disagree):
Return expressions (the two parsers agree):
The
rustcandparser-lalrparsers disagree about whether a barereturnexpression can be cast:Finally, I also noticed these two differences, which seem much less interesting to me. The grammar is probably just out-of-date or buggy:
lambda sometimes requires braces:
procis obsolete: