Skip to content

Commit 675f9c3

Browse files
committed
Parser support for no block parameter syntax
1 parent e5fb0e1 commit 675f9c3

3 files changed

Lines changed: 19 additions & 5 deletions

File tree

bin/prism

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,17 +269,17 @@ module Prism
269269

270270
# bin/prism parser [source]
271271
def parser(argv)
272-
require "parser/ruby34"
272+
require "parser/current"
273273
source, filepath = read_source(argv)
274274

275275
buffer = Parser::Source::Buffer.new(filepath, 1)
276276
buffer.source = source
277277

278278
puts "Parser:"
279-
parser_parse(Parser::Ruby34.new, buffer)
279+
parser_parse(Parser::CurrentRuby.new, buffer)
280280

281281
puts "Prism:"
282-
parser_parse(Prism::Translation::Parser34.new, buffer)
282+
parser_parse(Prism::Translation::ParserCurrent.new, buffer)
283283
end
284284

285285
# bin/prism ripper [source]

lib/prism/translation/parser/builder.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ class Parser
77
# A builder that knows how to convert more modern Ruby syntax
88
# into whitequark/parser gem's syntax tree.
99
class Builder < ::Parser::Builders::Default
10-
# It represents the `it` block argument, which is not yet implemented in the Parser gem.
10+
# It represents the `it` block argument, which is not yet implemented in
11+
# the Parser gem.
1112
def itarg
1213
n(:itarg, [:it], nil)
1314
end
1415

15-
# The following three lines have been added to support the `it` block parameter syntax in the source code below.
16+
# The following three lines have been added to support the `it` block
17+
# parameter syntax in the source code below.
1618
#
1719
# if args.type == :itarg
1820
# block_type = :itblock
@@ -56,6 +58,12 @@ def block(method_call, begin_t, args, body, end_t)
5658
method_call.loc.with_expression(join_exprs(method_call, block)))
5759
end
5860
end
61+
62+
# def foo(&nil); end
63+
# ^^^^
64+
def blocknilarg(amper_t, nil_t)
65+
n0(:blocknilarg, arg_prefix_map(amper_t, nil_t))
66+
end
5967
end
6068
end
6169
end

lib/prism/translation/parser/compiler.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,12 @@ def visit_nil_node(node)
13901390
builder.nil(token(node.location))
13911391
end
13921392

1393+
# def foo(&nil); end
1394+
# ^^^^
1395+
def visit_no_block_parameter_node(node)
1396+
builder.blocknilarg(token(node.operator_loc), token(node.keyword_loc))
1397+
end
1398+
13931399
# def foo(**nil); end
13941400
# ^^^^^
13951401
def visit_no_keywords_parameter_node(node)

0 commit comments

Comments
 (0)