Skip to content

Commit ef9dca2

Browse files
committed
Implement find pattern for ripper translation
1 parent 7f5a09f commit ef9dca2

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

lib/prism/translation/ripper.rb

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,26 @@ def visit_false_node(node)
931931
# foo => [*, bar, *]
932932
# ^^^^^^^^^^^
933933
def visit_find_pattern_node(node)
934-
raise NoMethodError, __method__
934+
constant = visit(node.constant)
935+
left =
936+
if node.left.expression.nil?
937+
bounds(node.left.location)
938+
on_var_field(nil)
939+
else
940+
visit(node.left.expression)
941+
end
942+
943+
requireds = visit_all(node.requireds) if node.requireds.any?
944+
right =
945+
if node.right.expression.nil?
946+
bounds(node.right.location)
947+
on_var_field(nil)
948+
else
949+
visit(node.right.expression)
950+
end
951+
952+
bounds(node.location)
953+
on_fndptn(constant, left, requireds, right)
935954
end
936955

937956
# if foo .. bar; end

test/prism/ripper_test.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,6 @@ class RipperFixturesTest < RipperTestCase
371371
seattlerb/case_in.txt
372372
seattlerb/case_in_37.txt
373373
seattlerb/case_in_else.txt
374-
seattlerb/case_in_find.txt
375-
seattlerb/case_in_find_array.txt
376374
seattlerb/case_in_hash_pat.txt
377375
seattlerb/case_in_hash_pat_assign.txt
378376
seattlerb/case_in_hash_pat_paren_assign.txt
@@ -590,7 +588,6 @@ class RipperFixturesTest < RipperTestCase
590588
unparser/corpus/literal/rescue.txt
591589
unparser/corpus/literal/send.txt
592590
unparser/corpus/literal/since/27.txt
593-
unparser/corpus/literal/since/30.txt
594591
unparser/corpus/literal/since/31.txt
595592
unparser/corpus/literal/since/32.txt
596593
unparser/corpus/literal/super.txt

0 commit comments

Comments
 (0)