Project

General

Profile

Actions

Bug #20790

open

Syntax acceptance of `*x = p rescue p 1` is different between parse.y and prism

Bug #20790: Syntax acceptance of `*x = p rescue p 1` is different between parse.y and prism

Added by tompng (tomoya ishida) about 1 year ago. Updated 12 months ago.

Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 3.4.0dev (2024-10-09T03:27:05Z master ed11a244dd) +PRISM [x86_64-linux]
[ruby-core:119488]

Description

*x = p rescue p 1 # syntax error in prism *x = p 1 rescue p 1 # both syntax ok x = p rescue p 1 # both syntax error x = p 1 rescue p 1 # both syntax ok 

Which is correct? If *x = p rescue p 1 is syntax valid, should x = p rescue p 1 also be syntax valid?


Related issues 1 (0 open1 closed)

Updated by mame (Yusuke Endoh) about 1 year ago Actions #1

  • Related to Bug #8279: Single-line rescue parsing added

Updated by mame (Yusuke Endoh) about 1 year ago Actions #2 [ruby-core:119803]

Discussed at the dev meeting. Here is matz's preference.

 # current parse.y behavior # matz's preference *x = p rescue p 1 # (*x = p) rescue (p 1) # *x = (p rescue (p 1)) *x = p 1 rescue p 1 # (*x = p 1) rescue (p 1) # *x = ((p 1) rescue (p 1)) a, b = p rescue p # a, b = (p rescue p) # as is x = p rescue p # x = (p rescue p) # as is x = p rescue p 1 # x = (p rescue p) 1 (ERROR) # x = (p rescue p 1) x = p 1 rescue p 1 # x = ((p 1) rescue (p 1)) # as is 

@yui-knk (Kaneko Yuichiro) @kddnewton (Kevin Newton) What do you think?

Updated by kddnewton (Kevin Newton) about 1 year ago Actions #3 [ruby-core:119845]

That makes sense to me, we can make that work.

Updated by ydah (Yudai Takada) 12 months ago Actions #4 [ruby-core:120001]

I checked if it is feasible with parse.y: https://github.com/ydah/ruby/commit/50100c136ac4bbe379b2c360994b739227610e17

I have been able to confirm that the following are feasible with the modifications shown above.

 # current parse.y behavior # matz's preference *x = p rescue p 1 # (*x = p) rescue (p 1) # *x = (p rescue (p 1)) *x = p 1 rescue p 1 # (*x = p 1) rescue (p 1) # *x = ((p 1) rescue (p 1)) a, b = p rescue p # a, b = (p rescue p) # as is x = p rescue p # x = (p rescue p) # as is x = p 1 rescue p 1 # x = ((p 1) rescue (p 1)) # as is 

The following are still under investigation for feasibility.

 # current parse.y behavior # matz's preference x = p rescue p 1 # x = (p rescue p) 1 (ERROR) # x = (p rescue p 1) 
Actions

Also available in: PDF Atom