Skip to content

Commit

Permalink
Implement case/in for ripper translation
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Mar 5, 2024
1 parent 5e47d8e commit 7f5a09f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
23 changes: 21 additions & 2 deletions lib/prism/translation/ripper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,14 @@ def visit_case_node(node)
# case foo; in bar; end
# ^^^^^^^^^^^^^^^^^^^^^
def visit_case_match_node(node)
raise NoMethodError, __method__
predicate = visit(node.predicate)
clauses =
node.conditions.reverse_each.inject(nil) do |consequent, condition|
on_in(*visit(condition), consequent)
end

bounds(node.location)
on_case(predicate, clauses)
end

# class Foo; end
Expand Down Expand Up @@ -1124,7 +1131,19 @@ def visit_implicit_rest_node(node)
# case foo; in bar; end
# ^^^^^^^^^^^^^^^^^^^^^
def visit_in_node(node)
raise NoMethodError, __method__
# This is a special case where we're not going to call on_in directly
# because we don't have access to the consequent. Instead, we'll return
# the component parts and let the parent node handle it.
pattern = visit(node.pattern)
statements =
if node.statements.nil?
bounds(node.location)
on_stmts_add(on_stmts_new, on_void_stmt)
else
visit(node.statements)
end

[pattern, statements]
end

# foo[bar] += baz
Expand Down
17 changes: 0 additions & 17 deletions test/prism/ripper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -369,18 +369,7 @@ class RipperFixturesTest < RipperTestCase
seattlerb/call_stabby_with_braces_block.txt
seattlerb/call_trailing_comma.txt
seattlerb/case_in.txt
seattlerb/case_in_31.txt
seattlerb/case_in_37.txt
seattlerb/case_in_42.txt
seattlerb/case_in_42_2.txt
seattlerb/case_in_47.txt
seattlerb/case_in_67.txt
seattlerb/case_in_86.txt
seattlerb/case_in_86_2.txt
seattlerb/case_in_array_pat_const.txt
seattlerb/case_in_array_pat_const2.txt
seattlerb/case_in_array_pat_paren_assign.txt
seattlerb/case_in_const.txt
seattlerb/case_in_else.txt
seattlerb/case_in_find.txt
seattlerb/case_in_find_array.txt
Expand All @@ -390,9 +379,6 @@ class RipperFixturesTest < RipperTestCase
seattlerb/case_in_hash_pat_paren_true.txt
seattlerb/case_in_hash_pat_rest.txt
seattlerb/case_in_hash_pat_rest_solo.txt
seattlerb/case_in_if_unless_post_mod.txt
seattlerb/case_in_multiple.txt
seattlerb/case_in_or.txt
seattlerb/class_comments.txt
seattlerb/defn_arg_forward_args.txt
seattlerb/defn_args_forward_args.txt
Expand Down Expand Up @@ -509,8 +495,6 @@ class RipperFixturesTest < RipperTestCase
seattlerb/parse_line_to_ary.txt
seattlerb/parse_opt_call_args_assocs_comma.txt
seattlerb/parse_opt_call_args_lit_comma.txt
seattlerb/parse_pattern_019.txt
seattlerb/parse_pattern_044.txt
seattlerb/parse_pattern_051.txt
seattlerb/parse_pattern_058.txt
seattlerb/parse_pattern_058_2.txt
Expand Down Expand Up @@ -730,7 +714,6 @@ class RipperFixturesTest < RipperTestCase
whitequark/parser_bug_645.txt
whitequark/parser_drops_truncated_parts_of_squiggly_heredoc.txt
whitequark/parser_slash_slash_n_escaping_in_literals.txt
whitequark/pattern_matching__FILE__LINE_literals.txt
whitequark/pattern_matching_blank_else.txt
whitequark/pattern_matching_else.txt
whitequark/pattern_matching_single_line_allowed_omission_of_parentheses.txt
Expand Down

0 comments on commit 7f5a09f

Please sign in to comment.