jruby-prism-parser 0.24.0-java → 1.4.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/BSDmakefile +58 -0
  3. data/CHANGELOG.md +269 -1
  4. data/CONTRIBUTING.md +0 -4
  5. data/Makefile +25 -18
  6. data/README.md +57 -6
  7. data/config.yml +1724 -140
  8. data/docs/build_system.md +39 -11
  9. data/docs/configuration.md +4 -0
  10. data/docs/cruby_compilation.md +1 -1
  11. data/docs/fuzzing.md +1 -1
  12. data/docs/parser_translation.md +14 -9
  13. data/docs/parsing_rules.md +4 -1
  14. data/docs/releasing.md +8 -10
  15. data/docs/relocation.md +34 -0
  16. data/docs/ripper_translation.md +72 -0
  17. data/docs/ruby_api.md +2 -1
  18. data/docs/serialization.md +29 -5
  19. data/ext/prism/api_node.c +3395 -1999
  20. data/ext/prism/api_pack.c +9 -0
  21. data/ext/prism/extconf.rb +55 -34
  22. data/ext/prism/extension.c +597 -346
  23. data/ext/prism/extension.h +6 -5
  24. data/include/prism/ast.h +2612 -455
  25. data/include/prism/defines.h +160 -2
  26. data/include/prism/diagnostic.h +188 -76
  27. data/include/prism/encoding.h +22 -4
  28. data/include/prism/node.h +89 -17
  29. data/include/prism/options.h +224 -12
  30. data/include/prism/pack.h +11 -0
  31. data/include/prism/parser.h +267 -66
  32. data/include/prism/prettyprint.h +8 -0
  33. data/include/prism/regexp.h +18 -8
  34. data/include/prism/static_literals.h +121 -0
  35. data/include/prism/util/pm_buffer.h +75 -2
  36. data/include/prism/util/pm_char.h +1 -2
  37. data/include/prism/util/pm_constant_pool.h +18 -9
  38. data/include/prism/util/pm_integer.h +126 -0
  39. data/include/prism/util/pm_list.h +1 -1
  40. data/include/prism/util/pm_newline_list.h +19 -0
  41. data/include/prism/util/pm_string.h +48 -8
  42. data/include/prism/version.h +3 -3
  43. data/include/prism.h +99 -5
  44. data/jruby-prism.jar +0 -0
  45. data/lib/prism/compiler.rb +11 -1
  46. data/lib/prism/desugar_compiler.rb +113 -74
  47. data/lib/prism/dispatcher.rb +45 -1
  48. data/lib/prism/dot_visitor.rb +201 -77
  49. data/lib/prism/dsl.rb +673 -461
  50. data/lib/prism/ffi.rb +233 -45
  51. data/lib/prism/inspect_visitor.rb +2389 -0
  52. data/lib/prism/lex_compat.rb +35 -16
  53. data/lib/prism/mutation_compiler.rb +24 -8
  54. data/lib/prism/node.rb +7731 -8460
  55. data/lib/prism/node_ext.rb +328 -32
  56. data/lib/prism/pack.rb +4 -0
  57. data/lib/prism/parse_result/comments.rb +34 -24
  58. data/lib/prism/parse_result/errors.rb +65 -0
  59. data/lib/prism/parse_result/newlines.rb +102 -12
  60. data/lib/prism/parse_result.rb +448 -44
  61. data/lib/prism/pattern.rb +28 -10
  62. data/lib/prism/polyfill/append_as_bytes.rb +15 -0
  63. data/lib/prism/polyfill/byteindex.rb +13 -0
  64. data/lib/prism/polyfill/unpack1.rb +14 -0
  65. data/lib/prism/reflection.rb +413 -0
  66. data/lib/prism/relocation.rb +504 -0
  67. data/lib/prism/serialize.rb +1940 -1198
  68. data/lib/prism/string_query.rb +30 -0
  69. data/lib/prism/translation/parser/builder.rb +61 -0
  70. data/lib/prism/translation/parser/compiler.rb +569 -195
  71. data/lib/prism/translation/parser/lexer.rb +516 -39
  72. data/lib/prism/translation/parser.rb +177 -12
  73. data/lib/prism/translation/parser33.rb +1 -1
  74. data/lib/prism/translation/parser34.rb +1 -1
  75. data/lib/prism/translation/parser35.rb +12 -0
  76. data/lib/prism/translation/ripper/sexp.rb +125 -0
  77. data/lib/prism/translation/ripper/shim.rb +5 -0
  78. data/lib/prism/translation/ripper.rb +3224 -462
  79. data/lib/prism/translation/ruby_parser.rb +194 -69
  80. data/lib/prism/translation.rb +4 -1
  81. data/lib/prism/version.rb +1 -1
  82. data/lib/prism/visitor.rb +13 -0
  83. data/lib/prism.rb +17 -27
  84. data/prism.gemspec +57 -17
  85. data/rbi/prism/compiler.rbi +12 -0
  86. data/rbi/prism/dsl.rbi +524 -0
  87. data/rbi/prism/inspect_visitor.rbi +12 -0
  88. data/rbi/prism/node.rbi +8722 -0
  89. data/rbi/prism/node_ext.rbi +107 -0
  90. data/rbi/prism/parse_result.rbi +404 -0
  91. data/rbi/prism/reflection.rbi +58 -0
  92. data/rbi/prism/string_query.rbi +12 -0
  93. data/rbi/prism/translation/parser.rbi +11 -0
  94. data/rbi/prism/translation/parser33.rbi +6 -0
  95. data/rbi/prism/translation/parser34.rbi +6 -0
  96. data/rbi/prism/translation/parser35.rbi +6 -0
  97. data/rbi/prism/translation/ripper.rbi +15 -0
  98. data/rbi/prism/visitor.rbi +473 -0
  99. data/rbi/prism.rbi +44 -7745
  100. data/sig/prism/compiler.rbs +9 -0
  101. data/sig/prism/dispatcher.rbs +16 -0
  102. data/sig/prism/dot_visitor.rbs +6 -0
  103. data/sig/prism/dsl.rbs +351 -0
  104. data/sig/prism/inspect_visitor.rbs +22 -0
  105. data/sig/prism/lex_compat.rbs +10 -0
  106. data/sig/prism/mutation_compiler.rbs +159 -0
  107. data/sig/prism/node.rbs +3614 -0
  108. data/sig/prism/node_ext.rbs +82 -0
  109. data/sig/prism/pack.rbs +43 -0
  110. data/sig/prism/parse_result.rbs +192 -0
  111. data/sig/prism/pattern.rbs +13 -0
  112. data/sig/prism/reflection.rbs +50 -0
  113. data/sig/prism/relocation.rbs +185 -0
  114. data/sig/prism/serialize.rbs +8 -0
  115. data/sig/prism/string_query.rbs +11 -0
  116. data/sig/prism/visitor.rbs +169 -0
  117. data/sig/prism.rbs +248 -4767
  118. data/src/diagnostic.c +672 -230
  119. data/src/encoding.c +211 -108
  120. data/src/node.c +7541 -1653
  121. data/src/options.c +135 -20
  122. data/src/pack.c +33 -17
  123. data/src/prettyprint.c +1543 -1485
  124. data/src/prism.c +7813 -3050
  125. data/src/regexp.c +225 -73
  126. data/src/serialize.c +101 -77
  127. data/src/static_literals.c +617 -0
  128. data/src/token_type.c +14 -13
  129. data/src/util/pm_buffer.c +187 -20
  130. data/src/util/pm_char.c +5 -5
  131. data/src/util/pm_constant_pool.c +39 -19
  132. data/src/util/pm_integer.c +670 -0
  133. data/src/util/pm_list.c +1 -1
  134. data/src/util/pm_newline_list.c +43 -5
  135. data/src/util/pm_string.c +213 -33
  136. data/src/util/pm_strncasecmp.c +13 -1
  137. data/src/util/pm_strpbrk.c +32 -6
  138. metadata +55 -19
  139. data/docs/ripper.md +0 -36
  140. data/include/prism/util/pm_state_stack.h +0 -42
  141. data/include/prism/util/pm_string_list.h +0 -44
  142. data/lib/prism/debug.rb +0 -206
  143. data/lib/prism/node_inspector.rb +0 -68
  144. data/lib/prism/translation/parser/rubocop.rb +0 -45
  145. data/rbi/prism_static.rbi +0 -207
  146. data/sig/prism_static.rbs +0 -201
  147. data/src/util/pm_state_stack.c +0 -25
  148. data/src/util/pm_string_list.c +0 -28
data/lib/prism/pattern.rb CHANGED
@@ -69,7 +69,14 @@ module Prism
69
69
  # nodes.
70
70
  def compile
71
71
  result = Prism.parse("case nil\nin #{query}\nend")
72
- compile_node(result.value.statements.body.last.conditions.last.pattern)
72
+
73
+ case_match_node = result.value.statements.body.last
74
+ raise CompilationError, case_match_node.inspect unless case_match_node.is_a?(CaseMatchNode)
75
+
76
+ in_node = case_match_node.conditions.last
77
+ raise CompilationError, in_node.inspect unless in_node.is_a?(InNode)
78
+
79
+ compile_node(in_node.pattern)
73
80
  end
74
81
 
75
82
  # Scan the given node and all of its children for nodes that match the
@@ -77,13 +84,13 @@ module Prism
77
84
  # matches the pattern. If no block is given, an enumerator will be returned
78
85
  # that will yield each node that matches the pattern.
79
86
  def scan(root)
80
- return to_enum(__method__, root) unless block_given?
87
+ return to_enum(:scan, root) unless block_given?
81
88
 
82
89
  @compiled ||= compile
83
90
  queue = [root]
84
91
 
85
92
  while (node = queue.shift)
86
- yield node if @compiled.call(node)
93
+ yield node if @compiled.call(node) # steep:ignore
87
94
  queue.concat(node.compact_child_nodes)
88
95
  end
89
96
  end
@@ -142,7 +149,10 @@ module Prism
142
149
  parent = node.parent
143
150
 
144
151
  if parent.is_a?(ConstantReadNode) && parent.slice == "Prism"
145
- compile_node(node.child)
152
+ name = node.name
153
+ raise CompilationError, node.inspect if name.nil?
154
+
155
+ compile_constant_name(node, name)
146
156
  else
147
157
  compile_error(node)
148
158
  end
@@ -151,14 +161,17 @@ module Prism
151
161
  # in ConstantReadNode
152
162
  # in String
153
163
  def compile_constant_read_node(node)
154
- value = node.slice
164
+ compile_constant_name(node, node.name)
165
+ end
155
166
 
156
- if Prism.const_defined?(value, false)
157
- clazz = Prism.const_get(value)
167
+ # Compile a name associated with a constant.
168
+ def compile_constant_name(node, name)
169
+ if Prism.const_defined?(name, false)
170
+ clazz = Prism.const_get(name)
158
171
 
159
172
  ->(other) { clazz === other }
160
- elsif Object.const_defined?(value, false)
161
- clazz = Object.const_get(value)
173
+ elsif Object.const_defined?(name, false)
174
+ clazz = Object.const_get(name)
162
175
 
163
176
  ->(other) { clazz === other }
164
177
  else
@@ -174,7 +187,12 @@ module Prism
174
187
 
175
188
  preprocessed =
176
189
  node.elements.to_h do |element|
177
- [element.key.unescaped.to_sym, compile_node(element.value)]
190
+ key = element.key
191
+ if key.is_a?(SymbolNode)
192
+ [key.unescaped.to_sym, compile_node(element.value)]
193
+ else
194
+ raise CompilationError, element.inspect
195
+ end
178
196
  end
179
197
 
180
198
  compiled_keywords = ->(other) do
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Polyfill for String#append_as_bytes, which didn't exist until Ruby 3.4.
4
+ if !("".respond_to?(:append_as_bytes))
5
+ String.include(
6
+ Module.new {
7
+ def append_as_bytes(*args)
8
+ args.each do |arg|
9
+ arg = Integer === arg ? [arg].pack("C") : arg.b
10
+ self.<<(arg) # steep:ignore
11
+ end
12
+ end
13
+ }
14
+ )
15
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Polyfill for String#byteindex, which didn't exist until Ruby 3.2.
4
+ if !("".respond_to?(:byteindex))
5
+ String.include(
6
+ Module.new {
7
+ def byteindex(needle, offset = 0)
8
+ charindex = index(needle, offset)
9
+ slice(0...charindex).bytesize if charindex
10
+ end
11
+ }
12
+ )
13
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Polyfill for String#unpack1 with the offset parameter. Not all Ruby engines
4
+ # have Method#parameters implemented, so we check the arity instead if
5
+ # necessary.
6
+ if (unpack1 = String.instance_method(:unpack1)).respond_to?(:parameters) ? unpack1.parameters.none? { |_, name| name == :offset } : (unpack1.arity == 1)
7
+ String.prepend(
8
+ Module.new {
9
+ def unpack1(format, offset: 0) # :nodoc:
10
+ offset == 0 ? super(format) : self[offset..].unpack1(format) # steep:ignore
11
+ end
12
+ }
13
+ )
14
+ end
@@ -0,0 +1,413 @@
1
+ # frozen_string_literal: true
2
+
3
+ =begin
4
+ This file is generated by the templates/template.rb script and should not be
5
+ modified manually. See templates/lib/prism/reflection.rb.erb
6
+ if you are looking to modify the template
7
+ =end
8
+
9
+ module Prism
10
+ # The Reflection module provides the ability to reflect on the structure of
11
+ # the syntax tree itself, as opposed to looking at a single syntax tree. This
12
+ # is useful in metaprogramming contexts.
13
+ module Reflection
14
+ # A field represents a single piece of data on a node. It is the base class
15
+ # for all other field types.
16
+ class Field
17
+ # The name of the field.
18
+ attr_reader :name
19
+
20
+ # Initializes the field with the given name.
21
+ def initialize(name)
22
+ @name = name
23
+ end
24
+ end
25
+
26
+ # A node field represents a single child node in the syntax tree. It
27
+ # resolves to a Prism::Node in Ruby.
28
+ class NodeField < Field
29
+ end
30
+
31
+ # An optional node field represents a single child node in the syntax tree
32
+ # that may or may not be present. It resolves to either a Prism::Node or nil
33
+ # in Ruby.
34
+ class OptionalNodeField < Field
35
+ end
36
+
37
+ # A node list field represents a list of child nodes in the syntax tree. It
38
+ # resolves to an array of Prism::Node instances in Ruby.
39
+ class NodeListField < Field
40
+ end
41
+
42
+ # A constant field represents a constant value on a node. Effectively, it
43
+ # represents an identifier found within the source. It resolves to a symbol
44
+ # in Ruby.
45
+ class ConstantField < Field
46
+ end
47
+
48
+ # An optional constant field represents a constant value on a node that may
49
+ # or may not be present. It resolves to either a symbol or nil in Ruby.
50
+ class OptionalConstantField < Field
51
+ end
52
+
53
+ # A constant list field represents a list of constant values on a node. It
54
+ # resolves to an array of symbols in Ruby.
55
+ class ConstantListField < Field
56
+ end
57
+
58
+ # A string field represents a string value on a node. It almost always
59
+ # represents the unescaped value of a string-like literal. It resolves to a
60
+ # string in Ruby.
61
+ class StringField < Field
62
+ end
63
+
64
+ # A location field represents the location of some part of the node in the
65
+ # source code. For example, the location of a keyword or an operator. It
66
+ # resolves to a Prism::Location in Ruby.
67
+ class LocationField < Field
68
+ end
69
+
70
+ # An optional location field represents the location of some part of the
71
+ # node in the source code that may or may not be present. It resolves to
72
+ # either a Prism::Location or nil in Ruby.
73
+ class OptionalLocationField < Field
74
+ end
75
+
76
+ # An integer field represents an integer value. It is used to represent the
77
+ # value of an integer literal, the depth of local variables, and the number
78
+ # of a numbered reference. It resolves to an Integer in Ruby.
79
+ class IntegerField < Field
80
+ end
81
+
82
+ # A float field represents a double-precision floating point value. It is
83
+ # used exclusively to represent the value of a floating point literal. It
84
+ # resolves to a Float in Ruby.
85
+ class FloatField < Field
86
+ end
87
+
88
+ # A flags field represents a bitset of flags on a node. It resolves to an
89
+ # integer in Ruby. Note that the flags cannot be accessed directly on the
90
+ # node because the integer is kept private. Instead, the various flags in
91
+ # the bitset should be accessed through their query methods.
92
+ class FlagsField < Field
93
+ # The names of the flags in the bitset.
94
+ attr_reader :flags
95
+
96
+ # Initializes the flags field with the given name and flags.
97
+ def initialize(name, flags)
98
+ super(name)
99
+ @flags = flags
100
+ end
101
+ end
102
+
103
+ # Returns the fields for the given node.
104
+ def self.fields_for(node)
105
+ case node.type
106
+ when :alias_global_variable_node
107
+ [NodeField.new(:new_name), NodeField.new(:old_name), LocationField.new(:keyword_loc)]
108
+ when :alias_method_node
109
+ [NodeField.new(:new_name), NodeField.new(:old_name), LocationField.new(:keyword_loc)]
110
+ when :alternation_pattern_node
111
+ [NodeField.new(:left), NodeField.new(:right), LocationField.new(:operator_loc)]
112
+ when :and_node
113
+ [NodeField.new(:left), NodeField.new(:right), LocationField.new(:operator_loc)]
114
+ when :arguments_node
115
+ [FlagsField.new(:flags, [:contains_forwarding?, :contains_keywords?, :contains_keyword_splat?, :contains_splat?, :contains_multiple_splats?]), NodeListField.new(:arguments)]
116
+ when :array_node
117
+ [FlagsField.new(:flags, [:contains_splat?]), NodeListField.new(:elements), OptionalLocationField.new(:opening_loc), OptionalLocationField.new(:closing_loc)]
118
+ when :array_pattern_node
119
+ [OptionalNodeField.new(:constant), NodeListField.new(:requireds), OptionalNodeField.new(:rest), NodeListField.new(:posts), OptionalLocationField.new(:opening_loc), OptionalLocationField.new(:closing_loc)]
120
+ when :assoc_node
121
+ [NodeField.new(:key), NodeField.new(:value), OptionalLocationField.new(:operator_loc)]
122
+ when :assoc_splat_node
123
+ [OptionalNodeField.new(:value), LocationField.new(:operator_loc)]
124
+ when :back_reference_read_node
125
+ [ConstantField.new(:name)]
126
+ when :begin_node
127
+ [OptionalLocationField.new(:begin_keyword_loc), OptionalNodeField.new(:statements), OptionalNodeField.new(:rescue_clause), OptionalNodeField.new(:else_clause), OptionalNodeField.new(:ensure_clause), OptionalLocationField.new(:end_keyword_loc)]
128
+ when :block_argument_node
129
+ [OptionalNodeField.new(:expression), LocationField.new(:operator_loc)]
130
+ when :block_local_variable_node
131
+ [FlagsField.new(:flags, [:repeated_parameter?]), ConstantField.new(:name)]
132
+ when :block_node
133
+ [ConstantListField.new(:locals), OptionalNodeField.new(:parameters), OptionalNodeField.new(:body), LocationField.new(:opening_loc), LocationField.new(:closing_loc)]
134
+ when :block_parameter_node
135
+ [FlagsField.new(:flags, [:repeated_parameter?]), OptionalConstantField.new(:name), OptionalLocationField.new(:name_loc), LocationField.new(:operator_loc)]
136
+ when :block_parameters_node
137
+ [OptionalNodeField.new(:parameters), NodeListField.new(:locals), OptionalLocationField.new(:opening_loc), OptionalLocationField.new(:closing_loc)]
138
+ when :break_node
139
+ [OptionalNodeField.new(:arguments), LocationField.new(:keyword_loc)]
140
+ when :call_and_write_node
141
+ [FlagsField.new(:flags, [:safe_navigation?, :variable_call?, :attribute_write?, :ignore_visibility?]), OptionalNodeField.new(:receiver), OptionalLocationField.new(:call_operator_loc), OptionalLocationField.new(:message_loc), ConstantField.new(:read_name), ConstantField.new(:write_name), LocationField.new(:operator_loc), NodeField.new(:value)]
142
+ when :call_node
143
+ [FlagsField.new(:flags, [:safe_navigation?, :variable_call?, :attribute_write?, :ignore_visibility?]), OptionalNodeField.new(:receiver), OptionalLocationField.new(:call_operator_loc), ConstantField.new(:name), OptionalLocationField.new(:message_loc), OptionalLocationField.new(:opening_loc), OptionalNodeField.new(:arguments), OptionalLocationField.new(:closing_loc), OptionalNodeField.new(:block)]
144
+ when :call_operator_write_node
145
+ [FlagsField.new(:flags, [:safe_navigation?, :variable_call?, :attribute_write?, :ignore_visibility?]), OptionalNodeField.new(:receiver), OptionalLocationField.new(:call_operator_loc), OptionalLocationField.new(:message_loc), ConstantField.new(:read_name), ConstantField.new(:write_name), ConstantField.new(:binary_operator), LocationField.new(:binary_operator_loc), NodeField.new(:value)]
146
+ when :call_or_write_node
147
+ [FlagsField.new(:flags, [:safe_navigation?, :variable_call?, :attribute_write?, :ignore_visibility?]), OptionalNodeField.new(:receiver), OptionalLocationField.new(:call_operator_loc), OptionalLocationField.new(:message_loc), ConstantField.new(:read_name), ConstantField.new(:write_name), LocationField.new(:operator_loc), NodeField.new(:value)]
148
+ when :call_target_node
149
+ [FlagsField.new(:flags, [:safe_navigation?, :variable_call?, :attribute_write?, :ignore_visibility?]), NodeField.new(:receiver), LocationField.new(:call_operator_loc), ConstantField.new(:name), LocationField.new(:message_loc)]
150
+ when :capture_pattern_node
151
+ [NodeField.new(:value), NodeField.new(:target), LocationField.new(:operator_loc)]
152
+ when :case_match_node
153
+ [OptionalNodeField.new(:predicate), NodeListField.new(:conditions), OptionalNodeField.new(:else_clause), LocationField.new(:case_keyword_loc), LocationField.new(:end_keyword_loc)]
154
+ when :case_node
155
+ [OptionalNodeField.new(:predicate), NodeListField.new(:conditions), OptionalNodeField.new(:else_clause), LocationField.new(:case_keyword_loc), LocationField.new(:end_keyword_loc)]
156
+ when :class_node
157
+ [ConstantListField.new(:locals), LocationField.new(:class_keyword_loc), NodeField.new(:constant_path), OptionalLocationField.new(:inheritance_operator_loc), OptionalNodeField.new(:superclass), OptionalNodeField.new(:body), LocationField.new(:end_keyword_loc), ConstantField.new(:name)]
158
+ when :class_variable_and_write_node
159
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
160
+ when :class_variable_operator_write_node
161
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:binary_operator_loc), NodeField.new(:value), ConstantField.new(:binary_operator)]
162
+ when :class_variable_or_write_node
163
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
164
+ when :class_variable_read_node
165
+ [ConstantField.new(:name)]
166
+ when :class_variable_target_node
167
+ [ConstantField.new(:name)]
168
+ when :class_variable_write_node
169
+ [ConstantField.new(:name), LocationField.new(:name_loc), NodeField.new(:value), LocationField.new(:operator_loc)]
170
+ when :constant_and_write_node
171
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
172
+ when :constant_operator_write_node
173
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:binary_operator_loc), NodeField.new(:value), ConstantField.new(:binary_operator)]
174
+ when :constant_or_write_node
175
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
176
+ when :constant_path_and_write_node
177
+ [NodeField.new(:target), LocationField.new(:operator_loc), NodeField.new(:value)]
178
+ when :constant_path_node
179
+ [OptionalNodeField.new(:parent), OptionalConstantField.new(:name), LocationField.new(:delimiter_loc), LocationField.new(:name_loc)]
180
+ when :constant_path_operator_write_node
181
+ [NodeField.new(:target), LocationField.new(:binary_operator_loc), NodeField.new(:value), ConstantField.new(:binary_operator)]
182
+ when :constant_path_or_write_node
183
+ [NodeField.new(:target), LocationField.new(:operator_loc), NodeField.new(:value)]
184
+ when :constant_path_target_node
185
+ [OptionalNodeField.new(:parent), OptionalConstantField.new(:name), LocationField.new(:delimiter_loc), LocationField.new(:name_loc)]
186
+ when :constant_path_write_node
187
+ [NodeField.new(:target), LocationField.new(:operator_loc), NodeField.new(:value)]
188
+ when :constant_read_node
189
+ [ConstantField.new(:name)]
190
+ when :constant_target_node
191
+ [ConstantField.new(:name)]
192
+ when :constant_write_node
193
+ [ConstantField.new(:name), LocationField.new(:name_loc), NodeField.new(:value), LocationField.new(:operator_loc)]
194
+ when :def_node
195
+ [ConstantField.new(:name), LocationField.new(:name_loc), OptionalNodeField.new(:receiver), OptionalNodeField.new(:parameters), OptionalNodeField.new(:body), ConstantListField.new(:locals), LocationField.new(:def_keyword_loc), OptionalLocationField.new(:operator_loc), OptionalLocationField.new(:lparen_loc), OptionalLocationField.new(:rparen_loc), OptionalLocationField.new(:equal_loc), OptionalLocationField.new(:end_keyword_loc)]
196
+ when :defined_node
197
+ [OptionalLocationField.new(:lparen_loc), NodeField.new(:value), OptionalLocationField.new(:rparen_loc), LocationField.new(:keyword_loc)]
198
+ when :else_node
199
+ [LocationField.new(:else_keyword_loc), OptionalNodeField.new(:statements), OptionalLocationField.new(:end_keyword_loc)]
200
+ when :embedded_statements_node
201
+ [LocationField.new(:opening_loc), OptionalNodeField.new(:statements), LocationField.new(:closing_loc)]
202
+ when :embedded_variable_node
203
+ [LocationField.new(:operator_loc), NodeField.new(:variable)]
204
+ when :ensure_node
205
+ [LocationField.new(:ensure_keyword_loc), OptionalNodeField.new(:statements), LocationField.new(:end_keyword_loc)]
206
+ when :false_node
207
+ []
208
+ when :find_pattern_node
209
+ [OptionalNodeField.new(:constant), NodeField.new(:left), NodeListField.new(:requireds), NodeField.new(:right), OptionalLocationField.new(:opening_loc), OptionalLocationField.new(:closing_loc)]
210
+ when :flip_flop_node
211
+ [FlagsField.new(:flags, [:exclude_end?]), OptionalNodeField.new(:left), OptionalNodeField.new(:right), LocationField.new(:operator_loc)]
212
+ when :float_node
213
+ [FloatField.new(:value)]
214
+ when :for_node
215
+ [NodeField.new(:index), NodeField.new(:collection), OptionalNodeField.new(:statements), LocationField.new(:for_keyword_loc), LocationField.new(:in_keyword_loc), OptionalLocationField.new(:do_keyword_loc), LocationField.new(:end_keyword_loc)]
216
+ when :forwarding_arguments_node
217
+ []
218
+ when :forwarding_parameter_node
219
+ []
220
+ when :forwarding_super_node
221
+ [OptionalNodeField.new(:block)]
222
+ when :global_variable_and_write_node
223
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
224
+ when :global_variable_operator_write_node
225
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:binary_operator_loc), NodeField.new(:value), ConstantField.new(:binary_operator)]
226
+ when :global_variable_or_write_node
227
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
228
+ when :global_variable_read_node
229
+ [ConstantField.new(:name)]
230
+ when :global_variable_target_node
231
+ [ConstantField.new(:name)]
232
+ when :global_variable_write_node
233
+ [ConstantField.new(:name), LocationField.new(:name_loc), NodeField.new(:value), LocationField.new(:operator_loc)]
234
+ when :hash_node
235
+ [LocationField.new(:opening_loc), NodeListField.new(:elements), LocationField.new(:closing_loc)]
236
+ when :hash_pattern_node
237
+ [OptionalNodeField.new(:constant), NodeListField.new(:elements), OptionalNodeField.new(:rest), OptionalLocationField.new(:opening_loc), OptionalLocationField.new(:closing_loc)]
238
+ when :if_node
239
+ [OptionalLocationField.new(:if_keyword_loc), NodeField.new(:predicate), OptionalLocationField.new(:then_keyword_loc), OptionalNodeField.new(:statements), OptionalNodeField.new(:subsequent), OptionalLocationField.new(:end_keyword_loc)]
240
+ when :imaginary_node
241
+ [NodeField.new(:numeric)]
242
+ when :implicit_node
243
+ [NodeField.new(:value)]
244
+ when :implicit_rest_node
245
+ []
246
+ when :in_node
247
+ [NodeField.new(:pattern), OptionalNodeField.new(:statements), LocationField.new(:in_loc), OptionalLocationField.new(:then_loc)]
248
+ when :index_and_write_node
249
+ [FlagsField.new(:flags, [:safe_navigation?, :variable_call?, :attribute_write?, :ignore_visibility?]), OptionalNodeField.new(:receiver), OptionalLocationField.new(:call_operator_loc), LocationField.new(:opening_loc), OptionalNodeField.new(:arguments), LocationField.new(:closing_loc), OptionalNodeField.new(:block), LocationField.new(:operator_loc), NodeField.new(:value)]
250
+ when :index_operator_write_node
251
+ [FlagsField.new(:flags, [:safe_navigation?, :variable_call?, :attribute_write?, :ignore_visibility?]), OptionalNodeField.new(:receiver), OptionalLocationField.new(:call_operator_loc), LocationField.new(:opening_loc), OptionalNodeField.new(:arguments), LocationField.new(:closing_loc), OptionalNodeField.new(:block), ConstantField.new(:binary_operator), LocationField.new(:binary_operator_loc), NodeField.new(:value)]
252
+ when :index_or_write_node
253
+ [FlagsField.new(:flags, [:safe_navigation?, :variable_call?, :attribute_write?, :ignore_visibility?]), OptionalNodeField.new(:receiver), OptionalLocationField.new(:call_operator_loc), LocationField.new(:opening_loc), OptionalNodeField.new(:arguments), LocationField.new(:closing_loc), OptionalNodeField.new(:block), LocationField.new(:operator_loc), NodeField.new(:value)]
254
+ when :index_target_node
255
+ [FlagsField.new(:flags, [:safe_navigation?, :variable_call?, :attribute_write?, :ignore_visibility?]), NodeField.new(:receiver), LocationField.new(:opening_loc), OptionalNodeField.new(:arguments), LocationField.new(:closing_loc), OptionalNodeField.new(:block)]
256
+ when :instance_variable_and_write_node
257
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
258
+ when :instance_variable_operator_write_node
259
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:binary_operator_loc), NodeField.new(:value), ConstantField.new(:binary_operator)]
260
+ when :instance_variable_or_write_node
261
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
262
+ when :instance_variable_read_node
263
+ [ConstantField.new(:name)]
264
+ when :instance_variable_target_node
265
+ [ConstantField.new(:name)]
266
+ when :instance_variable_write_node
267
+ [ConstantField.new(:name), LocationField.new(:name_loc), NodeField.new(:value), LocationField.new(:operator_loc)]
268
+ when :integer_node
269
+ [FlagsField.new(:flags, [:binary?, :decimal?, :octal?, :hexadecimal?]), IntegerField.new(:value)]
270
+ when :interpolated_match_last_line_node
271
+ [FlagsField.new(:flags, [:ignore_case?, :extended?, :multi_line?, :once?, :euc_jp?, :ascii_8bit?, :windows_31j?, :utf_8?, :forced_utf8_encoding?, :forced_binary_encoding?, :forced_us_ascii_encoding?]), LocationField.new(:opening_loc), NodeListField.new(:parts), LocationField.new(:closing_loc)]
272
+ when :interpolated_regular_expression_node
273
+ [FlagsField.new(:flags, [:ignore_case?, :extended?, :multi_line?, :once?, :euc_jp?, :ascii_8bit?, :windows_31j?, :utf_8?, :forced_utf8_encoding?, :forced_binary_encoding?, :forced_us_ascii_encoding?]), LocationField.new(:opening_loc), NodeListField.new(:parts), LocationField.new(:closing_loc)]
274
+ when :interpolated_string_node
275
+ [FlagsField.new(:flags, [:frozen?, :mutable?]), OptionalLocationField.new(:opening_loc), NodeListField.new(:parts), OptionalLocationField.new(:closing_loc)]
276
+ when :interpolated_symbol_node
277
+ [OptionalLocationField.new(:opening_loc), NodeListField.new(:parts), OptionalLocationField.new(:closing_loc)]
278
+ when :interpolated_x_string_node
279
+ [LocationField.new(:opening_loc), NodeListField.new(:parts), LocationField.new(:closing_loc)]
280
+ when :it_local_variable_read_node
281
+ []
282
+ when :it_parameters_node
283
+ []
284
+ when :keyword_hash_node
285
+ [FlagsField.new(:flags, [:symbol_keys?]), NodeListField.new(:elements)]
286
+ when :keyword_rest_parameter_node
287
+ [FlagsField.new(:flags, [:repeated_parameter?]), OptionalConstantField.new(:name), OptionalLocationField.new(:name_loc), LocationField.new(:operator_loc)]
288
+ when :lambda_node
289
+ [ConstantListField.new(:locals), LocationField.new(:operator_loc), LocationField.new(:opening_loc), LocationField.new(:closing_loc), OptionalNodeField.new(:parameters), OptionalNodeField.new(:body)]
290
+ when :local_variable_and_write_node
291
+ [LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value), ConstantField.new(:name), IntegerField.new(:depth)]
292
+ when :local_variable_operator_write_node
293
+ [LocationField.new(:name_loc), LocationField.new(:binary_operator_loc), NodeField.new(:value), ConstantField.new(:name), ConstantField.new(:binary_operator), IntegerField.new(:depth)]
294
+ when :local_variable_or_write_node
295
+ [LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value), ConstantField.new(:name), IntegerField.new(:depth)]
296
+ when :local_variable_read_node
297
+ [ConstantField.new(:name), IntegerField.new(:depth)]
298
+ when :local_variable_target_node
299
+ [ConstantField.new(:name), IntegerField.new(:depth)]
300
+ when :local_variable_write_node
301
+ [ConstantField.new(:name), IntegerField.new(:depth), LocationField.new(:name_loc), NodeField.new(:value), LocationField.new(:operator_loc)]
302
+ when :match_last_line_node
303
+ [FlagsField.new(:flags, [:ignore_case?, :extended?, :multi_line?, :once?, :euc_jp?, :ascii_8bit?, :windows_31j?, :utf_8?, :forced_utf8_encoding?, :forced_binary_encoding?, :forced_us_ascii_encoding?]), LocationField.new(:opening_loc), LocationField.new(:content_loc), LocationField.new(:closing_loc), StringField.new(:unescaped)]
304
+ when :match_predicate_node
305
+ [NodeField.new(:value), NodeField.new(:pattern), LocationField.new(:operator_loc)]
306
+ when :match_required_node
307
+ [NodeField.new(:value), NodeField.new(:pattern), LocationField.new(:operator_loc)]
308
+ when :match_write_node
309
+ [NodeField.new(:call), NodeListField.new(:targets)]
310
+ when :missing_node
311
+ []
312
+ when :module_node
313
+ [ConstantListField.new(:locals), LocationField.new(:module_keyword_loc), NodeField.new(:constant_path), OptionalNodeField.new(:body), LocationField.new(:end_keyword_loc), ConstantField.new(:name)]
314
+ when :multi_target_node
315
+ [NodeListField.new(:lefts), OptionalNodeField.new(:rest), NodeListField.new(:rights), OptionalLocationField.new(:lparen_loc), OptionalLocationField.new(:rparen_loc)]
316
+ when :multi_write_node
317
+ [NodeListField.new(:lefts), OptionalNodeField.new(:rest), NodeListField.new(:rights), OptionalLocationField.new(:lparen_loc), OptionalLocationField.new(:rparen_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
318
+ when :next_node
319
+ [OptionalNodeField.new(:arguments), LocationField.new(:keyword_loc)]
320
+ when :nil_node
321
+ []
322
+ when :no_keywords_parameter_node
323
+ [LocationField.new(:operator_loc), LocationField.new(:keyword_loc)]
324
+ when :numbered_parameters_node
325
+ [IntegerField.new(:maximum)]
326
+ when :numbered_reference_read_node
327
+ [IntegerField.new(:number)]
328
+ when :optional_keyword_parameter_node
329
+ [FlagsField.new(:flags, [:repeated_parameter?]), ConstantField.new(:name), LocationField.new(:name_loc), NodeField.new(:value)]
330
+ when :optional_parameter_node
331
+ [FlagsField.new(:flags, [:repeated_parameter?]), ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
332
+ when :or_node
333
+ [NodeField.new(:left), NodeField.new(:right), LocationField.new(:operator_loc)]
334
+ when :parameters_node
335
+ [NodeListField.new(:requireds), NodeListField.new(:optionals), OptionalNodeField.new(:rest), NodeListField.new(:posts), NodeListField.new(:keywords), OptionalNodeField.new(:keyword_rest), OptionalNodeField.new(:block)]
336
+ when :parentheses_node
337
+ [FlagsField.new(:flags, [:multiple_statements?]), OptionalNodeField.new(:body), LocationField.new(:opening_loc), LocationField.new(:closing_loc)]
338
+ when :pinned_expression_node
339
+ [NodeField.new(:expression), LocationField.new(:operator_loc), LocationField.new(:lparen_loc), LocationField.new(:rparen_loc)]
340
+ when :pinned_variable_node
341
+ [NodeField.new(:variable), LocationField.new(:operator_loc)]
342
+ when :post_execution_node
343
+ [OptionalNodeField.new(:statements), LocationField.new(:keyword_loc), LocationField.new(:opening_loc), LocationField.new(:closing_loc)]
344
+ when :pre_execution_node
345
+ [OptionalNodeField.new(:statements), LocationField.new(:keyword_loc), LocationField.new(:opening_loc), LocationField.new(:closing_loc)]
346
+ when :program_node
347
+ [ConstantListField.new(:locals), NodeField.new(:statements)]
348
+ when :range_node
349
+ [FlagsField.new(:flags, [:exclude_end?]), OptionalNodeField.new(:left), OptionalNodeField.new(:right), LocationField.new(:operator_loc)]
350
+ when :rational_node
351
+ [FlagsField.new(:flags, [:binary?, :decimal?, :octal?, :hexadecimal?]), IntegerField.new(:numerator), IntegerField.new(:denominator)]
352
+ when :redo_node
353
+ []
354
+ when :regular_expression_node
355
+ [FlagsField.new(:flags, [:ignore_case?, :extended?, :multi_line?, :once?, :euc_jp?, :ascii_8bit?, :windows_31j?, :utf_8?, :forced_utf8_encoding?, :forced_binary_encoding?, :forced_us_ascii_encoding?]), LocationField.new(:opening_loc), LocationField.new(:content_loc), LocationField.new(:closing_loc), StringField.new(:unescaped)]
356
+ when :required_keyword_parameter_node
357
+ [FlagsField.new(:flags, [:repeated_parameter?]), ConstantField.new(:name), LocationField.new(:name_loc)]
358
+ when :required_parameter_node
359
+ [FlagsField.new(:flags, [:repeated_parameter?]), ConstantField.new(:name)]
360
+ when :rescue_modifier_node
361
+ [NodeField.new(:expression), LocationField.new(:keyword_loc), NodeField.new(:rescue_expression)]
362
+ when :rescue_node
363
+ [LocationField.new(:keyword_loc), NodeListField.new(:exceptions), OptionalLocationField.new(:operator_loc), OptionalNodeField.new(:reference), OptionalLocationField.new(:then_keyword_loc), OptionalNodeField.new(:statements), OptionalNodeField.new(:subsequent)]
364
+ when :rest_parameter_node
365
+ [FlagsField.new(:flags, [:repeated_parameter?]), OptionalConstantField.new(:name), OptionalLocationField.new(:name_loc), LocationField.new(:operator_loc)]
366
+ when :retry_node
367
+ []
368
+ when :return_node
369
+ [LocationField.new(:keyword_loc), OptionalNodeField.new(:arguments)]
370
+ when :self_node
371
+ []
372
+ when :shareable_constant_node
373
+ [FlagsField.new(:flags, [:literal?, :experimental_everything?, :experimental_copy?]), NodeField.new(:write)]
374
+ when :singleton_class_node
375
+ [ConstantListField.new(:locals), LocationField.new(:class_keyword_loc), LocationField.new(:operator_loc), NodeField.new(:expression), OptionalNodeField.new(:body), LocationField.new(:end_keyword_loc)]
376
+ when :source_encoding_node
377
+ []
378
+ when :source_file_node
379
+ [FlagsField.new(:flags, [:forced_utf8_encoding?, :forced_binary_encoding?, :frozen?, :mutable?]), StringField.new(:filepath)]
380
+ when :source_line_node
381
+ []
382
+ when :splat_node
383
+ [LocationField.new(:operator_loc), OptionalNodeField.new(:expression)]
384
+ when :statements_node
385
+ [NodeListField.new(:body)]
386
+ when :string_node
387
+ [FlagsField.new(:flags, [:forced_utf8_encoding?, :forced_binary_encoding?, :frozen?, :mutable?]), OptionalLocationField.new(:opening_loc), LocationField.new(:content_loc), OptionalLocationField.new(:closing_loc), StringField.new(:unescaped)]
388
+ when :super_node
389
+ [LocationField.new(:keyword_loc), OptionalLocationField.new(:lparen_loc), OptionalNodeField.new(:arguments), OptionalLocationField.new(:rparen_loc), OptionalNodeField.new(:block)]
390
+ when :symbol_node
391
+ [FlagsField.new(:flags, [:forced_utf8_encoding?, :forced_binary_encoding?, :forced_us_ascii_encoding?]), OptionalLocationField.new(:opening_loc), OptionalLocationField.new(:value_loc), OptionalLocationField.new(:closing_loc), StringField.new(:unescaped)]
392
+ when :true_node
393
+ []
394
+ when :undef_node
395
+ [NodeListField.new(:names), LocationField.new(:keyword_loc)]
396
+ when :unless_node
397
+ [LocationField.new(:keyword_loc), NodeField.new(:predicate), OptionalLocationField.new(:then_keyword_loc), OptionalNodeField.new(:statements), OptionalNodeField.new(:else_clause), OptionalLocationField.new(:end_keyword_loc)]
398
+ when :until_node
399
+ [FlagsField.new(:flags, [:begin_modifier?]), LocationField.new(:keyword_loc), OptionalLocationField.new(:do_keyword_loc), OptionalLocationField.new(:closing_loc), NodeField.new(:predicate), OptionalNodeField.new(:statements)]
400
+ when :when_node
401
+ [LocationField.new(:keyword_loc), NodeListField.new(:conditions), OptionalLocationField.new(:then_keyword_loc), OptionalNodeField.new(:statements)]
402
+ when :while_node
403
+ [FlagsField.new(:flags, [:begin_modifier?]), LocationField.new(:keyword_loc), OptionalLocationField.new(:do_keyword_loc), OptionalLocationField.new(:closing_loc), NodeField.new(:predicate), OptionalNodeField.new(:statements)]
404
+ when :x_string_node
405
+ [FlagsField.new(:flags, [:forced_utf8_encoding?, :forced_binary_encoding?]), LocationField.new(:opening_loc), LocationField.new(:content_loc), LocationField.new(:closing_loc), StringField.new(:unescaped)]
406
+ when :yield_node
407
+ [LocationField.new(:keyword_loc), OptionalLocationField.new(:lparen_loc), OptionalNodeField.new(:arguments), OptionalLocationField.new(:rparen_loc)]
408
+ else
409
+ raise "Unknown node type: #{node.type.inspect}"
410
+ end
411
+ end
412
+ end
413
+ end