Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bin/prism
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
12 changes: 10 additions & 2 deletions lib/prism/translation/parser/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions lib/prism/translation/parser/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down