From 6e5556dbdf5797f9597a68622bc8e2738904f9ee Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Mon, 30 Oct 2023 10:33:27 -0400 Subject: [PATCH] Share comment generation logic --- templates/java/org/prism/Nodes.java.erb | 4 ++-- templates/javascript/src/nodes.js.erb | 4 ++-- templates/lib/prism/node.rb.erb | 4 ++-- templates/rbi/prism.rbi.erb | 4 ++-- templates/sig/prism.rbs.erb | 4 ++-- templates/template.rb | 4 ++++ 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/templates/java/org/prism/Nodes.java.erb b/templates/java/org/prism/Nodes.java.erb index e4044909781..98bda2ab807 100644 --- a/templates/java/org/prism/Nodes.java.erb +++ b/templates/java/org/prism/Nodes.java.erb @@ -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 { diff --git a/templates/javascript/src/nodes.js.erb b/templates/javascript/src/nodes.js.erb index ec1d3ba8bd6..3a90b7e6144 100644 --- a/templates/javascript/src/nodes.js.erb +++ b/templates/javascript/src/nodes.js.erb @@ -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 -%> { diff --git a/templates/lib/prism/node.rb.erb b/templates/lib/prism/node.rb.erb index affd2875eaa..b7efe335233 100644 --- a/templates/lib/prism/node.rb.erb +++ b/templates/lib/prism/node.rb.erb @@ -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| -%> diff --git a/templates/rbi/prism.rbi.erb b/templates/rbi/prism.rbi.erb index d2329a87eb7..53f75f35074 100644 --- a/templates/rbi/prism.rbi.erb +++ b/templates/rbi/prism.rbi.erb @@ -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| -%> diff --git a/templates/sig/prism.rbs.erb b/templates/sig/prism.rbs.erb index 44879ed581b..0c0bc14c703 100644 --- a/templates/sig/prism.rbs.erb +++ b/templates/sig/prism.rbs.erb @@ -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| -%> diff --git a/templates/template.rb b/templates/template.rb index 46dbf88f4fd..abd0976c415 100755 --- a/templates/template.rb +++ b/templates/template.rb @@ -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