diff options
author | Koichi ITO <[email protected]> | 2025-02-26 13:02:17 +0900 |
---|---|---|
committer | git <[email protected]> | 2025-03-10 16:57:46 +0000 |
commit | 6b4453e332d67b5fb8f6932244fff9c7b385abdc (patch) | |
tree | be2651464744deaa5426d82088129583960698a2 /lib/prism/translation/parser/compiler.rb | |
parent | 97c133a8591495156f46b53c613abee8c7088a04 (diff) |
[ruby/prism] Support `itblock` for `Prism::Translation::Parser`
## Summary
`itblock` node is added to support the `it` block parameter syntax introduced in Ruby 3.4.
```console
$ ruby -Ilib -rprism -rprism/translation/parser34 -e 'buffer = Parser::Source::Buffer.new("path"); buffer.source = "proc { it }"; \
p Prism::Translation::Parser34.new.tokenize(buffer)[0]'
s(:itblock,
s(:send, nil, :proc), :it,
s(:lvar, :it))
```
This node design is similar to the `numblock` node, which was introduced for the numbered parameter syntax in Ruby 2.7.
```
$ ruby -Ilib -rprism -rprism/translation/parser34 -e 'buffer = Parser::Source::Buffer.new("path"); buffer.source = "proc { _1 }"; \
p Prism::Translation::Parser34.new.tokenize(buffer)[0]'
s(:numblock,
s(:send, nil, :proc), 1,
s(:lvar, :_1))
```
The difference is that while numbered parameters can have multiple parameters, the `it` block parameter syntax allows only a single parameter.
In Ruby 3.3, the conventional node prior to the `it` block parameter syntax is returned.
```console
$ ruby -Ilib -rprism -rprism/translation/parser33 -e 'buffer = Parser::Source::Buffer.new("path"); buffer.source = "proc { it }"; \
p Prism::Translation::Parser33.new.tokenize(buffer)[0]'
s(:block,
s(:send, nil, :proc),
s(:args),
s(:send, nil, :it))
```
## Development Note
The Parser gem does not yet support the `it` block parameter syntax. This is the first case where Prism's node design precedes that of the Parser gem.
When implementing https://github.com/whitequark/parser/issues/962, this node design will need to be taken into consideration.
https://github.com/ruby/prism/commit/c141e1420a
Diffstat (limited to 'lib/prism/translation/parser/compiler.rb')
-rw-r--r-- | lib/prism/translation/parser/compiler.rb | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/prism/translation/parser/compiler.rb b/lib/prism/translation/parser/compiler.rb index c145cfa52c..8453c9383a 100644 --- a/lib/prism/translation/parser/compiler.rb +++ b/lib/prism/translation/parser/compiler.rb @@ -1138,7 +1138,7 @@ module Prism # -> { it } # ^^^^^^^^^ def visit_it_parameters_node(node) - builder.args(nil, [], nil, false) + builder.itarg end # foo(bar: baz) |