-
-
Notifications
You must be signed in to change notification settings - Fork 13
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 support for RE2::MatchData #57
Labels
Comments
mudge
added a commit
that referenced
this issue
Oct 22, 2022
GitHub: #57 So that RE2::MatchData can be used with Ruby's pattern matching (https://docs.ruby-lang.org/en/3.0/syntax/pattern_matching_rdoc.html), implement a deconstruct method that returns only the capturing groups. This enables the following example: case RE2('(\d)(\d)?').match("1") in x, y puts "Matched #{x} #{y}" end
mudge
added a commit
that referenced
this issue
Oct 22, 2022
GitHub: #57 In order to support pattern matching in Ruby, add a deconstruct_keys method to RE2::MatchData that will return all named matches if given nil or a subset of matches if given an array of capturing group names as symbols. To match [Ruby's implementation of this](ruby/ruby#6216) there are a few edge cases: 1. If the number of keys given exceeds the number of named capturing groups, immediately return an empty hash. 2. Each key is added to the hash in turn and the first invalid key will cause the hash to be returned so it is possible to get a partial set of named captures.
Merged
mudge
added a commit
that referenced
this issue
Oct 22, 2022
GitHub: #57 So that RE2::MatchData can be used with Ruby's pattern matching (https://docs.ruby-lang.org/en/3.0/syntax/pattern_matching_rdoc.html), implement a deconstruct method that returns only the capturing groups. This enables the following example: case RE2('(\d)(\d)?').match("1") in x, y puts "Matched #{x} #{y}" end
mudge
added a commit
that referenced
this issue
Oct 22, 2022
GitHub: #57 In order to support pattern matching in Ruby, add a deconstruct_keys method to RE2::MatchData that will return all named matches if given nil or a subset of matches if given an array of capturing group names as symbols. To match [Ruby's implementation of this](ruby/ruby#6216) there are a few edge cases: 1. If the number of keys given exceeds the number of named capturing groups, immediately return an empty hash. 2. Each key is added to the hash in turn and the first invalid key will cause the hash to be returned so it is possible to get a partial set of named captures.
mudge
added a commit
that referenced
this issue
Oct 22, 2022
GitHub: #57 In order to support pattern matching in Ruby, add a deconstruct_keys method to RE2::MatchData that will return all named matches if given nil or a subset of matches if given an array of capturing group names as symbols. To match [Ruby's implementation of this](ruby/ruby#6216) there are a few edge cases: 1. If the number of keys given exceeds the number of named capturing groups, immediately return an empty hash. 2. Each key is added to the hash in turn and the first invalid key will cause the hash to be returned so it is possible to get a partial set of named captures.
mudge
added a commit
that referenced
this issue
Oct 22, 2022
GitHub: #57 So that RE2::MatchData can be used with Ruby's pattern matching (https://docs.ruby-lang.org/en/3.0/syntax/pattern_matching_rdoc.html), implement a deconstruct method that returns only the capturing groups. This enables the following example: case RE2('(\d)(\d)?').match("1") in x, y puts "Matched #{x} #{y}" end
mudge
added a commit
that referenced
this issue
Oct 22, 2022
GitHub: #57 In order to support pattern matching in Ruby, add a deconstruct_keys method to RE2::MatchData that will return all named matches if given nil or a subset of matches if given an array of capturing group names as symbols. To match [Ruby's implementation of this](ruby/ruby#6216) there are a few edge cases: 1. If the number of keys given exceeds the number of named capturing groups, immediately return an empty hash. 2. Each key is added to the hash in turn and the first invalid key will cause the hash to be returned so it is possible to get a partial set of named captures.
Added in #58 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As per ruby/ruby#6216, add support for pattern matching RE2::MatchData objects by implementing deconstruct and deconstruct_keys.
See https://docs.ruby-lang.org/en/3.0/syntax/pattern_matching_rdoc.html#label-Matching+non-primitive+objects-3A+deconstruct+and+deconstruct_keys
The text was updated successfully, but these errors were encountered: