prism 0.24.0 → 0.26.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/BSDmakefile +58 -0
  3. data/CHANGELOG.md +69 -1
  4. data/Makefile +22 -16
  5. data/README.md +45 -6
  6. data/config.yml +510 -4
  7. data/docs/build_system.md +31 -0
  8. data/docs/configuration.md +3 -0
  9. data/docs/cruby_compilation.md +1 -1
  10. data/docs/parser_translation.md +14 -9
  11. data/docs/releasing.md +7 -9
  12. data/docs/ripper_translation.md +50 -0
  13. data/docs/ruby_api.md +1 -0
  14. data/docs/serialization.md +26 -5
  15. data/ext/prism/api_node.c +911 -815
  16. data/ext/prism/api_pack.c +9 -0
  17. data/ext/prism/extconf.rb +34 -13
  18. data/ext/prism/extension.c +341 -68
  19. data/ext/prism/extension.h +5 -4
  20. data/include/prism/ast.h +213 -64
  21. data/include/prism/defines.h +106 -2
  22. data/include/prism/diagnostic.h +146 -72
  23. data/include/prism/encoding.h +22 -4
  24. data/include/prism/node.h +93 -0
  25. data/include/prism/options.h +82 -7
  26. data/include/prism/pack.h +11 -0
  27. data/include/prism/parser.h +203 -54
  28. data/include/prism/prettyprint.h +8 -0
  29. data/include/prism/static_literals.h +118 -0
  30. data/include/prism/util/pm_buffer.h +65 -2
  31. data/include/prism/util/pm_constant_pool.h +18 -1
  32. data/include/prism/util/pm_integer.h +119 -0
  33. data/include/prism/util/pm_list.h +1 -1
  34. data/include/prism/util/pm_newline_list.h +8 -0
  35. data/include/prism/util/pm_string.h +26 -2
  36. data/include/prism/version.h +2 -2
  37. data/include/prism.h +59 -1
  38. data/lib/prism/compiler.rb +8 -1
  39. data/lib/prism/debug.rb +46 -3
  40. data/lib/prism/desugar_compiler.rb +4 -2
  41. data/lib/prism/dispatcher.rb +29 -0
  42. data/lib/prism/dot_visitor.rb +87 -16
  43. data/lib/prism/dsl.rb +24 -12
  44. data/lib/prism/ffi.rb +77 -12
  45. data/lib/prism/lex_compat.rb +17 -15
  46. data/lib/prism/mutation_compiler.rb +11 -0
  47. data/lib/prism/node.rb +2112 -2499
  48. data/lib/prism/node_ext.rb +77 -29
  49. data/lib/prism/pack.rb +4 -0
  50. data/lib/prism/parse_result/comments.rb +34 -17
  51. data/lib/prism/parse_result/newlines.rb +3 -1
  52. data/lib/prism/parse_result.rb +83 -32
  53. data/lib/prism/pattern.rb +16 -4
  54. data/lib/prism/polyfill/string.rb +12 -0
  55. data/lib/prism/reflection.rb +421 -0
  56. data/lib/prism/serialize.rb +450 -102
  57. data/lib/prism/translation/parser/compiler.rb +189 -50
  58. data/lib/prism/translation/parser/lexer.rb +103 -22
  59. data/lib/prism/translation/parser/rubocop.rb +41 -13
  60. data/lib/prism/translation/parser.rb +119 -7
  61. data/lib/prism/translation/parser33.rb +1 -1
  62. data/lib/prism/translation/parser34.rb +1 -1
  63. data/lib/prism/translation/ripper/sexp.rb +125 -0
  64. data/lib/prism/translation/ripper/shim.rb +5 -0
  65. data/lib/prism/translation/ripper.rb +3212 -462
  66. data/lib/prism/translation/ruby_parser.rb +35 -18
  67. data/lib/prism/translation.rb +3 -1
  68. data/lib/prism/visitor.rb +10 -0
  69. data/lib/prism.rb +9 -18
  70. data/prism.gemspec +39 -6
  71. data/rbi/prism/compiler.rbi +14 -0
  72. data/rbi/prism/desugar_compiler.rbi +5 -0
  73. data/rbi/prism/mutation_compiler.rbi +5 -0
  74. data/rbi/prism/node.rbi +8674 -0
  75. data/rbi/prism/node_ext.rbi +102 -0
  76. data/rbi/prism/parse_result.rbi +307 -0
  77. data/rbi/prism/reflection.rbi +64 -0
  78. data/rbi/prism/translation/parser/compiler.rbi +13 -0
  79. data/rbi/prism/translation/parser.rbi +11 -0
  80. data/rbi/prism/translation/parser33.rbi +6 -0
  81. data/rbi/prism/translation/parser34.rbi +6 -0
  82. data/rbi/prism/translation/ripper/ripper_compiler.rbi +5 -0
  83. data/rbi/prism/translation/ripper.rbi +25 -0
  84. data/rbi/prism/translation/ruby_parser.rbi +11 -0
  85. data/rbi/prism/visitor.rbi +470 -0
  86. data/rbi/prism.rbi +38 -7748
  87. data/sig/prism/compiler.rbs +9 -0
  88. data/sig/prism/dispatcher.rbs +16 -0
  89. data/sig/prism/dot_visitor.rbs +6 -0
  90. data/sig/prism/dsl.rbs +462 -0
  91. data/sig/prism/mutation_compiler.rbs +158 -0
  92. data/sig/prism/node.rbs +3538 -0
  93. data/sig/prism/node_ext.rbs +78 -0
  94. data/sig/prism/pack.rbs +43 -0
  95. data/sig/prism/parse_result.rbs +128 -0
  96. data/sig/prism/pattern.rbs +13 -0
  97. data/sig/prism/reflection.rbs +56 -0
  98. data/sig/prism/serialize.rbs +7 -0
  99. data/sig/prism/visitor.rbs +168 -0
  100. data/sig/prism.rbs +188 -4767
  101. data/src/diagnostic.c +597 -230
  102. data/src/encoding.c +211 -108
  103. data/src/node.c +7526 -447
  104. data/src/options.c +66 -31
  105. data/src/pack.c +33 -17
  106. data/src/prettyprint.c +1294 -1385
  107. data/src/prism.c +4015 -1149
  108. data/src/regexp.c +17 -2
  109. data/src/serialize.c +47 -28
  110. data/src/static_literals.c +552 -0
  111. data/src/token_type.c +4 -3
  112. data/src/util/pm_buffer.c +147 -20
  113. data/src/util/pm_char.c +4 -4
  114. data/src/util/pm_constant_pool.c +35 -11
  115. data/src/util/pm_integer.c +635 -0
  116. data/src/util/pm_list.c +1 -1
  117. data/src/util/pm_newline_list.c +14 -5
  118. data/src/util/pm_string.c +134 -5
  119. data/src/util/pm_string_list.c +2 -2
  120. metadata +41 -8
  121. data/docs/ripper.md +0 -36
  122. data/include/prism/util/pm_state_stack.h +0 -42
  123. data/rbi/prism_static.rbi +0 -207
  124. data/sig/prism_static.rbs +0 -201
  125. data/src/util/pm_state_stack.c +0 -25
