Improve grammar after the introduction of case-in pattern matching#197
Merged
aibaars merged 7 commits intotree-sitter:masterfrom Nov 22, 2021
Merged
Improve grammar after the introduction of case-in pattern matching#197aibaars merged 7 commits intotree-sitter:masterfrom
aibaars merged 7 commits intotree-sitter:masterfrom
Conversation
* The value is not optional * Remove singleton 'choice' from rule
* alias 'pattern_constant_resolution' as 'scope_resolution' * replace 'pattern_constant' with just 'constant'
483652c to
b8ef948
Compare
nickrolfe
suggested changes
Nov 22, 2021
|
|
||
| case_match: $ => seq( | ||
| 'case', | ||
| field('value', optional($._statement)), |
Contributor
There was a problem hiding this comment.
I don't think this change is correct, since the value does appear to be optional. MRI accepts code like this:
def f(a, b)
case
when a > 1
puts 'foo'
when b == 7
puts 'bar'
else
puts 'baz'
end
endHere is an example I found in the wild.
Compare parse.y line 3134 with line 3118.
Contributor
Author
There was a problem hiding this comment.
That case is covered by the case rule. The expression case in pattern then ... is not valid. The missing value is only allowed in combination with when branches.
Contributor
There was a problem hiding this comment.
Ah, sorry, that makes sense.
* array_pattern_rest => splat_parameter * hash_pattern_rest => hash_splat_parameter * hash_pattern_norest => hash_split_nil
This is more consistent with the naming of keyword_parameter
A pattern_variable is simply an identifier, no need for an additional named node.
nickrolfe
approved these changes
Nov 22, 2021
Contributor
nickrolfe
left a comment
There was a problem hiding this comment.
I went though each commit one-by-one, and they all look sensible to me.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request implements some simplifications and minor fixes .
case value in ...is no longer optionalcase_matchrule is removedconstantandscope_expression)*and**in array and hash patterns now use the same node names as the ones used in formal parameter lists (iesplat_parameter,hash_splat_parameter)**niltoken is now namedhash_splat_niland is used in patterns as well as formal parameter lists (used to be missing)pattern_pairis renamed tokeyword_patternto match the naming ofkeyword_parameterpattern_variablewas removed, it is a simpleidentifierand there is no real need for an additional wrapper node .range)Checklist: