ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:119462] [Ruby master Bug#20785] Should `a in b, and c` `a in b, or c` `a in b, rescue c` be syntax ok?
@ 2024-10-05  7:47 tompng (tomoya ishida) via ruby-core
  2024-10-05 14:25 ` [ruby-core:119463] " nobu (Nobuyoshi Nakada) via ruby-core
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: tompng (tomoya ishida) via ruby-core @ 2024-10-05  7:47 UTC (permalink / raw)
  To: ruby-core; +Cc: tompng (tomoya ishida)

Issue #20785 has been reported by tompng (tomoya ishida).

----------------------------------------
Bug #20785: Should `a in b, and c` `a in b, or c` `a in b, rescue c` be syntax ok?
https://bugs.ruby-lang.org/issues/20785

* Author: tompng (tomoya ishida)
* Status: Open
* ruby -v: ruby 3.4.0dev (2024-10-04T03:22:53Z master 939ec9f080) +YJIT +MN +PRISM [arm64-darwin22]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
This code is accepted in parse.y but rejected in prism
~~~ruby
tap do
  a in b, and c
  a in b, or c
  a in b, rescue c
end

# parsed as
tap do
  (a in b,;) and c
  (a in b,;) or c
  a in b,;
rescue c
end
~~~

I think these should be rejected like prism (parse.y accepts)
~~~ruby
a in b, and c

a in b,
and c

tap do
  a in b, rescue c
end
~~~


I think these should be accepted like parse.y (prism rejects)
~~~ruby
tap do
  a in b,
end

tap do
  a in b,
rescue
end
~~~



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:119463] [Ruby master Bug#20785] Should `a in b, and c` `a in b, or c` `a in b, rescue c` be syntax ok?
  2024-10-05  7:47 [ruby-core:119462] [Ruby master Bug#20785] Should `a in b, and c` `a in b, or c` `a in b, rescue c` be syntax ok? tompng (tomoya ishida) via ruby-core
@ 2024-10-05 14:25 ` nobu (Nobuyoshi Nakada) via ruby-core
  2024-10-05 14:27 ` [ruby-core:119464] " nobu (Nobuyoshi Nakada) via ruby-core
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: nobu (Nobuyoshi Nakada) via ruby-core @ 2024-10-05 14:25 UTC (permalink / raw)
  To: ruby-core; +Cc: nobu (Nobuyoshi Nakada)

Issue #20785 has been updated by nobu (Nobuyoshi Nakada).

Assignee set to matz (Yukihiro Matsumoto)

----------------------------------------
Bug #20785: Should `a in b, and c` `a in b, or c` `a in b, rescue c` be syntax ok?
https://bugs.ruby-lang.org/issues/20785#change-110081

* Author: tompng (tomoya ishida)
* Status: Open
* Assignee: matz (Yukihiro Matsumoto)
* ruby -v: ruby 3.4.0dev (2024-10-04T03:22:53Z master 939ec9f080) +YJIT +MN +PRISM [arm64-darwin22]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
This code is accepted in parse.y but rejected in prism
~~~ruby
tap do
  a in b, and c
  a in b, or c
  a in b, rescue c
end

# parsed as
tap do
  (a in b,;) and c
  (a in b,;) or c
  a in b,;
rescue c
end
~~~

I think these should be rejected like prism (parse.y accepts)
~~~ruby
a in b, and c

a in b,
and c

tap do
  a in b, rescue c
end
~~~


I think these should be accepted like parse.y (prism rejects)
~~~ruby
tap do
  a in b,
end

tap do
  a in b,
rescue
end
~~~



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:119464] [Ruby master Bug#20785] Should `a in b, and c` `a in b, or c` `a in b, rescue c` be syntax ok?
  2024-10-05  7:47 [ruby-core:119462] [Ruby master Bug#20785] Should `a in b, and c` `a in b, or c` `a in b, rescue c` be syntax ok? tompng (tomoya ishida) via ruby-core
  2024-10-05 14:25 ` [ruby-core:119463] " nobu (Nobuyoshi Nakada) via ruby-core
@ 2024-10-05 14:27 ` nobu (Nobuyoshi Nakada) via ruby-core
  2024-10-06  0:55 ` [ruby-core:119467] " Dan0042 (Daniel DeLorme) via ruby-core
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: nobu (Nobuyoshi Nakada) via ruby-core @ 2024-10-05 14:27 UTC (permalink / raw)
  To: ruby-core; +Cc: nobu (Nobuyoshi Nakada)

Issue #20785 has been updated by nobu (Nobuyoshi Nakada).

Assignee changed from matz (Yukihiro Matsumoto) to ktsj (Kazuki Tsujimoto)

----------------------------------------
Bug #20785: Should `a in b, and c` `a in b, or c` `a in b, rescue c` be syntax ok?
https://bugs.ruby-lang.org/issues/20785#change-110082

* Author: tompng (tomoya ishida)
* Status: Open
* Assignee: ktsj (Kazuki Tsujimoto)
* ruby -v: ruby 3.4.0dev (2024-10-04T03:22:53Z master 939ec9f080) +YJIT +MN +PRISM [arm64-darwin22]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
This code is accepted in parse.y but rejected in prism
~~~ruby
tap do
  a in b, and c
  a in b, or c
  a in b, rescue c
end

# parsed as
tap do
  (a in b,;) and c
  (a in b,;) or c
  a in b,;
rescue c
end
~~~

I think these should be rejected like prism (parse.y accepts)
~~~ruby
a in b, and c

a in b,
and c

tap do
  a in b, rescue c
end
~~~


I think these should be accepted like parse.y (prism rejects)
~~~ruby
tap do
  a in b,
end

tap do
  a in b,
rescue
end
~~~



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:119467] [Ruby master Bug#20785] Should `a in b, and c` `a in b, or c` `a in b, rescue c` be syntax ok?
  2024-10-05  7:47 [ruby-core:119462] [Ruby master Bug#20785] Should `a in b, and c` `a in b, or c` `a in b, rescue c` be syntax ok? tompng (tomoya ishida) via ruby-core
  2024-10-05 14:25 ` [ruby-core:119463] " nobu (Nobuyoshi Nakada) via ruby-core
  2024-10-05 14:27 ` [ruby-core:119464] " nobu (Nobuyoshi Nakada) via ruby-core
@ 2024-10-06  0:55 ` Dan0042 (Daniel DeLorme) via ruby-core
  2024-10-06  4:07 ` [ruby-core:119468] " ktsj (Kazuki Tsujimoto) via ruby-core
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Dan0042 (Daniel DeLorme) via ruby-core @ 2024-10-06  0:55 UTC (permalink / raw)
  To: ruby-core; +Cc: Dan0042 (Daniel DeLorme)

Issue #20785 has been updated by Dan0042 (Daniel DeLorme).


tompng (tomoya ishida) wrote:
> I think these should be accepted like parse.y (prism rejects)
> ~~~ruby
> tap do
>   a in b,
> end
> 
> tap do
>   a in b,
> rescue
> end
> ~~~

Can you explain your reasoning here? I'm guessing that `a in b,` is parsed as `a in [b,]` but a trailing comma like that is just too wild for me; it totally breaks my intuitions about Ruby syntax, and I think it should be rejected.

----------------------------------------
Bug #20785: Should `a in b, and c` `a in b, or c` `a in b, rescue c` be syntax ok?
https://bugs.ruby-lang.org/issues/20785#change-110085

* Author: tompng (tomoya ishida)
* Status: Open
* Assignee: ktsj (Kazuki Tsujimoto)
* ruby -v: ruby 3.4.0dev (2024-10-04T03:22:53Z master 939ec9f080) +YJIT +MN +PRISM [arm64-darwin22]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
This code is accepted in parse.y but rejected in prism
~~~ruby
tap do
  a in b, and c
  a in b, or c
  a in b, rescue c
end

# parsed as
tap do
  (a in b,;) and c
  (a in b,;) or c
  a in b,;
rescue c
end
~~~

I think these should be rejected like prism (parse.y accepts)
~~~ruby
a in b, and c

a in b,
and c

tap do
  a in b, rescue c
end
~~~


I think these should be accepted like parse.y (prism rejects)
~~~ruby
tap do
  a in b,
end

tap do
  a in b,
rescue
end
~~~



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:119468] [Ruby master Bug#20785] Should `a in b, and c` `a in b, or c` `a in b, rescue c` be syntax ok?
  2024-10-05  7:47 [ruby-core:119462] [Ruby master Bug#20785] Should `a in b, and c` `a in b, or c` `a in b, rescue c` be syntax ok? tompng (tomoya ishida) via ruby-core
                   ` (2 preceding siblings ...)
  2024-10-06  0:55 ` [ruby-core:119467] " Dan0042 (Daniel DeLorme) via ruby-core
@ 2024-10-06  4:07 ` ktsj (Kazuki Tsujimoto) via ruby-core
  2024-11-07 10:34 ` [ruby-core:119802] " mame (Yusuke Endoh) via ruby-core
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: ktsj (Kazuki Tsujimoto) via ruby-core @ 2024-10-06  4:07 UTC (permalink / raw)
  To: ruby-core; +Cc: ktsj (Kazuki Tsujimoto)

Issue #20785 has been updated by ktsj (Kazuki Tsujimoto).

Assignee changed from ktsj (Kazuki Tsujimoto) to matz (Yukihiro Matsumoto)

I agree with tompng's proposal.

> I'm guessing that `a in b`, is parsed as `a in [b,]` but a trailing comma like that is just too wild for me

`in` (`=>`) can be considered right assignment.
And, I think it makes sense that a trailing comma is allowed in right assignment, just as a trailing comma is allowed in normal assignment.

```ruby
a => b, # one-line pattern matching as right assignment
b, = a  # normal assignment
```

What do you think, @matz?


----------------------------------------
Bug #20785: Should `a in b, and c` `a in b, or c` `a in b, rescue c` be syntax ok?
https://bugs.ruby-lang.org/issues/20785#change-110086

* Author: tompng (tomoya ishida)
* Status: Open
* Assignee: matz (Yukihiro Matsumoto)
* ruby -v: ruby 3.4.0dev (2024-10-04T03:22:53Z master 939ec9f080) +YJIT +MN +PRISM [arm64-darwin22]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
This code is accepted in parse.y but rejected in prism
~~~ruby
tap do
  a in b, and c
  a in b, or c
  a in b, rescue c
end

# parsed as
tap do
  (a in b,;) and c
  (a in b,;) or c
  a in b,;
rescue c
end
~~~

I think these should be rejected like prism (parse.y accepts)
~~~ruby
a in b, and c

a in b,
and c

tap do
  a in b, rescue c
end
~~~


I think these should be accepted like parse.y (prism rejects)
~~~ruby
tap do
  a in b,
end

tap do
  a in b,
rescue
end
~~~



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:119802] [Ruby master Bug#20785] Should `a in b, and c` `a in b, or c` `a in b, rescue c` be syntax ok?
  2024-10-05  7:47 [ruby-core:119462] [Ruby master Bug#20785] Should `a in b, and c` `a in b, or c` `a in b, rescue c` be syntax ok? tompng (tomoya ishida) via ruby-core
                   ` (3 preceding siblings ...)
  2024-10-06  4:07 ` [ruby-core:119468] " ktsj (Kazuki Tsujimoto) via ruby-core
@ 2024-11-07 10:34 ` mame (Yusuke Endoh) via ruby-core
  2024-11-08 15:44 ` [ruby-core:119844] " kddnewton (Kevin Newton) via ruby-core
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mame (Yusuke Endoh) via ruby-core @ 2024-11-07 10:34 UTC (permalink / raw)
  To: ruby-core; +Cc: mame (Yusuke Endoh)

Issue #20785 has been updated by mame (Yusuke Endoh).


Discussed at the dev meeting. Matz says that, in principle, the trailing comma of a pattern should be allowed.

```ruby
a in b, and c    # Prism should accept this as `(a in b,) and c`
a in b, or c     # Prism should accept this as `(a in b,) or c`
```

In terms of rescue after a comma, it should be handled as a modifier.

```ruby
a in b, rescue c # (a in b,) rescue c
```

In terms of a newline after a comma, it should be handled as an end of a sentence.

```ruby
a in b, # This line should be a complete sentence
and c   # This is an invalid line
```

However, if there are implementation difficulties with the parser, he would consider compromises.

@yui-knk @kddnewton Do you think if matz's expectation is feasible?

----------------------------------------
Bug #20785: Should `a in b, and c` `a in b, or c` `a in b, rescue c` be syntax ok?
https://bugs.ruby-lang.org/issues/20785#change-110486

* Author: tompng (tomoya ishida)
* Status: Open
* Assignee: matz (Yukihiro Matsumoto)
* ruby -v: ruby 3.4.0dev (2024-10-04T03:22:53Z master 939ec9f080) +YJIT +MN +PRISM [arm64-darwin22]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
This code is accepted in parse.y but rejected in prism
~~~ruby
tap do
  a in b, and c
  a in b, or c
  a in b, rescue c
end

# parsed as
tap do
  (a in b,;) and c
  (a in b,;) or c
  a in b,;
rescue c
end
~~~

I think these should be rejected like prism (parse.y accepts)
~~~ruby
a in b, and c

a in b,
and c

tap do
  a in b, rescue c
end
~~~


I think these should be accepted like parse.y (prism rejects)
~~~ruby
tap do
  a in b,
end

tap do
  a in b,
rescue
end
~~~



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:119844] [Ruby master Bug#20785] Should `a in b, and c` `a in b, or c` `a in b, rescue c` be syntax ok?
  2024-10-05  7:47 [ruby-core:119462] [Ruby master Bug#20785] Should `a in b, and c` `a in b, or c` `a in b, rescue c` be syntax ok? tompng (tomoya ishida) via ruby-core
                   ` (4 preceding siblings ...)
  2024-11-07 10:34 ` [ruby-core:119802] " mame (Yusuke Endoh) via ruby-core
@ 2024-11-08 15:44 ` kddnewton (Kevin Newton) via ruby-core
  2024-11-13 13:14 ` [ruby-core:119914] " Dan0042 (Daniel DeLorme) via ruby-core
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: kddnewton (Kevin Newton) via ruby-core @ 2024-11-08 15:44 UTC (permalink / raw)
  To: ruby-core; +Cc: kddnewton (Kevin Newton)

Issue #20785 has been updated by kddnewton (Kevin Newton).


I think this resolution makes sense, we can make that work. Should we get started on it?

----------------------------------------
Bug #20785: Should `a in b, and c` `a in b, or c` `a in b, rescue c` be syntax ok?
https://bugs.ruby-lang.org/issues/20785#change-110534

* Author: tompng (tomoya ishida)
* Status: Open
* Assignee: matz (Yukihiro Matsumoto)
* ruby -v: ruby 3.4.0dev (2024-10-04T03:22:53Z master 939ec9f080) +YJIT +MN +PRISM [arm64-darwin22]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
This code is accepted in parse.y but rejected in prism
~~~ruby
tap do
  a in b, and c
  a in b, or c
  a in b, rescue c
end

# parsed as
tap do
  (a in b,;) and c
  (a in b,;) or c
  a in b,;
rescue c
end
~~~

I think these should be rejected like prism (parse.y accepts)
~~~ruby
a in b, and c

a in b,
and c

tap do
  a in b, rescue c
end
~~~


I think these should be accepted like parse.y (prism rejects)
~~~ruby
tap do
  a in b,
end

tap do
  a in b,
rescue
end
~~~



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:119914] [Ruby master Bug#20785] Should `a in b, and c` `a in b, or c` `a in b, rescue c` be syntax ok?
  2024-10-05  7:47 [ruby-core:119462] [Ruby master Bug#20785] Should `a in b, and c` `a in b, or c` `a in b, rescue c` be syntax ok? tompng (tomoya ishida) via ruby-core
                   ` (5 preceding siblings ...)
  2024-11-08 15:44 ` [ruby-core:119844] " kddnewton (Kevin Newton) via ruby-core
@ 2024-11-13 13:14 ` Dan0042 (Daniel DeLorme) via ruby-core
  2024-11-13 13:39 ` [ruby-core:119916] " Eregon (Benoit Daloze) via ruby-core
  2024-11-16  6:05 ` [ruby-core:119946] " mame (Yusuke Endoh) via ruby-core
  8 siblings, 0 replies; 10+ messages in thread
From: Dan0042 (Daniel DeLorme) via ruby-core @ 2024-11-13 13:14 UTC (permalink / raw)
  To: ruby-core; +Cc: Dan0042 (Daniel DeLorme)

Issue #20785 has been updated by Dan0042 (Daniel DeLorme).


mame (Yusuke Endoh) wrote in #note-5:
> In terms of a newline after a comma, it should be handled as an end of a sentence.
> 
> ```ruby
> a in b, # This line should be a complete sentence
> and c   # This is an invalid line
> ```

I doubt my opinion makes any difference here, but the above makes no sense to me. I would expect this to be a valid pattern match:

```ruby
a in b,
     c,
     d 
```


----------------------------------------
Bug #20785: Should `a in b, and c` `a in b, or c` `a in b, rescue c` be syntax ok?
https://bugs.ruby-lang.org/issues/20785#change-110635

* Author: tompng (tomoya ishida)
* Status: Assigned
* Assignee: matz (Yukihiro Matsumoto)
* ruby -v: ruby 3.4.0dev (2024-10-04T03:22:53Z master 939ec9f080) +YJIT +MN +PRISM [arm64-darwin22]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
This code is accepted in parse.y but rejected in prism
~~~ruby
tap do
  a in b, and c
  a in b, or c
  a in b, rescue c
end

# parsed as
tap do
  (a in b,;) and c
  (a in b,;) or c
  a in b,;
rescue c
end
~~~

I think these should be rejected like prism (parse.y accepts)
~~~ruby
a in b, and c

a in b,
and c

tap do
  a in b, rescue c
end
~~~


I think these should be accepted like parse.y (prism rejects)
~~~ruby
tap do
  a in b,
end

tap do
  a in b,
rescue
end
~~~



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:119916] [Ruby master Bug#20785] Should `a in b, and c` `a in b, or c` `a in b, rescue c` be syntax ok?
  2024-10-05  7:47 [ruby-core:119462] [Ruby master Bug#20785] Should `a in b, and c` `a in b, or c` `a in b, rescue c` be syntax ok? tompng (tomoya ishida) via ruby-core
                   ` (6 preceding siblings ...)
  2024-11-13 13:14 ` [ruby-core:119914] " Dan0042 (Daniel DeLorme) via ruby-core
@ 2024-11-13 13:39 ` Eregon (Benoit Daloze) via ruby-core
  2024-11-16  6:05 ` [ruby-core:119946] " mame (Yusuke Endoh) via ruby-core
  8 siblings, 0 replies; 10+ messages in thread
From: Eregon (Benoit Daloze) via ruby-core @ 2024-11-13 13:39 UTC (permalink / raw)
  To: ruby-core; +Cc: Eregon (Benoit Daloze)

Issue #20785 has been updated by Eregon (Benoit Daloze).


I think @Dan0042 has a point.
For instance if I'm using some longer variables names and the array/tuple has many elements it would be natural to wrap it into two lines, but IIUC this change would break it:
```ruby
if tuple in element_type, element_size, dimensions, pointer, offset, buffer_length, stride
  ...
end
# might be wrapped as:
if tuple in element_type, element_size, dimensions, pointer, offset,
    buffer_length, stride
  ...
end
```

In the OP description, I think all cases can be very easily made clear and unambiguous by appending `*`.
For example:
```ruby
tap do
  a in b, * and c
  a in b, * or c
  a in b, * rescue c
end

tap do
  a in b, *
end

tap do
  a in b, *
rescue
end
```

>From that I *think* considering trailing comma for `in` pattern matching as SyntaxError is good, as it encourages clarity and removes syntactical ambiguity (at least from a human perception).

----------------------------------------
Bug #20785: Should `a in b, and c` `a in b, or c` `a in b, rescue c` be syntax ok?
https://bugs.ruby-lang.org/issues/20785#change-110637

* Author: tompng (tomoya ishida)
* Status: Assigned
* Assignee: matz (Yukihiro Matsumoto)
* ruby -v: ruby 3.4.0dev (2024-10-04T03:22:53Z master 939ec9f080) +YJIT +MN +PRISM [arm64-darwin22]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
This code is accepted in parse.y but rejected in prism
~~~ruby
tap do
  a in b, and c
  a in b, or c
  a in b, rescue c
end

# parsed as
tap do
  (a in b,;) and c
  (a in b,;) or c
  a in b,;
rescue c
end
~~~

I think these should be rejected like prism (parse.y accepts)
~~~ruby
a in b, and c

a in b,
and c

tap do
  a in b, rescue c
end
~~~


I think these should be accepted like parse.y (prism rejects)
~~~ruby
tap do
  a in b,
end

tap do
  a in b,
rescue
end
~~~



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:119946] [Ruby master Bug#20785] Should `a in b, and c` `a in b, or c` `a in b, rescue c` be syntax ok?
  2024-10-05  7:47 [ruby-core:119462] [Ruby master Bug#20785] Should `a in b, and c` `a in b, or c` `a in b, rescue c` be syntax ok? tompng (tomoya ishida) via ruby-core
                   ` (7 preceding siblings ...)
  2024-11-13 13:39 ` [ruby-core:119916] " Eregon (Benoit Daloze) via ruby-core
@ 2024-11-16  6:05 ` mame (Yusuke Endoh) via ruby-core
  8 siblings, 0 replies; 10+ messages in thread
From: mame (Yusuke Endoh) via ruby-core @ 2024-11-16  6:05 UTC (permalink / raw)
  To: ruby-core; +Cc: mame (Yusuke Endoh)

Issue #20785 has been updated by mame (Yusuke Endoh).


Dan0042 (Daniel DeLorme) wrote in #note-8:
> I doubt my opinion makes any difference here, but the above makes no sense to me. I would expect this to be a valid pattern match:
> 
> ```ruby
> a in b,
>      c,
>      d 
> ```

In RubyConf venue, I showed @matz your example, and it has convinced him. He changed his mind and said that a comma at the line end should continue to the next line. Your opinion made difference :-)

----------------------------------------
Bug #20785: Should `a in b, and c` `a in b, or c` `a in b, rescue c` be syntax ok?
https://bugs.ruby-lang.org/issues/20785#change-110669

* Author: tompng (tomoya ishida)
* Status: Assigned
* Assignee: matz (Yukihiro Matsumoto)
* ruby -v: ruby 3.4.0dev (2024-10-04T03:22:53Z master 939ec9f080) +YJIT +MN +PRISM [arm64-darwin22]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
This code is accepted in parse.y but rejected in prism
~~~ruby
tap do
  a in b, and c
  a in b, or c
  a in b, rescue c
end

# parsed as
tap do
  (a in b,;) and c
  (a in b,;) or c
  a in b,;
rescue c
end
~~~

I think these should be rejected like prism (parse.y accepts)
~~~ruby
a in b, and c

a in b,
and c

tap do
  a in b, rescue c
end
~~~


I think these should be accepted like parse.y (prism rejects)
~~~ruby
tap do
  a in b,
end

tap do
  a in b,
rescue
end
~~~



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-11-16  6:05 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-05  7:47 [ruby-core:119462] [Ruby master Bug#20785] Should `a in b, and c` `a in b, or c` `a in b, rescue c` be syntax ok? tompng (tomoya ishida) via ruby-core
2024-10-05 14:25 ` [ruby-core:119463] " nobu (Nobuyoshi Nakada) via ruby-core
2024-10-05 14:27 ` [ruby-core:119464] " nobu (Nobuyoshi Nakada) via ruby-core
2024-10-06  0:55 ` [ruby-core:119467] " Dan0042 (Daniel DeLorme) via ruby-core
2024-10-06  4:07 ` [ruby-core:119468] " ktsj (Kazuki Tsujimoto) via ruby-core
2024-11-07 10:34 ` [ruby-core:119802] " mame (Yusuke Endoh) via ruby-core
2024-11-08 15:44 ` [ruby-core:119844] " kddnewton (Kevin Newton) via ruby-core
2024-11-13 13:14 ` [ruby-core:119914] " Dan0042 (Daniel DeLorme) via ruby-core
2024-11-13 13:39 ` [ruby-core:119916] " Eregon (Benoit Daloze) via ruby-core
2024-11-16  6:05 ` [ruby-core:119946] " mame (Yusuke Endoh) via ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).