diff options
| author | Kevin Newton <kddnewton@gmail.com> | 2024-06-04 14:50:18 -0400 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2024-06-04 20:28:54 +0000 |
| commit | e440804d7ad42bf244c5a20e461cd6e7beed20f3 (patch) | |
| tree | 543ee4c2fda82a7fb28cb37498fbecd336837565 | |
| parent | c2d3573c63934047df1d455a71a4f4248070a638 (diff) | |
[ruby/prism] (parser) split up regexp content by lines
https://github.com/ruby/prism/commit/85b4a5f804
| -rw-r--r-- | lib/prism/translation/parser/compiler.rb | 13 | ||||
| -rw-r--r-- | test/prism/ruby/parser_test.rb | 2 |
2 files changed, 13 insertions, 2 deletions
diff --git a/lib/prism/translation/parser/compiler.rb b/lib/prism/translation/parser/compiler.rb index 1d93375c29..c6205e542d 100644 --- a/lib/prism/translation/parser/compiler.rb +++ b/lib/prism/translation/parser/compiler.rb @@ -1507,9 +1507,20 @@ module Prism # /foo/ # ^^^^^ def visit_regular_expression_node(node) + content = node.content + parts = + if content.include?("\n") + offset = node.content_loc.start_offset + content.lines.map do |line| + builder.string_internal([line, srange_offsets(offset, offset += line.bytesize)]) + end + else + [builder.string_internal(token(node.content_loc))] + end + builder.regexp_compose( token(node.opening_loc), - [builder.string_internal(token(node.content_loc))], + parts, [node.closing[0], srange_offsets(node.closing_loc.start_offset, node.closing_loc.start_offset + 1)], builder.regexp_options([node.closing[1..], srange_offsets(node.closing_loc.start_offset + 1, node.closing_loc.end_offset)]) ) diff --git a/test/prism/ruby/parser_test.rb b/test/prism/ruby/parser_test.rb index d3538f5cfd..8ca3272d7e 100644 --- a/test/prism/ruby/parser_test.rb +++ b/test/prism/ruby/parser_test.rb @@ -69,7 +69,6 @@ module Prism "seattlerb/parse_line_heredoc_hardnewline.txt", "seattlerb/pctW_lineno.txt", "seattlerb/regexp_esc_C_slash.txt", - "seattlerb/TestRubyParserShared.txt", "unparser/corpus/literal/literal.txt", "unparser/corpus/semantic/dstr.txt", "whitequark/dedenting_interpolating_heredoc_fake_line_continuation.txt", @@ -146,6 +145,7 @@ module Prism "seattlerb/str_single_newline.txt", "seattlerb/symbol_empty.txt", "seattlerb/symbols_empty_space.txt", + "seattlerb/TestRubyParserShared.txt", "unparser/corpus/literal/assignment.txt", "unparser/corpus/literal/dstr.txt", "unparser/corpus/semantic/opasgn.txt", |
