ed-precompiled_prism 1.5.2

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 (154) hide show
  1. checksums.yaml +7 -0
  2. data/BSDmakefile +58 -0
  3. data/CHANGELOG.md +723 -0
  4. data/CODE_OF_CONDUCT.md +76 -0
  5. data/CONTRIBUTING.md +58 -0
  6. data/LICENSE.md +7 -0
  7. data/Makefile +110 -0
  8. data/README.md +143 -0
  9. data/config.yml +4714 -0
  10. data/docs/build_system.md +119 -0
  11. data/docs/configuration.md +68 -0
  12. data/docs/cruby_compilation.md +27 -0
  13. data/docs/design.md +53 -0
  14. data/docs/encoding.md +121 -0
  15. data/docs/fuzzing.md +88 -0
  16. data/docs/heredocs.md +36 -0
  17. data/docs/javascript.md +118 -0
  18. data/docs/local_variable_depth.md +229 -0
  19. data/docs/mapping.md +117 -0
  20. data/docs/parser_translation.md +24 -0
  21. data/docs/parsing_rules.md +22 -0
  22. data/docs/releasing.md +98 -0
  23. data/docs/relocation.md +34 -0
  24. data/docs/ripper_translation.md +72 -0
  25. data/docs/ruby_api.md +44 -0
  26. data/docs/ruby_parser_translation.md +19 -0
  27. data/docs/serialization.md +233 -0
  28. data/docs/testing.md +55 -0
  29. data/ext/prism/api_node.c +6941 -0
  30. data/ext/prism/api_pack.c +276 -0
  31. data/ext/prism/extconf.rb +127 -0
  32. data/ext/prism/extension.c +1419 -0
  33. data/ext/prism/extension.h +19 -0
  34. data/include/prism/ast.h +8220 -0
  35. data/include/prism/defines.h +260 -0
  36. data/include/prism/diagnostic.h +456 -0
  37. data/include/prism/encoding.h +283 -0
  38. data/include/prism/node.h +129 -0
  39. data/include/prism/options.h +482 -0
  40. data/include/prism/pack.h +163 -0
  41. data/include/prism/parser.h +933 -0
  42. data/include/prism/prettyprint.h +34 -0
  43. data/include/prism/regexp.h +43 -0
  44. data/include/prism/static_literals.h +121 -0
  45. data/include/prism/util/pm_buffer.h +236 -0
  46. data/include/prism/util/pm_char.h +204 -0
  47. data/include/prism/util/pm_constant_pool.h +218 -0
  48. data/include/prism/util/pm_integer.h +130 -0
  49. data/include/prism/util/pm_list.h +103 -0
  50. data/include/prism/util/pm_memchr.h +29 -0
  51. data/include/prism/util/pm_newline_list.h +113 -0
  52. data/include/prism/util/pm_string.h +200 -0
  53. data/include/prism/util/pm_strncasecmp.h +32 -0
  54. data/include/prism/util/pm_strpbrk.h +46 -0
  55. data/include/prism/version.h +29 -0
  56. data/include/prism.h +408 -0
  57. data/lib/prism/compiler.rb +801 -0
  58. data/lib/prism/desugar_compiler.rb +392 -0
  59. data/lib/prism/dispatcher.rb +2210 -0
  60. data/lib/prism/dot_visitor.rb +4762 -0
  61. data/lib/prism/dsl.rb +1003 -0
  62. data/lib/prism/ffi.rb +570 -0
  63. data/lib/prism/inspect_visitor.rb +2392 -0
  64. data/lib/prism/lex_compat.rb +928 -0
  65. data/lib/prism/mutation_compiler.rb +772 -0
  66. data/lib/prism/node.rb +18816 -0
  67. data/lib/prism/node_ext.rb +511 -0
  68. data/lib/prism/pack.rb +230 -0
  69. data/lib/prism/parse_result/comments.rb +188 -0
  70. data/lib/prism/parse_result/errors.rb +66 -0
  71. data/lib/prism/parse_result/newlines.rb +155 -0
  72. data/lib/prism/parse_result.rb +911 -0
  73. data/lib/prism/pattern.rb +269 -0
  74. data/lib/prism/polyfill/append_as_bytes.rb +15 -0
  75. data/lib/prism/polyfill/byteindex.rb +13 -0
  76. data/lib/prism/polyfill/scan_byte.rb +14 -0
  77. data/lib/prism/polyfill/unpack1.rb +14 -0
  78. data/lib/prism/polyfill/warn.rb +36 -0
  79. data/lib/prism/reflection.rb +416 -0
  80. data/lib/prism/relocation.rb +505 -0
  81. data/lib/prism/serialize.rb +2398 -0
  82. data/lib/prism/string_query.rb +31 -0
  83. data/lib/prism/translation/parser/builder.rb +62 -0
  84. data/lib/prism/translation/parser/compiler.rb +2234 -0
  85. data/lib/prism/translation/parser/lexer.rb +820 -0
  86. data/lib/prism/translation/parser.rb +374 -0
  87. data/lib/prism/translation/parser33.rb +13 -0
  88. data/lib/prism/translation/parser34.rb +13 -0
  89. data/lib/prism/translation/parser35.rb +13 -0
  90. data/lib/prism/translation/parser_current.rb +24 -0
  91. data/lib/prism/translation/ripper/sexp.rb +126 -0
  92. data/lib/prism/translation/ripper/shim.rb +5 -0
  93. data/lib/prism/translation/ripper.rb +3474 -0
  94. data/lib/prism/translation/ruby_parser.rb +1929 -0
  95. data/lib/prism/translation.rb +16 -0
  96. data/lib/prism/visitor.rb +813 -0
  97. data/lib/prism.rb +97 -0
  98. data/prism.gemspec +174 -0
  99. data/rbi/prism/compiler.rbi +12 -0
  100. data/rbi/prism/dsl.rbi +524 -0
  101. data/rbi/prism/inspect_visitor.rbi +12 -0
  102. data/rbi/prism/node.rbi +8734 -0
  103. data/rbi/prism/node_ext.rbi +107 -0
  104. data/rbi/prism/parse_result.rbi +404 -0
  105. data/rbi/prism/reflection.rbi +58 -0
  106. data/rbi/prism/string_query.rbi +12 -0
  107. data/rbi/prism/translation/parser.rbi +11 -0
  108. data/rbi/prism/translation/parser33.rbi +6 -0
  109. data/rbi/prism/translation/parser34.rbi +6 -0
  110. data/rbi/prism/translation/parser35.rbi +6 -0
  111. data/rbi/prism/translation/ripper.rbi +15 -0
  112. data/rbi/prism/visitor.rbi +473 -0
  113. data/rbi/prism.rbi +66 -0
  114. data/sig/prism/compiler.rbs +9 -0
  115. data/sig/prism/dispatcher.rbs +19 -0
  116. data/sig/prism/dot_visitor.rbs +6 -0
  117. data/sig/prism/dsl.rbs +351 -0
  118. data/sig/prism/inspect_visitor.rbs +22 -0
  119. data/sig/prism/lex_compat.rbs +10 -0
  120. data/sig/prism/mutation_compiler.rbs +159 -0
  121. data/sig/prism/node.rbs +4028 -0
  122. data/sig/prism/node_ext.rbs +149 -0
  123. data/sig/prism/pack.rbs +43 -0
  124. data/sig/prism/parse_result/comments.rbs +38 -0
  125. data/sig/prism/parse_result.rbs +196 -0
  126. data/sig/prism/pattern.rbs +13 -0
  127. data/sig/prism/reflection.rbs +50 -0
  128. data/sig/prism/relocation.rbs +185 -0
  129. data/sig/prism/serialize.rbs +8 -0
  130. data/sig/prism/string_query.rbs +11 -0
  131. data/sig/prism/visitor.rbs +169 -0
  132. data/sig/prism.rbs +254 -0
  133. data/src/diagnostic.c +850 -0
  134. data/src/encoding.c +5235 -0
  135. data/src/node.c +8676 -0
  136. data/src/options.c +328 -0
  137. data/src/pack.c +509 -0
  138. data/src/prettyprint.c +8941 -0
  139. data/src/prism.c +23361 -0
  140. data/src/regexp.c +790 -0
  141. data/src/serialize.c +2268 -0
  142. data/src/static_literals.c +617 -0
  143. data/src/token_type.c +703 -0
  144. data/src/util/pm_buffer.c +357 -0
  145. data/src/util/pm_char.c +318 -0
  146. data/src/util/pm_constant_pool.c +342 -0
  147. data/src/util/pm_integer.c +670 -0
  148. data/src/util/pm_list.c +49 -0
  149. data/src/util/pm_memchr.c +35 -0
  150. data/src/util/pm_newline_list.c +125 -0
  151. data/src/util/pm_string.c +381 -0
  152. data/src/util/pm_strncasecmp.c +36 -0
  153. data/src/util/pm_strpbrk.c +206 -0
  154. metadata +195 -0
