diff options
| author | Benoit Daloze <eregontp@gmail.com> | 2024-01-03 18:34:31 +0100 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2024-01-03 20:00:18 +0000 |
| commit | 7304d56236347eec1ce20cbdd0b44842d4cb7c2b (patch) | |
| tree | 3e6dbd5009f57aa01087ae0c73a2029d10279183 | |
| parent | c7ce2f537f96ab2cf2f5fc2982d6147866ff5340 (diff) | |
[ruby/prism] Include field comments in Java source
https://github.com/ruby/prism/commit/4a9389f304
| -rw-r--r-- | prism/templates/include/prism/ast.h.erb | 8 | ||||
| -rw-r--r-- | prism/templates/lib/prism/node.rb.erb | 4 | ||||
| -rwxr-xr-x | prism/templates/template.rb | 4 |
3 files changed, 14 insertions, 2 deletions
diff --git a/prism/templates/include/prism/ast.h.erb b/prism/templates/include/prism/ast.h.erb index 3f71b923b7..d0d935c9dc 100644 --- a/prism/templates/include/prism/ast.h.erb +++ b/prism/templates/include/prism/ast.h.erb @@ -166,7 +166,13 @@ typedef struct pm_<%= node.human %> { <%- node.fields.grep_v(Prism::FlagsField).each do |field| -%> /** - * <%= node.name %>#<%= field.name %><%= "\n *\n * " + field.comment.split("\n").join("\n * ") if field.comment %> + * <%= node.name %>#<%= field.name %> + <%- if field.comment -%> + * + <%- field.each_comment_line do |line| -%> + *<%= line %> + <%- end -%> + <%- end -%> */ <%= case field when Prism::NodeField, Prism::OptionalNodeField then "struct #{field.c_type} *#{field.name}" diff --git a/prism/templates/lib/prism/node.rb.erb b/prism/templates/lib/prism/node.rb.erb index 54e48ffccb..4a10dfcecf 100644 --- a/prism/templates/lib/prism/node.rb.erb +++ b/prism/templates/lib/prism/node.rb.erb @@ -47,7 +47,9 @@ module Prism <%- if field.comment.nil? -%> # <%= "private " if field.is_a?(Prism::FlagsField) %>attr_reader <%= field.name %>: <%= field.rbs_class %> <%- else -%> - # <%= field.comment.split("\n").join("\n # ") %> + <%- field.each_comment_line do |line| -%> + #<%= line %> + <%- end -%> <%- end -%> <%= "private " if field.is_a?(Prism::FlagsField) %>attr_reader :<%= field.name %> diff --git a/prism/templates/template.rb b/prism/templates/template.rb index 01d0711148..4576191701 100755 --- a/prism/templates/template.rb +++ b/prism/templates/template.rb @@ -21,6 +21,10 @@ module Prism @options = options end + def each_comment_line + comment.each_line { |line| yield line.prepend(" ").rstrip } if comment + end + def semantic_field? true end |
