[ruby-core:94108] [Ruby master Feature#16037] Allow multiple single-splatted variables in `in` pattern matching and introduce non-greedy-splatted variables

From: sawadatsuyoshi@...
Date: 2019-08-02 11:50:31 UTC
List: ruby-core #94108
Issue #16037 has been reported by sawa (Tsuyoshi Sawada).

----------------------------------------
Feature #16037: Allow multiple single-splatted variables in `in` pattern matching and introduce non-greedy-splatted variables
https://bugs.ruby-lang.org/issues/16037

* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Pattern matching in `in` argument seems to prohibit multiple occurrences of single/double-splatted variables.

```ruby
case ""; in *foo, bar; end # >> NoMatchingPatternError (Not SyntaxError)
case ""; in *foo, *bar; end # >> SyntaxError: unexpected *
```

However, unlike conventional constant/variable assignment, it makes sense to have multiple occurrences of single/double-splatted variables in a single pattern matching provided that we have a definite rule regarding whether the splats are greedy or not.

I propose the following.

1. Relax the syntax for pattern matching in `in` argument to allow multiple occurrences of single/double-splatted variables, and set up a rule regarding whether the splats are greedy or not; preferably greedy.
2. Further, introduce new syntax for non-greedy splats `*?foo`, `**?foo`. Currently, they are syntactically invalid, so I don't think they would conflict with existing code.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next