summaryrefslogtreecommitdiff
path: root/prism
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2023-10-30 14:00:44 -0400
committerKevin Newton <kddnewton@gmail.com>2023-11-01 13:10:29 -0400
commit0a460b23e0e8a4cced92e752b46c2170e83cec63 (patch)
treeccd89b9dd02c6bbc0b2e7ed490ed6794b22da8fb /prism
parentf12617ec9832ff8979cd86eb717fa9ee5820123e (diff)
[ruby/prism] Add comments on flags
https://github.com/ruby/prism/commit/3abd09c803
Diffstat (limited to 'prism')
-rw-r--r--prism/config.yml7
-rw-r--r--prism/templates/include/prism/ast.h.erb4
-rw-r--r--prism/templates/lib/prism/node.rb.erb1
-rwxr-xr-xprism/templates/template.rb3
4 files changed, 13 insertions, 2 deletions
diff --git a/prism/config.yml b/prism/config.yml
index 7fe14ca671..97e8804ad4 100644
--- a/prism/config.yml
+++ b/prism/config.yml
@@ -333,12 +333,14 @@ flags:
values:
- name: KEYWORD_SPLAT
comment: "if arguments contain keyword splat"
+ comment: Flags for arguments nodes.
- name: CallNodeFlags
values:
- name: SAFE_NAVIGATION
comment: "&. operator"
- name: VARIABLE_CALL
comment: "a call that could have been a local variable"
+ comment: Flags for call nodes.
- name: IntegerBaseFlags
values:
- name: BINARY
@@ -349,14 +351,17 @@ flags:
comment: "0d or no prefix"
- name: HEXADECIMAL
comment: "0x prefix"
+ comment: Flags for integer nodes that correspond to the base of the integer.
- name: LoopFlags
values:
- name: BEGIN_MODIFIER
comment: "a loop after a begin statement, so the body is executed first before the condition"
+ comment: Flags for while and until loop nodes.
- name: RangeFlags
values:
- name: EXCLUDE_END
comment: "... operator"
+ comment: Flags for range and flip-flop nodes.
- name: RegularExpressionFlags
values:
- name: IGNORE_CASE
@@ -375,10 +380,12 @@ flags:
comment: "s - forces the Windows-31J encoding"
- name: UTF_8
comment: "u - forces the UTF-8 encoding"
+ comment: Flags for regular expression and match last line nodes.
- name: StringFlags
values:
- name: FROZEN
comment: "frozen by virtue of a `frozen_string_literal` comment"
+ comment: Flags for string nodes.
nodes:
- name: AliasGlobalVariableNode
fields:
diff --git a/prism/templates/include/prism/ast.h.erb b/prism/templates/include/prism/ast.h.erb
index bdd31538a7..38c01d1f05 100644
--- a/prism/templates/include/prism/ast.h.erb
+++ b/prism/templates/include/prism/ast.h.erb
@@ -105,7 +105,9 @@ typedef struct pm_<%= node.human %> {
<%- end -%>
<%- flags.each do |flag| -%>
-// <%= flag.name %>
+/**
+ * <%= flag.comment %>
+ */
typedef enum pm_<%= flag.human %> {
<%- flag.values.each_with_index do |value, index| -%>
PM_<%= flag.human.upcase %>_<%= value.name %> = 1 << <%= index %>,
diff --git a/prism/templates/lib/prism/node.rb.erb b/prism/templates/lib/prism/node.rb.erb
index b7efe33523..23bf77dc06 100644
--- a/prism/templates/lib/prism/node.rb.erb
+++ b/prism/templates/lib/prism/node.rb.erb
@@ -234,6 +234,7 @@ module Prism
<%- end -%>
<%- flags.each_with_index do |flag, flag_index| -%>
+ # <%= flag.comment %>
module <%= flag.name %>
<%- flag.values.each_with_index do |value, index| -%>
# <%= value.comment %>
diff --git a/prism/templates/template.rb b/prism/templates/template.rb
index abd0976c41..0d2f324456 100755
--- a/prism/templates/template.rb
+++ b/prism/templates/template.rb
@@ -321,12 +321,13 @@ module Prism
end
end
- attr_reader :name, :human, :values
+ attr_reader :name, :human, :values, :comment
def initialize(config)
@name = config.fetch("name")
@human = @name.gsub(/(?<=.)[A-Z]/, "_\\0").downcase
@values = config.fetch("values").map { |flag| Flag.new(flag) }
+ @comment = config.fetch("comment")
end
end