Skip to content

Commit

Permalink
Share comment generation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Oct 30, 2023
1 parent 04d6994 commit 6e5556d
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions templates/java/org/prism/Nodes.java.erb
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ public abstract class Nodes {
<%- nodes.each do |node| -%>

/**
<%- node.comment.each_line do |line| -%>
*<%= line.prepend(" ").rstrip %>
<%- node.each_comment_line do |line| -%>
*<%= line %>
<%- end -%>
*/
public static final class <%= node.name -%> extends Node {
Expand Down
4 changes: 2 additions & 2 deletions templates/javascript/src/nodes.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ const <%= flag.name %> = {
<%- nodes.each do |node| -%>
/**
<%- node.comment.each_line do |line| -%>
*<%= line.prepend(" ").rstrip %>
<%- node.each_comment_line do |line| -%>
*<%= line %>
<%- end -%>
*/
export class <%= node.name -%> {
Expand Down
4 changes: 2 additions & 2 deletions templates/lib/prism/node.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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| -%>
Expand Down
4 changes: 2 additions & 2 deletions templates/rbi/prism.rbi.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

module Prism
<%- 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| -%>
Expand Down
4 changes: 2 additions & 2 deletions templates/sig/prism.rbs.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Prism
<%- 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| -%>
Expand Down
4 changes: 4 additions & 0 deletions templates/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ def initialize(config)
@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
Expand Down

0 comments on commit 6e5556d

Please sign in to comment.