@@ -0,0 +1,392 @@
1
+ # frozen_string_literal: true
2
+ # :markup: markdown
3
+
4
+ module Prism
5
+ class DesugarAndWriteNode # :nodoc:
6
+ include DSL
7
+
8
+ attr_reader :node, :default_source, :read_class, :write_class, :arguments
9
+
10
+ def initialize(node, default_source, read_class, write_class, **arguments)
11
+ @node = node
12
+ @default_source = default_source
13
+ @read_class = read_class
14
+ @write_class = write_class
15
+ @arguments = arguments
16
+ end
17
+
18
+ # Desugar `x &&= y` to `x && x = y`
19
+ def compile
20
+ and_node(
21
+ location: node.location,
22
+ left: public_send(read_class, location: node.name_loc, **arguments),
23
+ right: public_send(
24
+ write_class,
25
+ location: node.location,
26
+ **arguments,
27
+ name_loc: node.name_loc,
28
+ value: node.value,
29
+ operator_loc: node.operator_loc
30
+ ),
31
+ operator_loc: node.operator_loc
32
+ )
33
+ end
34
+ end
35
+
36
+ class DesugarOrWriteDefinedNode # :nodoc:
37
+ include DSL
38
+
39
+ attr_reader :node, :default_source, :read_class, :write_class, :arguments
40
+
41
+ def initialize(node, default_source, read_class, write_class, **arguments)
42
+ @node = node
43
+ @default_source = default_source
44
+ @read_class = read_class
45
+ @write_class = write_class
46
+ @arguments = arguments
47
+ end
48
+
49
+ # Desugar `x ||= y` to `defined?(x) ? x : x = y`
50
+ def compile
51
+ if_node(
52
+ location: node.location,
53
+ if_keyword_loc: node.operator_loc,
54
+ predicate: defined_node(
55
+ location: node.name_loc,
56
+ value: public_send(read_class, location: node.name_loc, **arguments),
57
+ keyword_loc: node.operator_loc
58
+ ),
59
+ then_keyword_loc: node.operator_loc,
60
+ statements: statements_node(
61
+ location: node.location,
62
+ body: [public_send(read_class, location: node.name_loc, **arguments)]
63
+ ),
64
+ subsequent: else_node(
65
+ location: node.location,
66
+ else_keyword_loc: node.operator_loc,
67
+ statements: statements_node(
68
+ location: node.location,
69
+ body: [
70
+ public_send(
71
+ write_class,
72
+ location: node.location,
73
+ **arguments,
74
+ name_loc: node.name_loc,
75
+ value: node.value,
76
+ operator_loc: node.operator_loc
77
+ )
78
+ ]
79
+ ),
80
+ end_keyword_loc: node.operator_loc
81
+ ),
82
+ end_keyword_loc: node.operator_loc
83
+ )
84
+ end
85
+ end
86
+
87
+ class DesugarOperatorWriteNode # :nodoc:
88
+ include DSL
89
+
90
+ attr_reader :node, :default_source, :read_class, :write_class, :arguments
91
+
92
+ def initialize(node, default_source, read_class, write_class, **arguments)
93
+ @node = node
94
+ @default_source = default_source
95
+ @read_class = read_class
96
+ @write_class = write_class
97
+ @arguments = arguments
98
+ end
99
+
100
+ # Desugar `x += y` to `x = x + y`
101
+ def compile
102
+ binary_operator_loc = node.binary_operator_loc.chop
103
+
104
+ public_send(
105
+ write_class,
106
+ location: node.location,
107
+ **arguments,
108
+ name_loc: node.name_loc,
109
+ value: call_node(
110
+ location: node.location,
111
+ receiver: public_send(
112
+ read_class,
113
+ location: node.name_loc,
114
+ **arguments
115
+ ),
116
+ name: binary_operator_loc.slice.to_sym,
117
+ message_loc: binary_operator_loc,
118
+ arguments: arguments_node(
119
+ location: node.value.location,
120
+ arguments: [node.value]
121
+ )
122
+ ),
123
+ operator_loc: node.binary_operator_loc.copy(
124
+ start_offset: node.binary_operator_loc.end_offset - 1,
125
+ length: 1
126
+ )
127
+ )
128
+ end
129
+ end
130
+
131
+ class DesugarOrWriteNode # :nodoc:
132
+ include DSL
133
+
134
+ attr_reader :node, :default_source, :read_class, :write_class, :arguments
135
+
136
+ def initialize(node, default_source, read_class, write_class, **arguments)
137
+ @node = node
138
+ @default_source = default_source
139
+ @read_class = read_class
140
+ @write_class = write_class
141
+ @arguments = arguments
142
+ end
143
+
144
+ # Desugar `x ||= y` to `x || x = y`
145
+ def compile
146
+ or_node(
147
+ location: node.location,
148
+ left: public_send(read_class, location: node.name_loc, **arguments),
149
+ right: public_send(
150
+ write_class,
151
+ location: node.location,
152
+ **arguments,
153
+ name_loc: node.name_loc,
154
+ value: node.value,
155
+ operator_loc: node.operator_loc
156
+ ),
157
+ operator_loc: node.operator_loc
158
+ )
159
+ end
160
+ end
161
+
162
+ private_constant :DesugarAndWriteNode, :DesugarOrWriteNode, :DesugarOrWriteDefinedNode, :DesugarOperatorWriteNode
163
+
164
+ class ClassVariableAndWriteNode
165
+ def desugar # :nodoc:
166
+ DesugarAndWriteNode.new(self, source, :class_variable_read_node, :class_variable_write_node, name: name).compile
167
+ end
168
+ end
169
+
170
+ class ClassVariableOrWriteNode
171
+ def desugar # :nodoc:
172
+ DesugarOrWriteDefinedNode.new(self, source, :class_variable_read_node, :class_variable_write_node, name: name).compile
173
+ end
174
+ end
175
+
176
+ class ClassVariableOperatorWriteNode
177
+ def desugar # :nodoc:
178
+ DesugarOperatorWriteNode.new(self, source, :class_variable_read_node, :class_variable_write_node, name: name).compile
179
+ end
180
+ end
181
+
182
+ class ConstantAndWriteNode
183
+ def desugar # :nodoc:
184
+ DesugarAndWriteNode.new(self, source, :constant_read_node, :constant_write_node, name: name).compile
185
+ end
186
+ end
187
+
188
+ class ConstantOrWriteNode
189
+ def desugar # :nodoc:
190
+ DesugarOrWriteDefinedNode.new(self, source, :constant_read_node, :constant_write_node, name: name).compile
191
+ end
192
+ end
193
+
194
+ class ConstantOperatorWriteNode
195
+ def desugar # :nodoc:
196
+ DesugarOperatorWriteNode.new(self, source, :constant_read_node, :constant_write_node, name: name).compile
197
+ end
198
+ end
199
+
200
+ class GlobalVariableAndWriteNode
201
+ def desugar # :nodoc:
202
+ DesugarAndWriteNode.new(self, source, :global_variable_read_node, :global_variable_write_node, name: name).compile
203
+ end
204
+ end
205
+
206
+ class GlobalVariableOrWriteNode
207
+ def desugar # :nodoc:
208
+ DesugarOrWriteDefinedNode.new(self, source, :global_variable_read_node, :global_variable_write_node, name: name).compile
209
+ end
210
+ end
211
+
212
+ class GlobalVariableOperatorWriteNode
213
+ def desugar # :nodoc:
214
+ DesugarOperatorWriteNode.new(self, source, :global_variable_read_node, :global_variable_write_node, name: name).compile
215
+ end
216
+ end
217
+
218
+ class InstanceVariableAndWriteNode
219
+ def desugar # :nodoc:
220
+ DesugarAndWriteNode.new(self, source, :instance_variable_read_node, :instance_variable_write_node, name: name).compile
221
+ end
222
+ end
223
+
224
+ class InstanceVariableOrWriteNode
225
+ def desugar # :nodoc:
226
+ DesugarOrWriteNode.new(self, source, :instance_variable_read_node, :instance_variable_write_node, name: name).compile
227
+ end
228
+ end
229
+
230
+ class InstanceVariableOperatorWriteNode
231
+ def desugar # :nodoc:
232
+ DesugarOperatorWriteNode.new(self, source, :instance_variable_read_node, :instance_variable_write_node, name: name).compile
233
+ end
234
+ end
235
+
236
+ class LocalVariableAndWriteNode
237
+ def desugar # :nodoc:
238
+ DesugarAndWriteNode.new(self, source, :local_variable_read_node, :local_variable_write_node, name: name, depth: depth).compile
239
+ end
240
+ end
241
+
242
+ class LocalVariableOrWriteNode
243
+ def desugar # :nodoc:
244
+ DesugarOrWriteNode.new(self, source, :local_variable_read_node, :local_variable_write_node, name: name, depth: depth).compile
245
+ end
246
+ end
247
+
248
+ class LocalVariableOperatorWriteNode
249
+ def desugar # :nodoc:
250
+ DesugarOperatorWriteNode.new(self, source, :local_variable_read_node, :local_variable_write_node, name: name, depth: depth).compile
251
+ end
252
+ end
253
+
254
+ # DesugarCompiler is a compiler that desugars Ruby code into a more primitive
255
+ # form. This is useful for consumers that want to deal with fewer node types.
256
+ class DesugarCompiler < MutationCompiler
257
+ # @@foo &&= bar
258
+ #
259
+ # becomes
260
+ #
261
+ # @@foo && @@foo = bar
262
+ def visit_class_variable_and_write_node(node)
263
+ node.desugar
264
+ end
265
+
266
+ # @@foo ||= bar
267
+ #
268
+ # becomes
269
+ #
270
+ # defined?(@@foo) ? @@foo : @@foo = bar
271
+ def visit_class_variable_or_write_node(node)
272
+ node.desugar
273
+ end
274
+
275
+ # @@foo += bar
276
+ #
277
+ # becomes
278
+ #
279
+ # @@foo = @@foo + bar
280
+ def visit_class_variable_operator_write_node(node)
281
+ node.desugar
282
+ end
283
+
284
+ # Foo &&= bar
285
+ #
286
+ # becomes
287
+ #
288
+ # Foo && Foo = bar
289
+ def visit_constant_and_write_node(node)
290
+ node.desugar
291
+ end
292
+
293
+ # Foo ||= bar
294
+ #
295
+ # becomes
296
+ #
297
+ # defined?(Foo) ? Foo : Foo = bar
298
+ def visit_constant_or_write_node(node)
299
+ node.desugar
300
+ end
301
+
302
+ # Foo += bar
303
+ #
304
+ # becomes
305
+ #
306
+ # Foo = Foo + bar
307
+ def visit_constant_operator_write_node(node)
308
+ node.desugar
309
+ end
310
+
311
+ # $foo &&= bar
312
+ #
313
+ # becomes
314
+ #
315
+ # $foo && $foo = bar
316
+ def visit_global_variable_and_write_node(node)
317
+ node.desugar
318
+ end
319
+
320
+ # $foo ||= bar
321
+ #
322
+ # becomes
323
+ #
324
+ # defined?($foo) ? $foo : $foo = bar
325
+ def visit_global_variable_or_write_node(node)
326
+ node.desugar
327
+ end
328
+
329
+ # $foo += bar
330
+ #
331
+ # becomes
332
+ #
333
+ # $foo = $foo + bar
334
+ def visit_global_variable_operator_write_node(node)
335
+ node.desugar
336
+ end
337
+
338
+ # @foo &&= bar
339
+ #
340
+ # becomes
341
+ #
342
+ # @foo && @foo = bar
343
+ def visit_instance_variable_and_write_node(node)
344
+ node.desugar
345
+ end
346
+
347
+ # @foo ||= bar
348
+ #
349
+ # becomes
350
+ #
351
+ # @foo || @foo = bar
352
+ def visit_instance_variable_or_write_node(node)
353
+ node.desugar
354
+ end
355
+
356
+ # @foo += bar
357
+ #
358
+ # becomes
359
+ #
360
+ # @foo = @foo + bar
361
+ def visit_instance_variable_operator_write_node(node)
362
+ node.desugar
363
+ end
364
+
365
+ # foo &&= bar
366
+ #
367
+ # becomes
368
+ #
369
+ # foo && foo = bar
370
+ def visit_local_variable_and_write_node(node)
371
+ node.desugar
372
+ end
373
+
374
+ # foo ||= bar
375
+ #
376
+ # becomes
377
+ #
378
+ # foo || foo = bar
379
+ def visit_local_variable_or_write_node(node)
380
+ node.desugar
381
+ end
382
+
383
+ # foo += bar
384
+ #
385
+ # becomes
386
+ #
387
+ # foo = foo + bar
388
+ def visit_local_variable_operator_write_node(node)
389
+ node.desugar
390
+ end
391
+ end
392
+ end