mirror of
https://github.com/ruby/ruby.git
synced 2025-09-21 11:33:58 +02:00
parent
5d73c0f3df
commit
c0f162caab
3 changed files with 16 additions and 9 deletions
|
@ -100,9 +100,7 @@ module YARP
|
||||||
comment_end = comment.location.end_offset
|
comment_end = comment.location.end_offset
|
||||||
|
|
||||||
targets = []
|
targets = []
|
||||||
node.deconstruct_keys(nil).each do |key, value|
|
node.comment_targets.map do |value|
|
||||||
next if key == :location
|
|
||||||
|
|
||||||
case value
|
case value
|
||||||
when StatementsNode
|
when StatementsNode
|
||||||
targets.concat(value.body.map { |node| NodeTarget.new(node) })
|
targets.concat(value.body.map { |node| NodeTarget.new(node) })
|
||||||
|
@ -110,8 +108,6 @@ module YARP
|
||||||
targets << NodeTarget.new(value)
|
targets << NodeTarget.new(value)
|
||||||
when Location
|
when Location
|
||||||
targets << LocationTarget.new(value)
|
targets << LocationTarget.new(value)
|
||||||
when Array
|
|
||||||
targets.concat(value.map { |node| NodeTarget.new(node) }) if value.first.is_a?(Node)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -166,6 +162,8 @@ module YARP
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private_constant :Comments
|
||||||
|
|
||||||
# Attach the list of comments to their respective locations in the tree.
|
# Attach the list of comments to their respective locations in the tree.
|
||||||
def attach_comments!
|
def attach_comments!
|
||||||
Comments.new(self).attach!
|
Comments.new(self).attach!
|
||||||
|
|
|
@ -17,7 +17,7 @@ module YARP
|
||||||
# Note that the logic in this file should be kept in sync with the Java
|
# Note that the logic in this file should be kept in sync with the Java
|
||||||
# MarkNewlinesVisitor, since that visitor is responsible for marking the
|
# MarkNewlinesVisitor, since that visitor is responsible for marking the
|
||||||
# newlines for JRuby/TruffleRuby.
|
# newlines for JRuby/TruffleRuby.
|
||||||
class MarkNewlinesVisitor < Visitor
|
class Newlines < Visitor
|
||||||
def initialize(newline_marked)
|
def initialize(newline_marked)
|
||||||
@newline_marked = newline_marked
|
@newline_marked = newline_marked
|
||||||
end
|
end
|
||||||
|
@ -50,12 +50,11 @@ module YARP
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private_constant :MarkNewlinesVisitor
|
private_constant :Newlines
|
||||||
|
|
||||||
# Walk the tree and mark nodes that are on a new line.
|
# Walk the tree and mark nodes that are on a new line.
|
||||||
def mark_newlines!
|
def mark_newlines!
|
||||||
newline_marked = Array.new(1 + source.offsets.size, false)
|
value.accept(Newlines.new(Array.new(1 + source.offsets.size, false)))
|
||||||
value.accept(MarkNewlinesVisitor.new(newline_marked))
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -48,6 +48,16 @@ module YARP
|
||||||
}.compact.join(", ") %>]
|
}.compact.join(", ") %>]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# def comment_targets: () -> Array[Node | Location]
|
||||||
|
def comment_targets
|
||||||
|
[<%= node.fields.map { |field|
|
||||||
|
case field
|
||||||
|
when YARP::NodeField, YARP::LocationField then field.name
|
||||||
|
when YARP::OptionalNodeField, YARP::NodeListField, YARP::OptionalLocationField then "*#{field.name}"
|
||||||
|
end
|
||||||
|
}.compact.join(", ") %>]
|
||||||
|
end
|
||||||
|
|
||||||
# def copy: (**params) -> <%= node.name %>
|
# def copy: (**params) -> <%= node.name %>
|
||||||
def copy(**params)
|
def copy(**params)
|
||||||
<%= node.name %>.new(
|
<%= node.name %>.new(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue