Skip to content

Commit 788cf7c

Browse files
committed
Implement regular expressions for ripper translation
1 parent 6285e31 commit 788cf7c

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

lib/prism/translation/ripper.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,7 @@ def visit_match_required_node(node)
13291329
# /(?<foo>foo)/ =~ bar
13301330
# ^^^^^^^^^^^^^^^^^^^^
13311331
def visit_match_write_node(node)
1332-
raise NoMethodError, __method__
1332+
visit(node.call)
13331333
end
13341334

13351335
# A node that is missing from the syntax tree. This is only used in the
@@ -1568,7 +1568,13 @@ def visit_redo_node(node)
15681568
# /foo/
15691569
# ^^^^^
15701570
def visit_regular_expression_node(node)
1571-
raise NoMethodError, __method__
1571+
bounds(node.content_loc)
1572+
content = on_tstring_content(node.unescaped)
1573+
1574+
bounds(node.closing_loc)
1575+
closing = on_regexp_end(node.closing)
1576+
1577+
on_regexp_literal(on_regexp_add(on_regexp_new, content), closing)
15721578
end
15731579

15741580
# def foo(bar:); end

test/prism/ripper_test.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ class RipperFixturesTest < RipperTestCase
307307
methods.txt
308308
modules.txt
309309
multi_write.txt
310-
newline_terminated.txt
311310
non_alphanumeric_methods.txt
312311
not.txt
313312
patterns.txt
@@ -355,9 +354,7 @@ class RipperFixturesTest < RipperTestCase
355354
seattlerb/bug_args_masgn2.txt
356355
seattlerb/bug_args_masgn_outer_parens__19.txt
357356
seattlerb/bug_call_arglist_parens.txt
358-
seattlerb/bug_case_when_regexp.txt
359357
seattlerb/bug_comma.txt
360-
seattlerb/bug_cond_pct.txt
361358
seattlerb/bug_hash_args_trailing_comma.txt
362359
seattlerb/bug_hash_interp_array.txt
363360
seattlerb/bug_masgn_right.txt
@@ -575,11 +572,8 @@ class RipperFixturesTest < RipperTestCase
575572
seattlerb/qwords_empty.txt
576573
seattlerb/read_escape_unicode_curlies.txt
577574
seattlerb/read_escape_unicode_h4.txt
578-
seattlerb/regexp.txt
579575
seattlerb/regexp_esc_C_slash.txt
580-
seattlerb/regexp_esc_u.txt
581576
seattlerb/regexp_escape_extended.txt
582-
seattlerb/regexp_unicode_curlies.txt
583577
seattlerb/required_kwarg_no_value.txt
584578
seattlerb/rescue_do_end_ensure_result.txt
585579
seattlerb/rescue_do_end_no_raise.txt
@@ -715,7 +709,6 @@ class RipperFixturesTest < RipperTestCase
715709
whitequark/bug_heredoc_do.txt
716710
whitequark/bug_interp_single.txt
717711
whitequark/bug_lambda_leakage.txt
718-
whitequark/bug_regex_verification.txt
719712
whitequark/bug_rescue_empty_else.txt
720713
whitequark/bug_while_not_parens_do.txt
721714
whitequark/case_cond_else.txt
@@ -799,7 +792,6 @@ class RipperFixturesTest < RipperTestCase
799792
whitequark/parser_bug_604.txt
800793
whitequark/parser_bug_640.txt
801794
whitequark/parser_bug_645.txt
802-
whitequark/parser_bug_830.txt
803795
whitequark/parser_drops_truncated_parts_of_squiggly_heredoc.txt
804796
whitequark/parser_slash_slash_n_escaping_in_literals.txt
805797
whitequark/pattern_matching__FILE__LINE_literals.txt
@@ -808,7 +800,6 @@ class RipperFixturesTest < RipperTestCase
808800
whitequark/pattern_matching_single_line_allowed_omission_of_parentheses.txt
809801
whitequark/procarg0.txt
810802
whitequark/regex_interp.txt
811-
whitequark/regex_plain.txt
812803
whitequark/resbody_var.txt
813804
whitequark/rescue_else.txt
814805
whitequark/rescue_else_ensure.txt

0 commit comments

Comments
 (0)