Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3596,7 +3596,7 @@ nodes:
fields:
- name: opening_loc
type: location
- name: content_loc
- name: value_loc
type: location
- name: closing_loc
type: location
Expand Down Expand Up @@ -4281,7 +4281,7 @@ nodes:
fields:
- name: opening_loc
type: location
- name: content_loc
- name: value_loc
type: location
- name: closing_loc
type: location
Expand Down Expand Up @@ -4503,7 +4503,7 @@ nodes:
fields:
- name: opening_loc
type: location?
- name: content_loc
- name: value_loc
type: location
- name: closing_loc
type: location?
Expand Down Expand Up @@ -4721,7 +4721,7 @@ nodes:
fields:
- name: opening_loc
type: location
- name: content_loc
- name: value_loc
type: location
- name: closing_loc
type: location
Expand Down
52 changes: 50 additions & 2 deletions lib/prism/node_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def to_interpolated
location,
frozen? ? InterpolatedStringNodeFlags::FROZEN : 0,
opening_loc,
[copy(location: content_loc, opening_loc: nil, closing_loc: nil)],
[copy(location: value_loc, opening_loc: nil, closing_loc: nil)],
closing_loc
)
end
Expand All @@ -152,7 +152,7 @@ def to_interpolated
location,
flags,
opening_loc,
[StringNode.new(source, node_id, content_loc, 0, nil, content_loc, nil, unescaped)],
[StringNode.new(source, node_id, value_loc, 0, nil, value_loc, nil, unescaped)],
closing_loc
)
end
Expand Down Expand Up @@ -488,5 +488,53 @@ def closing_loc # :nodoc
end_keyword_loc
end
end

class MatchLastLineNode < Node
#: () -> String
def content # :nodoc
value
end

#: () -> Location
def content_loc # :nodoc
value_loc
end
end

class RegularExpressionNode < Node
#: () -> String
def content # :nodoc
value
end

#: () -> Location
def content_loc # :nodoc
value_loc
end
end

class StringNode < Node
#: () -> String
def content # :nodoc
value
end

#: () -> Location
def content_loc # :nodoc
value_loc
end
end

class XStringNode < Node
#: () -> String
def content # :nodoc
value
end

