-
Notifications
You must be signed in to change notification settings - Fork 205
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
[patterns] Syntactic ambiguity #2714
Comments
We can do this if you really think it's worth it, but I chose the current approach because I believe it leads to a simpler specification overall. If we have both I felt it was simpler to have the grammar productions have a 1-1 correspondence with semantics and then just disambiguate the syntax early on. That way, all variable declarations in patterns are |
The point is that the current grammar is ambiguous, and the parser can't decide on which derivation to use in each case.
The patterns spec refers to 'variablePattern' two times, total. Everywhere else it says 'variable pattern'. So you just need to say, once, that a variable pattern is a Similarly, a constant pattern is a There is no separate pattern for bare identifiers in an assignment context, but we could have an assignable expression pattern which would be an |
I think I agree with @eernstg here that if we're going to go to the trouble to specify the grammar, we shouldn't specify a grammar that is unnecessarily ambiguous, even if it should be obvious to the implementation teams how to programmatically disambiguate it. |
There are no user-visible syntax or semantic changes here. It only changes how the grammar is organized. Fix #2714.
* [patterns] Disambiguate identifiers in the pattern grammar. There are no user-visible syntax or semantic changes here. It only changes how the grammar is organized. Fix #2714. * Apply review feedback.
The grammar rules about patterns include an ambiguity:
I would recommend that the grammar is changed such that neither
<constantPattern>
nor<variablePattern>
can derive<identifier>
, but<primaryPattern>
gets a new case<identifierPattern>
:An identifier pattern would then be disambiguated based on the context:
The text was updated successfully, but these errors were encountered: