From d815d68cbb420243d0f2e3fc866350761154dd82 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Tue, 5 Mar 2024 07:43:24 -0500 Subject: [PATCH] [ruby/prism] Implement regular expressions for ripper translation https://github.com/ruby/prism/commit/788cf7c528 --- lib/prism/translation/ripper.rb | 10 ++++++++-- test/prism/ripper_test.rb | 9 --------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/prism/translation/ripper.rb b/lib/prism/translation/ripper.rb index c839b904564f0b..fe44fae8369aa5 100644 --- a/lib/prism/translation/ripper.rb +++ b/lib/prism/translation/ripper.rb @@ -1329,7 +1329,7 @@ def visit_match_required_node(node) # /(?foo)/ =~ bar # ^^^^^^^^^^^^^^^^^^^^ def visit_match_write_node(node) - raise NoMethodError, __method__ + visit(node.call) end # A node that is missing from the syntax tree. This is only used in the @@ -1568,7 +1568,13 @@ def visit_redo_node(node) # /foo/ # ^^^^^ def visit_regular_expression_node(node) - raise NoMethodError, __method__ + bounds(node.content_loc) + content = on_tstring_content(node.unescaped) + + bounds(node.closing_loc) + closing = on_regexp_end(node.closing) + + on_regexp_literal(on_regexp_add(on_regexp_new, content), closing) end # def foo(bar:); end diff --git a/test/prism/ripper_test.rb b/test/prism/ripper_test.rb index 212d2777fd57c5..a1744cd7cbf8e9 100644 --- a/test/prism/ripper_test.rb +++ b/test/prism/ripper_test.rb @@ -307,7 +307,6 @@ class RipperFixturesTest < RipperTestCase methods.txt modules.txt multi_write.txt - newline_terminated.txt non_alphanumeric_methods.txt not.txt patterns.txt @@ -355,9 +354,7 @@ class RipperFixturesTest < RipperTestCase seattlerb/bug_args_masgn2.txt seattlerb/bug_args_masgn_outer_parens__19.txt seattlerb/bug_call_arglist_parens.txt - seattlerb/bug_case_when_regexp.txt seattlerb/bug_comma.txt - seattlerb/bug_cond_pct.txt seattlerb/bug_hash_args_trailing_comma.txt seattlerb/bug_hash_interp_array.txt seattlerb/bug_masgn_right.txt @@ -575,11 +572,8 @@ class RipperFixturesTest < RipperTestCase seattlerb/qwords_empty.txt seattlerb/read_escape_unicode_curlies.txt seattlerb/read_escape_unicode_h4.txt - seattlerb/regexp.txt seattlerb/regexp_esc_C_slash.txt - seattlerb/regexp_esc_u.txt seattlerb/regexp_escape_extended.txt - seattlerb/regexp_unicode_curlies.txt seattlerb/required_kwarg_no_value.txt seattlerb/rescue_do_end_ensure_result.txt seattlerb/rescue_do_end_no_raise.txt @@ -715,7 +709,6 @@ class RipperFixturesTest < RipperTestCase whitequark/bug_heredoc_do.txt whitequark/bug_interp_single.txt whitequark/bug_lambda_leakage.txt - whitequark/bug_regex_verification.txt whitequark/bug_rescue_empty_else.txt whitequark/bug_while_not_parens_do.txt whitequark/case_cond_else.txt @@ -799,7 +792,6 @@ class RipperFixturesTest < RipperTestCase whitequark/parser_bug_604.txt whitequark/parser_bug_640.txt whitequark/parser_bug_645.txt - whitequark/parser_bug_830.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 @@ -808,7 +800,6 @@ class RipperFixturesTest < RipperTestCase whitequark/pattern_matching_single_line_allowed_omission_of_parentheses.txt whitequark/procarg0.txt whitequark/regex_interp.txt - whitequark/regex_plain.txt whitequark/resbody_var.txt whitequark/rescue_else.txt whitequark/rescue_else_ensure.txt