From 3bdb0fecd103a5901a7ee1ab7ff6105a4e916fe5 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Tue, 5 Mar 2024 08:08:16 -0500 Subject: [ruby/prism] Implement case/in for ripper translation https://github.com/ruby/prism/commit/7f5a09f40e --- lib/prism/translation/ripper.rb | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/prism/translation/ripper.rb b/lib/prism/translation/ripper.rb index e3cd300446..0872ed9f9e 100644 --- a/lib/prism/translation/ripper.rb +++ b/lib/prism/translation/ripper.rb @@ -539,7 +539,14 @@ module Prism # 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 @@ -1124,7 +1131,19 @@ module Prism # 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 -- cgit v1.2.3