summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2024-06-04 14:50:18 -0400
committergit <svn-admin@ruby-lang.org>2024-06-04 20:28:54 +0000
commite440804d7ad42bf244c5a20e461cd6e7beed20f3 (patch)
tree543ee4c2fda82a7fb28cb37498fbecd336837565 /lib
parentc2d3573c63934047df1d455a71a4f4248070a638 (diff)
[ruby/prism] (parser) split up regexp content by lines
https://github.com/ruby/prism/commit/85b4a5f804
Diffstat (limited to 'lib')
-rw-r--r--lib/prism/translation/parser/compiler.rb13
1 files changed, 12 insertions, 1 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)])
)