Skip to content

Commit 785de2c

Browse files
committed
Match parser for match_rest in pattern
1 parent 3227772 commit 785de2c

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

lib/prism/translation/parser/compiler.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ def visit_assoc_node(node)
146146
# { **foo }
147147
# ^^^^^
148148
def visit_assoc_splat_node(node)
149-
if node.value.nil? && forwarding.include?(:**)
149+
if in_pattern
150+
builder.match_rest(token(node.operator_loc), token(node.value&.location))
151+
elsif node.value.nil? && forwarding.include?(:**)
150152
builder.forwarded_kwrestarg(token(node.operator_loc))
151153
else
152154
builder.kwsplat(token(node.operator_loc), visit(node.value))

test/prism/ruby/parser_test.rb

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,9 @@ def ==(other)
4242

4343
module Prism
4444
class ParserTest < TestCase
45-
# These files are erroring because of the parser gem being wrong.
46-
skip_incorrect = [
47-
"embdoc_no_newline_at_end.txt"
48-
]
49-
5045
# These files are either failing to parse or failing to translate, so we'll
5146
# skip them for now.
52-
skip_all = skip_incorrect | [
47+
skip_all = [
5348
"dash_heredocs.txt",
5449
"dos_endings.txt",
5550
"heredocs_with_ignored_newlines.txt",
@@ -58,15 +53,12 @@ class ParserTest < TestCase
5853
"spanning_heredoc.txt",
5954
"spanning_heredoc_newlines.txt",
6055
"unescaping.txt",
61-
"seattlerb/backticks_interpolation_line.txt",
6256
"seattlerb/block_decomp_anon_splat_arg.txt",
6357
"seattlerb/block_decomp_arg_splat_arg.txt",
6458
"seattlerb/block_decomp_arg_splat.txt",
6559
"seattlerb/block_decomp_splat.txt",
6660
"seattlerb/block_paren_splat.txt",
6761
"seattlerb/bug190.txt",
68-
"seattlerb/case_in_hash_pat_rest_solo.txt",
69-
"seattlerb/case_in_hash_pat_rest.txt",
7062
"seattlerb/case_in.txt",
7163
"seattlerb/heredoc_nested.txt",
7264
"seattlerb/heredoc_squiggly_blank_line_plus_interpolation.txt",
@@ -78,8 +70,6 @@ class ParserTest < TestCase
7870
"seattlerb/masgn_double_paren.txt",
7971
"seattlerb/parse_line_heredoc_hardnewline.txt",
8072
"seattlerb/parse_pattern_044.txt",
81-
"seattlerb/parse_pattern_058_2.txt",
82-
"seattlerb/parse_pattern_058.txt",
8373
"seattlerb/pct_nl.txt",
8474
"seattlerb/pctW_lineno.txt",
8575
"seattlerb/regexp_esc_C_slash.txt",
@@ -91,7 +81,6 @@ class ParserTest < TestCase
9181
"unparser/corpus/literal/literal.txt",
9282
"unparser/corpus/literal/pattern.txt",
9383
"unparser/corpus/semantic/dstr.txt",
94-
"unparser/corpus/semantic/opasgn.txt",
9584
"whitequark/dedenting_interpolating_heredoc_fake_line_continuation.txt",
9685
"whitequark/masgn_nested.txt",
9786
"whitequark/newline_in_hash_argument.txt",
@@ -111,12 +100,14 @@ class ParserTest < TestCase
111100
# output expected by the parser gem, so we'll skip them for now.
112101
skip_tokens = [
113102
"comments.txt",
103+
"embdoc_no_newline_at_end.txt",
114104
"heredoc_with_comment.txt",
115105
"indented_file_end.txt",
116106
"methods.txt",
117107
"strings.txt",
118108
"tilde_heredocs.txt",
119109
"xstring_with_backslash.txt",
110+
"seattlerb/backticks_interpolation_line.txt",
120111
"seattlerb/bug169.txt",
121112
"seattlerb/class_comments.txt",
122113
"seattlerb/difficult4__leading_dots2.txt",
@@ -164,6 +155,7 @@ class ParserTest < TestCase
164155
"seattlerb/str_single_newline.txt",
165156
"seattlerb/symbol_empty.txt",
166157
"seattlerb/symbols_empty_space.txt",
158+
"unparser/corpus/semantic/opasgn.txt",
167159
"whitequark/args.txt",
168160
"whitequark/beginless_erange_after_newline.txt",
169161
"whitequark/beginless_irange_after_newline.txt",
@@ -183,15 +175,20 @@ class ParserTest < TestCase
183175
"whitequark/space_args_block.txt"
184176
]
185177

186-
Fixture.each(except: skip_all) do |fixture|
178+
Fixture.each do |fixture|
187179
define_method(fixture.test_name) do
188-
assert_equal_parses(fixture, compare_tokens: !skip_tokens.include?(fixture.path))
180+
assert_equal_parses(
181+
fixture,
182+
compare_asts: !skip_all.include?(fixture.path),
183+
compare_tokens: !skip_tokens.include?(fixture.path),
184+
compare_comments: fixture.path != "embdoc_no_newline_at_end.txt"
185+
)
189186
end
190187
end
191188

192189
private
193190

194-
def assert_equal_parses(fixture, compare_tokens: true)
191+
def assert_equal_parses(fixture, compare_asts: true, compare_tokens: true, compare_comments: true)
195192
buffer = Parser::Source::Buffer.new(fixture.path, 1)
196193
buffer.source = fixture.read
197194

@@ -209,9 +206,17 @@ def assert_equal_parses(fixture, compare_tokens: true)
209206
actual_ast, actual_comments, actual_tokens =
210207
ignore_warnings { Prism::Translation::Parser33.new.tokenize(buffer) }
211208

212-
assert_equal expected_ast, actual_ast, -> { assert_equal_asts_message(expected_ast, actual_ast) }
213-
assert_equal_tokens(expected_tokens, actual_tokens) if compare_tokens
214-
assert_equal_comments(expected_comments, actual_comments)
209+
if expected_ast == actual_ast
210+
if !compare_asts
211+
puts "#{fixture.path} is now passing"
212+
end
213+
214+
assert_equal expected_ast, actual_ast, -> { assert_equal_asts_message(expected_ast, actual_ast) }
215+
assert_equal_tokens(expected_tokens, actual_tokens) if compare_tokens
216+
assert_equal_comments(expected_comments, actual_comments) if compare_comments
217+
elsif compare_asts
218+
flunk "expected: #{expected_ast.inspect}\nactual: #{actual_ast.inspect}"
219+
end
215220
end
216221

217222
def assert_equal_asts_message(expected_ast, actual_ast)

0 commit comments

Comments
 (0)