-
Notifications
You must be signed in to change notification settings - Fork 57
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
Pattern matching #193
Pattern matching #193
Conversation
ff1d2f4
to
31abc7f
Compare
85a588d
to
176f3a9
Compare
176f3a9
to
2ca1233
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, thanks @aibaars! Do the syntax highlighting queries need to be updated to highlight patterns correctly?
@dcreager Possibly, but I don't know how to check that. I suspect that things might "just work" already because the pattern syntax is quite similar to expressions and re-uses the same keywords. |
The easiest way would be to run |
(encoding) @constant.builtin | ||
|
||
(hash_pattern_norest | ||
"**" @operator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dcreager Ideally the highlight of **
would be none
, however, I don't know how to express that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I actually don't know if that can be done! That's an interesting thing that we should support. 👍 with this workaround for now.
(encoding) @constant.builtin | ||
|
||
(hash_pattern_norest | ||
"**" @operator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I actually don't know if that can be done! That's an interesting thing that we should support. 👍 with this workaround for now.
This pull request adds pattern matching syntax to the Ruby grammar. This syntax looks as follows:
See also: https://docs.ruby-lang.org/en/3.0.0/doc/syntax/pattern_matching_rdoc.html
This pull request does not yet add the one-line pattern matching syntax (
expr in pattern
andexpr => pattern
). While the addition to the grammar just a few lines, it causes a serious increase in the generated C code. Therefore, I think this is best left as a follow-up pull request where we can discuss what causes the blow-up and how to address it. See also: aibaars#1This pull request makes some minor changes to the existing grammar:
_expression
is added to the supertypes list to avoid a lot of duplication in the node-types file_literal
is extracted for the various types of literals allowing it to be used for expressions as well as patterns.Checklist: