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
4 changes: 2 additions & 2 deletions lib/prism/translation/ruby_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1151,8 +1151,8 @@ def visit_keyword_rest_parameter_node(node)
def visit_lambda_node(node)
parameters =
case node.parameters
when nil, NumberedParametersNode
s(node, :args)
when nil, ItParametersNode, NumberedParametersNode
0
else
visit(node.parameters)
end
Expand Down
67 changes: 41 additions & 26 deletions snapshots/it.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,46 @@
@ ProgramNode (location: (1,0)-(3,3))
@ ProgramNode (location: (1,0)-(5,9))
├── flags: ∅
├── locals: []
└── statements:
@ StatementsNode (location: (1,0)-(3,3))
@ StatementsNode (location: (1,0)-(5,9))
├── flags: ∅
└── body: (length: 1)
└── @ CallNode (location: (1,0)-(3,3))
├── flags: newline, ignore_visibility
├── receiver: ∅
├── call_operator_loc: ∅
├── name: :x
├── message_loc: (1,0)-(1,1) = "x"
├── opening_loc: ∅
├── arguments: ∅
├── closing_loc: ∅
└── block:
@ BlockNode (location: (1,2)-(3,3))
└── body: (length: 2)
├── @ CallNode (location: (1,0)-(3,3))
│ ├── flags: newline, ignore_visibility
│ ├── receiver: ∅
│ ├── call_operator_loc: ∅
│ ├── name: :x
│ ├── message_loc: (1,0)-(1,1) = "x"
│ ├── opening_loc: ∅
│ ├── arguments: ∅
│ ├── closing_loc: ∅
│ └── block:
│ @ BlockNode (location: (1,2)-(3,3))
│ ├── flags: ∅
│ ├── locals: []
│ ├── parameters:
│ │ @ ItParametersNode (location: (1,2)-(3,3))
│ │ └── flags: ∅
│ ├── body:
│ │ @ StatementsNode (location: (2,2)-(2,4))
│ │ ├── flags: ∅
│ │ └── body: (length: 1)
│ │ └── @ ItLocalVariableReadNode (location: (2,2)-(2,4))
│ │ └── flags: newline
│ ├── opening_loc: (1,2)-(1,4) = "do"
│ └── closing_loc: (3,0)-(3,3) = "end"
└── @ LambdaNode (location: (5,0)-(5,9))
├── flags: newline
├── locals: []
├── operator_loc: (5,0)-(5,2) = "->"
├── opening_loc: (5,3)-(5,4) = "{"
├── closing_loc: (5,8)-(5,9) = "}"
├── parameters:
│ @ ItParametersNode (location: (5,0)-(5,9))
│ └── flags: ∅
└── body:
@ StatementsNode (location: (5,5)-(5,7))
├── flags: ∅
├── locals: []
├── parameters:
│ @ ItParametersNode (location: (1,2)-(3,3))
│ └── flags: ∅
├── body:
│ @ StatementsNode (location: (2,2)-(2,4))
│ ├── flags: ∅
│ └── body: (length: 1)
│ └── @ ItLocalVariableReadNode (location: (2,2)-(2,4))
│ └── flags: newline
├── opening_loc: (1,2)-(1,4) = "do"
└── closing_loc: (3,0)-(3,3) = "end"
└── body: (length: 1)
└── @ ItLocalVariableReadNode (location: (5,5)-(5,7))
└── flags: newline
2 changes: 2 additions & 0 deletions test/prism/fixtures/it.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
x do
it
end

-> { it }
6 changes: 5 additions & 1 deletion test/prism/ruby/parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,13 @@ def test_it_block_parameter_syntax
actual_ast = Prism::Translation::Parser34.new.tokenize(buffer)[0]

it_block_parameter_sexp = parse_sexp {
s(:begin,
s(:itblock,
s(:send, nil, :x), :it,
s(:lvar, :it))
s(:lvar, :it)),
s(:itblock,
s(:lambda), :it,
s(:lvar, :it)))
}

assert_equal(it_block_parameter_sexp, actual_ast.to_sexp)
Expand Down
27 changes: 8 additions & 19 deletions test/prism/ruby/ruby_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,22 @@
return
end

# We want to also compare lines and files to make sure we're setting them
# correctly.
Sexp.prepend(
Module.new do
def ==(other)
super && line == other.line && file == other.file # && line_max == other.line_max
end
end
)

module Prism
class RubyParserTest < TestCase
todos = [
"encoding_euc_jp.txt",
"newline_terminated.txt",
"regex_char_width.txt",
"seattlerb/bug169.txt",
"seattlerb/masgn_colon3.txt",
"seattlerb/messy_op_asgn_lineno.txt",
"seattlerb/op_asgn_primary_colon_const_command_call.txt",
"seattlerb/regexp_esc_C_slash.txt",
"seattlerb/str_lit_concat_bad_encodings.txt",
"strings.txt",
"unescaping.txt",
"unparser/corpus/literal/kwbegin.txt",
"unparser/corpus/literal/send.txt",
"whitequark/masgn_const.txt",
"whitequark/pattern_matching_constants.txt",
"whitequark/pattern_matching_implicit_array_match.txt",
"whitequark/pattern_matching_single_match.txt",
"whitequark/ruby_bug_12402.txt",
"whitequark/ruby_bug_14690.txt",
"whitequark/space_args_block.txt"
]

# https://github.com/seattlerb/ruby_parser/issues/344
Expand Down Expand Up @@ -105,10 +88,16 @@ def assert_ruby_parser(fixture, allowed_failure)
source = fixture.read
expected = ignore_warnings { ::RubyParser.new.parse(source, fixture.path) }
actual = Prism::Translation::RubyParser.new.parse(source, fixture.path)
on_failure = -> { message(expected, actual) }

if !allowed_failure
assert_equal(expected, actual, -> { message(expected, actual) })
elsif expected == actual
assert_equal(expected, actual, on_failure)

unless actual.nil?
assert_equal(expected.line, actual.line, on_failure)
assert_equal(expected.file, actual.file, on_failure)
end
elsif expected == actual && expected.line && actual.line && expected.file == actual.file
puts "#{name} now passes"
end
end
Expand Down
Loading