@@ -0,0 +1,421 @@
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
+ # A uint8 field represents an unsigned 8-bit integer value on a node. It
77
+ # resolves to an Integer in Ruby.
78
+ class UInt8Field < Field
79
+ end
80
+
81
+ # A uint32 field represents an unsigned 32-bit integer value on a node. It
82
+ # resolves to an Integer in Ruby.
83
+ class UInt32Field < Field
84
+ end
85
+
86
+ # A flags field represents a bitset of flags on a node. It resolves to an
87
+ # integer in Ruby. Note that the flags cannot be accessed directly on the
88
+ # node because the integer is kept private. Instead, the various flags in
89
+ # the bitset should be accessed through their query methods.
90
+ class FlagsField < Field
91
+ # The names of the flags in the bitset.
92
+ attr_reader :flags
93
+
94
+ # Initializes the flags field with the given name and flags.
95
+ def initialize(name, flags)
96
+ super(name)
97
+ @flags = flags
98
+ end
99
+ end
100
+
101
+ # An integer field represents an arbitrarily-sized integer value. It is used
102
+ # exclusively to represent the value of an integer literal. It resolves to
103
+ # an Integer in Ruby.
104
+ class IntegerField < Field
105
+ end
106
+
107
+ # A double field represents a double-precision floating point value. It is
108
+ # used exclusively to represent the value of a floating point literal. It
109
+ # resolves to a Float in Ruby.
110
+ class DoubleField < Field
111
+ end
112
+
113
+ # Returns the fields for the given node.
114
+ def self.fields_for(node)
115
+ case node.type
116
+ when :alias_global_variable_node
117
+ [NodeField.new(:new_name), NodeField.new(:old_name), LocationField.new(:keyword_loc)]
118
+ when :alias_method_node
119
+ [NodeField.new(:new_name), NodeField.new(:old_name), LocationField.new(:keyword_loc)]
120
+ when :alternation_pattern_node
121
+ [NodeField.new(:left), NodeField.new(:right), LocationField.new(:operator_loc)]
122
+ when :and_node
123
+ [NodeField.new(:left), NodeField.new(:right), LocationField.new(:operator_loc)]
124
+ when :arguments_node
125
+ [FlagsField.new(:flags, [:contains_keyword_splat?]), NodeListField.new(:arguments)]
126
+ when :array_node
127
+ [FlagsField.new(:flags, [:contains_splat?]), NodeListField.new(:elements), OptionalLocationField.new(:opening_loc), OptionalLocationField.new(:closing_loc)]
128
+ when :array_pattern_node
129
+ [OptionalNodeField.new(:constant), NodeListField.new(:requireds), OptionalNodeField.new(:rest), NodeListField.new(:posts), OptionalLocationField.new(:opening_loc), OptionalLocationField.new(:closing_loc)]
130
+ when :assoc_node
131
+ [NodeField.new(:key), NodeField.new(:value), OptionalLocationField.new(:operator_loc)]
132
+ when :assoc_splat_node
133
+ [OptionalNodeField.new(:value), LocationField.new(:operator_loc)]
134
+ when :back_reference_read_node
135
+ [ConstantField.new(:name)]
136
+ when :begin_node
137
+ [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)]
138
+ when :block_argument_node
139
+ [OptionalNodeField.new(:expression), LocationField.new(:operator_loc)]
140
+ when :block_local_variable_node
141
+ [FlagsField.new(:flags, [:repeated_parameter?]), ConstantField.new(:name)]
142
+ when :block_node
143
+ [ConstantListField.new(:locals), OptionalNodeField.new(:parameters), OptionalNodeField.new(:body), LocationField.new(:opening_loc), LocationField.new(:closing_loc)]
144
+ when :block_parameter_node
145
+ [FlagsField.new(:flags, [:repeated_parameter?]), OptionalConstantField.new(:name), OptionalLocationField.new(:name_loc), LocationField.new(:operator_loc)]
146
+ when :block_parameters_node
147
+ [OptionalNodeField.new(:parameters), NodeListField.new(:locals), OptionalLocationField.new(:opening_loc), OptionalLocationField.new(:closing_loc)]
148
+ when :break_node
149
+ [OptionalNodeField.new(:arguments), LocationField.new(:keyword_loc)]
150
+ when :call_and_write_node
151
+ [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)]
152
+ when :call_node
153
+ [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)]
154
+ when :call_operator_write_node
155
+ [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(:operator), LocationField.new(:operator_loc), NodeField.new(:value)]
156
+ when :call_or_write_node
157
+ [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)]
158
+ when :call_target_node
159
+ [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)]
160
+ when :capture_pattern_node
161
+ [NodeField.new(:value), NodeField.new(:target), LocationField.new(:operator_loc)]
162
+ when :case_match_node
163
+ [OptionalNodeField.new(:predicate), NodeListField.new(:conditions), OptionalNodeField.new(:consequent), LocationField.new(:case_keyword_loc), LocationField.new(:end_keyword_loc)]
164
+ when :case_node
165
+ [OptionalNodeField.new(:predicate), NodeListField.new(:conditions), OptionalNodeField.new(:consequent), LocationField.new(:case_keyword_loc), LocationField.new(:end_keyword_loc)]
166
+ when :class_node
167
+ [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)]
168
+ when :class_variable_and_write_node
169
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
170
+ when :class_variable_operator_write_node
171
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value), ConstantField.new(:operator)]
172
+ when :class_variable_or_write_node
173
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
174
+ when :class_variable_read_node
175
+ [ConstantField.new(:name)]
176
+ when :class_variable_target_node
177
+ [ConstantField.new(:name)]
178
+ when :class_variable_write_node
179
+ [ConstantField.new(:name), LocationField.new(:name_loc), NodeField.new(:value), LocationField.new(:operator_loc)]
180
+ when :constant_and_write_node
181
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
182
+ when :constant_operator_write_node
183
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value), ConstantField.new(:operator)]
184
+ when :constant_or_write_node
185
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
186
+ when :constant_path_and_write_node
187
+ [NodeField.new(:target), LocationField.new(:operator_loc), NodeField.new(:value)]
188
+ when :constant_path_node
189
+ [OptionalNodeField.new(:parent), NodeField.new(:child), LocationField.new(:delimiter_loc)]
190
+ when :constant_path_operator_write_node
191
+ [NodeField.new(:target), LocationField.new(:operator_loc), NodeField.new(:value), ConstantField.new(:operator)]
192
+ when :constant_path_or_write_node
193
+ [NodeField.new(:target), LocationField.new(:operator_loc), NodeField.new(:value)]
194
+ when :constant_path_target_node
195
+ [OptionalNodeField.new(:parent), NodeField.new(:child), LocationField.new(:delimiter_loc)]
196
+ when :constant_path_write_node
197
+ [NodeField.new(:target), LocationField.new(:operator_loc), NodeField.new(:value)]
198
+ when :constant_read_node
199
+ [ConstantField.new(:name)]
200
+ when :constant_target_node
201
+ [ConstantField.new(:name)]
202
+ when :constant_write_node
203
+ [ConstantField.new(:name), LocationField.new(:name_loc), NodeField.new(:value), LocationField.new(:operator_loc)]
204
+ when :def_node
205
+ [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)]
206
+ when :defined_node
207
+ [OptionalLocationField.new(:lparen_loc), NodeField.new(:value), OptionalLocationField.new(:rparen_loc), LocationField.new(:keyword_loc)]
208
+ when :else_node
209
+ [LocationField.new(:else_keyword_loc), OptionalNodeField.new(:statements), OptionalLocationField.new(:end_keyword_loc)]
210
+ when :embedded_statements_node
211
+ [LocationField.new(:opening_loc), OptionalNodeField.new(:statements), LocationField.new(:closing_loc)]
212
+ when :embedded_variable_node
213
+ [LocationField.new(:operator_loc), NodeField.new(:variable)]
214
+ when :ensure_node
215
+ [LocationField.new(:ensure_keyword_loc), OptionalNodeField.new(:statements), LocationField.new(:end_keyword_loc)]
216
+ when :false_node
217
+ []
218
+ when :find_pattern_node
219
+ [OptionalNodeField.new(:constant), NodeField.new(:left), NodeListField.new(:requireds), NodeField.new(:right), OptionalLocationField.new(:opening_loc), OptionalLocationField.new(:closing_loc)]
220
+ when :flip_flop_node
221
+ [FlagsField.new(:flags, [:exclude_end?]), OptionalNodeField.new(:left), OptionalNodeField.new(:right), LocationField.new(:operator_loc)]
222
+ when :float_node
223
+ [DoubleField.new(:value)]
224
+ when :for_node
225
+ [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)]
226
+ when :forwarding_arguments_node
227
+ []
228
+ when :forwarding_parameter_node
229
+ []
230
+ when :forwarding_super_node
231
+ [OptionalNodeField.new(:block)]
232
+ when :global_variable_and_write_node
233
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
234
+ when :global_variable_operator_write_node
235
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value), ConstantField.new(:operator)]
236
+ when :global_variable_or_write_node
237
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
238
+ when :global_variable_read_node
239
+ [ConstantField.new(:name)]
240
+ when :global_variable_target_node
241
+ [ConstantField.new(:name)]
242
+ when :global_variable_write_node
243
+ [ConstantField.new(:name), LocationField.new(:name_loc), NodeField.new(:value), LocationField.new(:operator_loc)]
244
+ when :hash_node
245
+ [LocationField.new(:opening_loc), NodeListField.new(:elements), LocationField.new(:closing_loc)]
246
+ when :hash_pattern_node
247
+ [OptionalNodeField.new(:constant), NodeListField.new(:elements), OptionalNodeField.new(:rest), OptionalLocationField.new(:opening_loc), OptionalLocationField.new(:closing_loc)]
248
+ when :if_node
249
+ [OptionalLocationField.new(:if_keyword_loc), NodeField.new(:predicate), OptionalLocationField.new(:then_keyword_loc), OptionalNodeField.new(:statements), OptionalNodeField.new(:consequent), OptionalLocationField.new(:end_keyword_loc)]
250
+ when :imaginary_node
251
+ [NodeField.new(:numeric)]
252
+ when :implicit_node
253
+ [NodeField.new(:value)]
254
+ when :implicit_rest_node
255
+ []
256
+ when :in_node
257
+ [NodeField.new(:pattern), OptionalNodeField.new(:statements), LocationField.new(:in_loc), OptionalLocationField.new(:then_loc)]
258
+ when :index_and_write_node
259
+ [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)]
260
+ when :index_operator_write_node
261
+ [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(:operator), LocationField.new(:operator_loc), NodeField.new(:value)]
262
+ when :index_or_write_node
263
+ [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)]
264
+ when :index_target_node
265
+ [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)]
266
+ when :instance_variable_and_write_node
267
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
268
+ when :instance_variable_operator_write_node
269
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value), ConstantField.new(:operator)]
270
+ when :instance_variable_or_write_node
271
+ [ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
272
+ when :instance_variable_read_node
273
+ [ConstantField.new(:name)]
274
+ when :instance_variable_target_node
275
+ [ConstantField.new(:name)]
276
+ when :instance_variable_write_node
277
+ [ConstantField.new(:name), LocationField.new(:name_loc), NodeField.new(:value), LocationField.new(:operator_loc)]
278
+ when :integer_node
279
+ [FlagsField.new(:flags, [:binary?, :decimal?, :octal?, :hexadecimal?]), IntegerField.new(:value)]
280
+ when :interpolated_match_last_line_node
281
+ [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)]
282
+ when :interpolated_regular_expression_node
283
+ [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)]
284
+ when :interpolated_string_node
285
+ [FlagsField.new(:flags, [:frozen?, :mutable?]), OptionalLocationField.new(:opening_loc), NodeListField.new(:parts), OptionalLocationField.new(:closing_loc)]
286
+ when :interpolated_symbol_node
287
+ [OptionalLocationField.new(:opening_loc), NodeListField.new(:parts), OptionalLocationField.new(:closing_loc)]
288
+ when :interpolated_x_string_node
289
+ [LocationField.new(:opening_loc), NodeListField.new(:parts), LocationField.new(:closing_loc)]
290
+ when :it_parameters_node
291
+ []
292
+ when :keyword_hash_node
293
+ [FlagsField.new(:flags, [:symbol_keys?]), NodeListField.new(:elements)]
294
+ when :keyword_rest_parameter_node
295
+ [FlagsField.new(:flags, [:repeated_parameter?]), OptionalConstantField.new(:name), OptionalLocationField.new(:name_loc), LocationField.new(:operator_loc)]
296
+ when :lambda_node
297
+ [ConstantListField.new(:locals), LocationField.new(:operator_loc), LocationField.new(:opening_loc), LocationField.new(:closing_loc), OptionalNodeField.new(:parameters), OptionalNodeField.new(:body)]
298
+ when :local_variable_and_write_node
299
+ [LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value), ConstantField.new(:name), UInt32Field.new(:depth)]
300
+ when :local_variable_operator_write_node
301
+ [LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value), ConstantField.new(:name), ConstantField.new(:operator), UInt32Field.new(:depth)]
302
+ when :local_variable_or_write_node
303
+ [LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value), ConstantField.new(:name), UInt32Field.new(:depth)]
304
+ when :local_variable_read_node
305
+ [ConstantField.new(:name), UInt32Field.new(:depth)]
306
+ when :local_variable_target_node
307
+ [ConstantField.new(:name), UInt32Field.new(:depth)]
308
+ when :local_variable_write_node
309
+ [ConstantField.new(:name), UInt32Field.new(:depth), LocationField.new(:name_loc), NodeField.new(:value), LocationField.new(:operator_loc)]
310
+ when :match_last_line_node
311
+ [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)]
312
+ when :match_predicate_node
313
+ [NodeField.new(:value), NodeField.new(:pattern), LocationField.new(:operator_loc)]
314
+ when :match_required_node
315
+ [NodeField.new(:value), NodeField.new(:pattern), LocationField.new(:operator_loc)]
316
+ when :match_write_node
317
+ [NodeField.new(:call), NodeListField.new(:targets)]
318
+ when :missing_node
319
+ []
320
+ when :module_node
321
+ [ConstantListField.new(:locals), LocationField.new(:module_keyword_loc), NodeField.new(:constant_path), OptionalNodeField.new(:body), LocationField.new(:end_keyword_loc), ConstantField.new(:name)]
322
+ when :multi_target_node
323
+ [NodeListField.new(:lefts), OptionalNodeField.new(:rest), NodeListField.new(:rights), OptionalLocationField.new(:lparen_loc), OptionalLocationField.new(:rparen_loc)]
324
+ when :multi_write_node
325
+ [NodeListField.new(:lefts), OptionalNodeField.new(:rest), NodeListField.new(:rights), OptionalLocationField.new(:lparen_loc), OptionalLocationField.new(:rparen_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
326
+ when :next_node
327
+ [OptionalNodeField.new(:arguments), LocationField.new(:keyword_loc)]
328
+ when :nil_node
329
+ []
330
+ when :no_keywords_parameter_node
331
+ [LocationField.new(:operator_loc), LocationField.new(:keyword_loc)]
332
+ when :numbered_parameters_node
333
+ [UInt8Field.new(:maximum)]
334
+ when :numbered_reference_read_node
335
+ [UInt32Field.new(:number)]
336
+ when :optional_keyword_parameter_node
337
+ [FlagsField.new(:flags, [:repeated_parameter?]), ConstantField.new(:name), LocationField.new(:name_loc), NodeField.new(:value)]
338
+ when :optional_parameter_node
339
+ [FlagsField.new(:flags, [:repeated_parameter?]), ConstantField.new(:name), LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value)]
340
+ when :or_node
341
+ [NodeField.new(:left), NodeField.new(:right), LocationField.new(:operator_loc)]
342
+ when :parameters_node
343
+ [NodeListField.new(:requireds), NodeListField.new(:optionals), OptionalNodeField.new(:rest), NodeListField.new(:posts), NodeListField.new(:keywords), OptionalNodeField.new(:keyword_rest), OptionalNodeField.new(:block)]
344
+ when :parentheses_node
345
+ [OptionalNodeField.new(:body), LocationField.new(:opening_loc), LocationField.new(:closing_loc)]
346
+ when :pinned_expression_node
347
+ [NodeField.new(:expression), LocationField.new(:operator_loc), LocationField.new(:lparen_loc), LocationField.new(:rparen_loc)]
348
+ when :pinned_variable_node
349
+ [NodeField.new(:variable), LocationField.new(:operator_loc)]
350
+ when :post_execution_node
351
+ [OptionalNodeField.new(:statements), LocationField.new(:keyword_loc), LocationField.new(:opening_loc), LocationField.new(:closing_loc)]
352
+ when :pre_execution_node
353
+ [OptionalNodeField.new(:statements), LocationField.new(:keyword_loc), LocationField.new(:opening_loc), LocationField.new(:closing_loc)]
354
+ when :program_node
355
+ [ConstantListField.new(:locals), NodeField.new(:statements)]
356
+ when :range_node
357
+ [FlagsField.new(:flags, [:exclude_end?]), OptionalNodeField.new(:left), OptionalNodeField.new(:right), LocationField.new(:operator_loc)]
358
+ when :rational_node
359
+ [NodeField.new(:numeric)]
360
+ when :redo_node
361
+ []
362
+ when :regular_expression_node
363
+ [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)]
364
+ when :required_keyword_parameter_node
365
+ [FlagsField.new(:flags, [:repeated_parameter?]), ConstantField.new(:name), LocationField.new(:name_loc)]
366
+ when :required_parameter_node
367
+ [FlagsField.new(:flags, [:repeated_parameter?]), ConstantField.new(:name)]
368
+ when :rescue_modifier_node
369
+ [NodeField.new(:expression), LocationField.new(:keyword_loc), NodeField.new(:rescue_expression)]
370
+ when :rescue_node
371
+ [LocationField.new(:keyword_loc), NodeListField.new(:exceptions), OptionalLocationField.new(:operator_loc), OptionalNodeField.new(:reference), OptionalNodeField.new(:statements), OptionalNodeField.new(:consequent)]
372
+ when :rest_parameter_node
373
+ [FlagsField.new(:flags, [:repeated_parameter?]), OptionalConstantField.new(:name), OptionalLocationField.new(:name_loc), LocationField.new(:operator_loc)]
374
+ when :retry_node
375
+ []
376
+ when :return_node
377
+ [LocationField.new(:keyword_loc), OptionalNodeField.new(:arguments)]
378
+ when :self_node
379
+ []
380
+ when :shareable_constant_node
381
+ [FlagsField.new(:flags, [:literal?, :experimental_everything?, :experimental_copy?]), NodeField.new(:write)]
382
+ when :singleton_class_node
383
+ [ConstantListField.new(:locals), LocationField.new(:class_keyword_loc), LocationField.new(:operator_loc), NodeField.new(:expression), OptionalNodeField.new(:body), LocationField.new(:end_keyword_loc)]
384
+ when :source_encoding_node
385
+ []
386
+ when :source_file_node
387
+ [FlagsField.new(:flags, [:forced_utf8_encoding?, :forced_binary_encoding?, :frozen?, :mutable?]), StringField.new(:filepath)]
388
+ when :source_line_node
389
+ []
390
+ when :splat_node
391
+ [LocationField.new(:operator_loc), OptionalNodeField.new(:expression)]
392
+ when :statements_node
393
+ [NodeListField.new(:body)]
394
+ when :string_node
395
+ [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)]
396
+ when :super_node
397
+ [LocationField.new(:keyword_loc), OptionalLocationField.new(:lparen_loc), OptionalNodeField.new(:arguments), OptionalLocationField.new(:rparen_loc), OptionalNodeField.new(:block)]
398
+ when :symbol_node
399
+ [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)]
400
+ when :true_node
401
+ []
402
+ when :undef_node
403
+ [NodeListField.new(:names), LocationField.new(:keyword_loc)]
404
+ when :unless_node
405
+ [LocationField.new(:keyword_loc), NodeField.new(:predicate), OptionalLocationField.new(:then_keyword_loc), OptionalNodeField.new(:statements), OptionalNodeField.new(:consequent), OptionalLocationField.new(:end_keyword_loc)]
406
+ when :until_node
407
+ [FlagsField.new(:flags, [:begin_modifier?]), LocationField.new(:keyword_loc), OptionalLocationField.new(:closing_loc), NodeField.new(:predicate), OptionalNodeField.new(:statements)]
408
+ when :when_node
409
+ [LocationField.new(:keyword_loc), NodeListField.new(:conditions), OptionalLocationField.new(:then_keyword_loc), OptionalNodeField.new(:statements)]
410
+ when :while_node
411
+ [FlagsField.new(:flags, [:begin_modifier?]), LocationField.new(:keyword_loc), OptionalLocationField.new(:closing_loc), NodeField.new(:predicate), OptionalNodeField.new(:statements)]
412
+ when :x_string_node
413
+ [FlagsField.new(:flags, [:forced_utf8_encoding?, :forced_binary_encoding?]), LocationField.new(:opening_loc), LocationField.new(:content_loc), LocationField.new(:closing_loc), StringField.new(:unescaped)]
414
+ when :yield_node
415
+ [LocationField.new(:keyword_loc), OptionalLocationField.new(:lparen_loc), OptionalNodeField.new(:arguments), OptionalLocationField.new(:rparen_loc)]
416
+ else
417
+ raise "Unknown node type: #{node.type.inspect}"
418
+ end
419
+ end
420
+ end
421
+ end