Skip to content
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

Support it (read: It is time to switch to Prism.) #1450

Open
ParadoxV5 opened this issue Dec 28, 2024 · 0 comments
Open

Support it (read: It is time to switch to Prism.) #1450

ParadoxV5 opened this issue Dec 28, 2024 · 0 comments

Comments

@ParadoxV5
Copy link
Contributor

ParadoxV5 commented Dec 28, 2024

Late Merry Christmas! Ruby 3.4 is out and–

$ cat ruby.rb; steep check
5.then { it }
# Type checking files:

.F

ruby.rb:1:9: [error] Type `::Object` does not have method `it`
│ Diagnostic ID: Ruby::NoMethod

└ 5.then { it }
           ~~

Detected 1 problem from 1 file

The problem:

irb(main):001> require 'parser/current'
warning: parser/current is loading parser/ruby34, which recognizes 3.4.0-compliant syntax, but you are running 3.4.1.
Please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
=> true
irb(main):002> Parser::CurrentRuby.parse('5.then { it }')
=>
s(:block,
  s(:send,
    s(:int, 5), :then),
  s(:args),
  s(:send, nil, :it))
irb(main):003> Parser::CurrentRuby.parse('5.then { _1 }') # control
=>
s(:numblock,
  s(:send,
    s(:int, 5), :then), 1,
  s(:lvar, :_1))

But should we bother the Parser team?

With the conclusion of the Syntax Moratorium, who know what pipeline operators creative sugar the devs of Ruby will come up with.
Combined with syntax bug fixes, Prism the “official” parser will make maintainers new and old lose interest of older alternatives, sooner or later.

irb(main):001> Prism.parse '5.then { it }'
=>

              └── block:
                  @ BlockNode (location: (1,7)-(1,13))
                  ├── flags: 
                  ├── locals: []
                  ├── parameters:
                     @ ItParametersNode (location: (1,7)-(1,13))
                     └── flags: 
                  ├── body:

I can stick with _1s for the time beïng.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant