[ruby/prism] Share comment generation logic

https://github.com/ruby/prism/commit/6e5556dbdf
This commit is contained in:
Kevin Newton 2023-10-30 10:33:27 -04:00 committed by git
parent 322755a007
commit b0a2373e14
2 changed files with 6 additions and 2 deletions

View File

@ -32,8 +32,8 @@ module Prism
end
<%- nodes.each do |node| -%>
<%- node.comment.each_line do |line| -%>
#<%= line.prepend(" ").rstrip %>
<%- node.each_comment_line do |line| -%>
#<%= line %>
<%- end -%>
class <%= node.name -%> < Node
<%- node.fields.each do |field| -%>

View File

@ -255,6 +255,10 @@ module Prism
@comment = config.fetch("comment")
end
def each_comment_line
comment.each_line { |line| yield line.prepend(" ").rstrip }
end
def semantic_fields
@semantic_fields ||= @fields.select(&:semantic_field?)
end