From 6e9cdf7f33add454aaebfbbe2b289ff09a52b559 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Mon, 16 Feb 2026 11:16:16 -0500 Subject: [PATCH] Parser support for no block parameter syntax --- bin/prism | 6 +++--- lib/prism/translation/parser/builder.rb | 12 ++++++++++-- lib/prism/translation/parser/compiler.rb | 6 ++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/bin/prism b/bin/prism index dbd0ddb174..b23baa9818 100755 --- a/bin/prism +++ b/bin/prism @@ -270,17 +270,17 @@ module Prism # bin/prism parser [source] def parser(argv) - require "parser/ruby34" + require "parser/current" source, filepath = read_source(argv) buffer = Parser::Source::Buffer.new(filepath, 1) buffer.source = source puts "Parser:" - parser_parse(Parser::Ruby34.new, buffer) + parser_parse(Parser::CurrentRuby.new, buffer) puts "Prism:" - parser_parse(Prism::Translation::Parser34.new, buffer) + parser_parse(Prism::Translation::ParserCurrent.new, buffer) end # bin/prism ripper [source] diff --git a/lib/prism/translation/parser/builder.rb b/lib/prism/translation/parser/builder.rb index 6b620c25bc..7fc3bba6b7 100644 --- a/lib/prism/translation/parser/builder.rb +++ b/lib/prism/translation/parser/builder.rb @@ -7,12 +7,14 @@ class Parser # A builder that knows how to convert more modern Ruby syntax # into whitequark/parser gem's syntax tree. class Builder < ::Parser::Builders::Default - # It represents the `it` block argument, which is not yet implemented in the Parser gem. + # It represents the `it` block argument, which is not yet implemented in + # the Parser gem. def itarg n(:itarg, [:it], nil) end - # The following three lines have been added to support the `it` block parameter syntax in the source code below. + # The following three lines have been added to support the `it` block + # parameter syntax in the source code below. # # if args.type == :itarg # block_type = :itblock @@ -56,6 +58,12 @@ def block(method_call, begin_t, args, body, end_t) method_call.loc.with_expression(join_exprs(method_call, block))) end end + + # def foo(&nil); end + # ^^^^ + def blocknilarg(amper_t, nil_t) + n0(:blocknilarg, arg_prefix_map(amper_t, nil_t)) + end end end end diff --git a/lib/prism/translation/parser/compiler.rb b/lib/prism/translation/parser/compiler.rb index 37951a1d40..21aa7796c3 100644 --- a/lib/prism/translation/parser/compiler.rb +++ b/lib/prism/translation/parser/compiler.rb @@ -1390,6 +1390,12 @@ def visit_nil_node(node) builder.nil(token(node.location)) end + # def foo(&nil); end + # ^^^^ + def visit_no_block_parameter_node(node) + builder.blocknilarg(token(node.operator_loc), token(node.keyword_loc)) + end + # def foo(**nil); end # ^^^^^ def visit_no_keywords_parameter_node(node)