#: () -> Location
def content_loc # :nodoc
value_loc
end
end
# :startdoc:
end
36 changes: 18 additions & 18 deletions lib/prism/translation/parser/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ def visit_array_node(node)
if node.opening&.start_with?("%w", "%W", "%i", "%I")
elements = node.elements.flat_map do |element|
if element.is_a?(StringNode)
if element.content.include?("\n")
string_nodes_from_line_continuations(element.unescaped, element.content, element.content_loc.start_offset, node.opening)
if element.value.include?("\n")
string_nodes_from_line_continuations(element.unescaped, element.value, element.value_loc.start_offset, node.opening)
else
[builder.string_internal([element.unescaped, srange(element.content_loc)])]
[builder.string_internal([element.unescaped, srange(element.value_loc)])]
end
elsif element.is_a?(InterpolatedStringNode)
builder.string_compose(
Expand Down Expand Up @@ -1564,12 +1564,12 @@ def visit_redo_node(node)
# ^^^^^
def visit_regular_expression_node(node)
parts =
if node.content == ""
if node.value == ""
[]
elsif node.content.include?("\n")
string_nodes_from_line_continuations(node.unescaped, node.content, node.content_loc.start_offset, node.opening)
elsif node.value.include?("\n")
string_nodes_from_line_continuations(node.unescaped, node.value, node.value_loc.start_offset, node.opening)
else
[builder.string_internal([node.unescaped, srange(node.content_loc)])]
[builder.string_internal([node.unescaped, srange(node.value_loc)])]
end

builder.regexp_compose(
Expand Down Expand Up @@ -1727,10 +1727,10 @@ def visit_string_node(node)
builder.string_compose(token(node.opening_loc), [], token(node.closing_loc))
else
parts =
if node.content.include?("\n")
string_nodes_from_line_continuations(node.unescaped, node.content, node.content_loc.start_offset, node.opening)
if node.value.include?("\n")
string_nodes_from_line_continuations(node.unescaped, node.value, node.value_loc.start_offset, node.opening)
else
[builder.string_internal([node.unescaped, srange(node.content_loc)])]
[builder.string_internal([node.unescaped, srange(node.value_loc)])]
end

builder.string_compose(
Expand Down Expand Up @@ -1914,12 +1914,12 @@ def visit_x_string_node(node)
end

parts =
if node.content == ""
if node.value == ""
[]
elsif node.content.include?("\n")
string_nodes_from_line_continuations(node.unescaped, node.content, node.content_loc.start_offset, node.opening)
elsif node.value.include?("\n")
string_nodes_from_line_continuations(node.unescaped, node.value, node.value_loc.start_offset, node.opening)
else
[builder.string_internal([node.unescaped, srange(node.content_loc)])]
[builder.string_internal([node.unescaped, srange(node.value_loc)])]
end

builder.xstring_compose(
Expand Down Expand Up @@ -2073,8 +2073,8 @@ def visit_heredoc(node)

node.parts.each do |part|
pushing =
if part.is_a?(StringNode) && part.content.include?("\n")
string_nodes_from_line_continuations(part.unescaped, part.content, part.location.start_offset, node.opening)
if part.is_a?(StringNode) && part.value.include?("\n")
string_nodes_from_line_continuations(part.unescaped, part.value, part.location.start_offset, node.opening)
else
[visit(part)]
end
Expand Down Expand Up @@ -2129,8 +2129,8 @@ def within_pattern
# parser gem creates individual string nodes for each line the content is part of.
def string_nodes_from_interpolation(node, opening)
node.parts.flat_map do |part|
if part.type == :string_node && part.content.include?("\n") && part.opening_loc.nil?
string_nodes_from_line_continuations(part.unescaped, part.content, part.content_loc.start_offset, opening)
if part.type == :string_node && part.value.include?("\n") && part.opening_loc.nil?
string_nodes_from_line_continuations(part.unescaped, part.value, part.value_loc.start_offset, opening)
else
visit(part)
end
Expand Down
46 changes: 23 additions & 23 deletions lib/prism/translation/ripper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ def visit_array_node(node)
visit_words_sep(opening_loc, previous, element)

bounds(element.location)
elements = on_qwords_add(elements, on_tstring_content(element.content))
elements = on_qwords_add(elements, on_tstring_content(element.value))

previous = element
end
Expand Down Expand Up @@ -814,13 +814,13 @@ def visit_array_node(node)
on_words_add(
elements,
if element.is_a?(StringNode)
on_word_add(on_word_new, on_tstring_content(element.content))
on_word_add(on_word_new, on_tstring_content(element.value))
else
element.parts.inject(on_word_new) do |word, part|
word_part =
if part.is_a?(StringNode)
bounds(part.location)
on_tstring_content(part.content)
on_tstring_content(part.value)
else
visit(part)
end
Expand Down Expand Up @@ -859,7 +859,7 @@ def visit_array_node(node)
word_part =
if part.is_a?(StringNode)
bounds(part.location)
on_tstring_content(part.content)
on_tstring_content(part.value)
else
visit(part)
end
Expand Down Expand Up @@ -2665,8 +2665,8 @@ def visit_interpolated_match_last_line_node(node)

bounds(node.parts.first.location)
parts =
node.parts.inject(on_regexp_new) do |content, part|
on_regexp_add(content, visit_string_content(part))
node.parts.inject(on_regexp_new) do |value, part|
on_regexp_add(value, visit_string_content(part))
end

bounds(node.closing_loc)
Expand Down Expand Up @@ -2765,8 +2765,8 @@ def visit_interpolated_x_string_node(node)
# Visit an individual part of a string-like node.
private def visit_string_content(part)
if part.is_a?(StringNode)
bounds(part.content_loc)
on_tstring_content(part.content)
bounds(part.value_loc)
on_tstring_content(part.value)
else
visit(part)
end
Expand Down Expand Up @@ -2971,8 +2971,8 @@ def visit_match_last_line_node(node)
bounds(node.opening_loc)
on_regexp_beg(node.opening)

bounds(node.content_loc)
tstring_content = on_tstring_content(node.content)
bounds(node.value_loc)
tstring_content = on_tstring_content(node.value)

bounds(node.closing_loc)
closing = on_regexp_end(node.closing)
Expand Down Expand Up @@ -3411,14 +3411,14 @@ def visit_regular_expression_node(node)
bounds(node.opening_loc)
on_regexp_beg(node.opening)

if node.content.empty?
if node.value.empty?
bounds(node.closing_loc)
closing = on_regexp_end(node.closing)

on_regexp_literal(on_regexp_new, closing)
else
bounds(node.content_loc)
tstring_content = on_tstring_content(node.content)
bounds(node.value_loc)
tstring_content = on_tstring_content(node.value)

bounds(node.closing_loc)
closing = on_regexp_end(node.closing)
Expand Down Expand Up @@ -3648,20 +3648,20 @@ def visit_statements_node(node)
# ^^^^^
def visit_string_node(node)
with_string_bounds(node) do
if (content = node.content).empty?
if (value = node.value).empty?
bounds(node.location)
on_string_literal(on_string_content)
elsif (opening = node.opening) == "?"
bounds(node.location)
on_CHAR("?#{node.content}")
on_CHAR("?#{value}")
elsif opening.start_with?("<<~")
heredoc = visit_heredoc_string_node(node.to_interpolated)

bounds(node.location)
on_string_literal(heredoc)
else
bounds(node.content_loc)
tstring_content = on_tstring_content(content)
bounds(node.value_loc)
tstring_content = on_tstring_content(value)

bounds(node.location)
on_string_literal(on_string_add(on_string_content, tstring_content))
Expand Down Expand Up @@ -3720,10 +3720,10 @@ def visit_string_node(node)

parts.each do |part|
if part.is_a?(StringNode)
if dedent_next && !(content = part.content).chomp.empty?
if dedent_next && !(value = part.value).chomp.empty?
common_whitespace = [
common_whitespace || Float::INFINITY,
content[/\A\s*/].each_char.inject(0) do |part_whitespace, char|
value[/\A\s*/].each_char.inject(0) do |part_whitespace, char|
char == "\t" ? ((part_whitespace / 8 + 1) * 8) : (part_whitespace + 1)
end
].min
Expand Down Expand Up @@ -3758,7 +3758,7 @@ def visit_string_node(node)
else
unless string.empty?
bounds(string[0].location)
result = yield result, on_tstring_content(string.map(&:content).join)
result = yield result, on_tstring_content(string.map(&:value).join)
string = []
end

Expand All @@ -3768,7 +3768,7 @@ def visit_string_node(node)

unless string.empty?
bounds(string[0].location)
result = yield result, on_tstring_content(string.map(&:content).join)
result = yield result, on_tstring_content(string.map(&:value).join)
end

result
Expand Down Expand Up @@ -4037,8 +4037,8 @@ def visit_x_string_node(node)
bounds(node.location)
on_xstring_literal(heredoc)
else
bounds(node.content_loc)
content = on_tstring_content(node.content)
bounds(node.value_loc)
content = on_tstring_content(node.value)

bounds(node.location)
on_xstring_literal(on_xstring_add(on_xstring_new, content))
Expand Down
4 changes: 2 additions & 2 deletions lib/prism/translation/ruby_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1531,8 +1531,8 @@ def visit_x_string_node(node)
result = s(node, :xstr, node.unescaped)

if node.heredoc?
result.line = node.content_loc.start_line
result.line_max = node.content_loc.end_line
result.line = node.value_loc.start_line
result.line_max = node.value_loc.end_line
end

result
Expand Down
16 changes: 8 additions & 8 deletions rbi/generated/prism/dsl.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading