jruby-prism-parser 0.23.0.pre.SNAPSHOT-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +401 -0
  3. data/CODE_OF_CONDUCT.md +76 -0
  4. data/CONTRIBUTING.md +62 -0
  5. data/LICENSE.md +7 -0
  6. data/Makefile +101 -0
  7. data/README.md +98 -0
  8. data/config.yml +2902 -0
  9. data/docs/build_system.md +91 -0
  10. data/docs/configuration.md +64 -0
  11. data/docs/cruby_compilation.md +27 -0
  12. data/docs/design.md +53 -0
  13. data/docs/encoding.md +121 -0
  14. data/docs/fuzzing.md +88 -0
  15. data/docs/heredocs.md +36 -0
  16. data/docs/javascript.md +118 -0
  17. data/docs/local_variable_depth.md +229 -0
  18. data/docs/mapping.md +117 -0
  19. data/docs/parser_translation.md +34 -0
  20. data/docs/parsing_rules.md +19 -0
  21. data/docs/releasing.md +98 -0
  22. data/docs/ripper.md +36 -0
  23. data/docs/ruby_api.md +43 -0
  24. data/docs/ruby_parser_translation.md +19 -0
  25. data/docs/serialization.md +209 -0
  26. data/docs/testing.md +55 -0
  27. data/ext/prism/api_node.c +5098 -0
  28. data/ext/prism/api_pack.c +267 -0
  29. data/ext/prism/extconf.rb +110 -0
  30. data/ext/prism/extension.c +1155 -0
  31. data/ext/prism/extension.h +18 -0
  32. data/include/prism/ast.h +5807 -0
  33. data/include/prism/defines.h +102 -0
  34. data/include/prism/diagnostic.h +339 -0
  35. data/include/prism/encoding.h +265 -0
  36. data/include/prism/node.h +57 -0
  37. data/include/prism/options.h +230 -0
  38. data/include/prism/pack.h +152 -0
  39. data/include/prism/parser.h +732 -0
  40. data/include/prism/prettyprint.h +26 -0
  41. data/include/prism/regexp.h +33 -0
  42. data/include/prism/util/pm_buffer.h +155 -0
  43. data/include/prism/util/pm_char.h +205 -0
  44. data/include/prism/util/pm_constant_pool.h +209 -0
  45. data/include/prism/util/pm_list.h +97 -0
  46. data/include/prism/util/pm_memchr.h +29 -0
  47. data/include/prism/util/pm_newline_list.h +93 -0
  48. data/include/prism/util/pm_state_stack.h +42 -0
  49. data/include/prism/util/pm_string.h +150 -0
  50. data/include/prism/util/pm_string_list.h +44 -0
  51. data/include/prism/util/pm_strncasecmp.h +32 -0
  52. data/include/prism/util/pm_strpbrk.h +46 -0
  53. data/include/prism/version.h +29 -0
  54. data/include/prism.h +289 -0
  55. data/jruby-prism.jar +0 -0
  56. data/lib/prism/compiler.rb +486 -0
  57. data/lib/prism/debug.rb +206 -0
  58. data/lib/prism/desugar_compiler.rb +207 -0
  59. data/lib/prism/dispatcher.rb +2150 -0
  60. data/lib/prism/dot_visitor.rb +4634 -0
  61. data/lib/prism/dsl.rb +785 -0
  62. data/lib/prism/ffi.rb +346 -0
  63. data/lib/prism/lex_compat.rb +908 -0
  64. data/lib/prism/mutation_compiler.rb +753 -0
  65. data/lib/prism/node.rb +17864 -0
  66. data/lib/prism/node_ext.rb +212 -0
  67. data/lib/prism/node_inspector.rb +68 -0
  68. data/lib/prism/pack.rb +224 -0
  69. data/lib/prism/parse_result/comments.rb +177 -0
  70. data/lib/prism/parse_result/newlines.rb +64 -0
  71. data/lib/prism/parse_result.rb +498 -0
  72. data/lib/prism/pattern.rb +250 -0
  73. data/lib/prism/serialize.rb +1354 -0
  74. data/lib/prism/translation/parser/compiler.rb +1838 -0
  75. data/lib/prism/translation/parser/lexer.rb +335 -0
  76. data/lib/prism/translation/parser/rubocop.rb +37 -0
  77. data/lib/prism/translation/parser.rb +178 -0
  78. data/lib/prism/translation/ripper.rb +577 -0
  79. data/lib/prism/translation/ruby_parser.rb +1521 -0
  80. data/lib/prism/translation.rb +11 -0
  81. data/lib/prism/version.rb +3 -0
  82. data/lib/prism/visitor.rb +495 -0
  83. data/lib/prism.rb +99 -0
  84. data/prism.gemspec +135 -0
  85. data/rbi/prism.rbi +7767 -0
  86. data/rbi/prism_static.rbi +207 -0
  87. data/sig/prism.rbs +4773 -0
  88. data/sig/prism_static.rbs +201 -0
  89. data/src/diagnostic.c +400 -0
  90. data/src/encoding.c +5132 -0
  91. data/src/node.c +2786 -0
  92. data/src/options.c +213 -0
  93. data/src/pack.c +493 -0
  94. data/src/prettyprint.c +8881 -0
  95. data/src/prism.c +18406 -0
  96. data/src/regexp.c +638 -0
  97. data/src/serialize.c +1554 -0
  98. data/src/token_type.c +700 -0
  99. data/src/util/pm_buffer.c +190 -0
  100. data/src/util/pm_char.c +318 -0
  101. data/src/util/pm_constant_pool.c +322 -0
  102. data/src/util/pm_list.c +49 -0
  103. data/src/util/pm_memchr.c +35 -0
  104. data/src/util/pm_newline_list.c +84 -0
  105. data/src/util/pm_state_stack.c +25 -0
  106. data/src/util/pm_string.c +203 -0
  107. data/src/util/pm_string_list.c +28 -0
  108. data/src/util/pm_strncasecmp.c +24 -0
  109. data/src/util/pm_strpbrk.c +180 -0
  110. metadata +156 -0
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Prism
4
+ # This module is responsible for converting the prism syntax tree into other
5
+ # syntax trees.
6
+ module Translation
7
+ autoload :Parser, "prism/translation/parser"
8
+ autoload :Ripper, "prism/translation/ripper"
9
+ autoload :RubyParser, "prism/translation/ruby_parser"
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Prism
2
+ VERSION = '0.23.0-SNAPSHOT'
3
+ end
@@ -0,0 +1,495 @@
1
+ # frozen_string_literal: true
2
+ =begin
3
+ This file is generated by the templates/template.rb script and should not be
4
+ modified manually. See templates/lib/prism/visitor.rb.erb
5
+ if you are looking to modify the template
6
+ =end
7
+
8
+ module Prism
9
+ # A class that knows how to walk down the tree. None of the individual visit
10
+ # methods are implemented on this visitor, so it forces the consumer to
11
+ # implement each one that they need. For a default implementation that
12
+ # continues walking the tree, see the Visitor class.
13
+ class BasicVisitor
14
+ # Calls `accept` on the given node if it is not `nil`, which in turn should
15
+ # call back into this visitor by calling the appropriate `visit_*` method.
16
+ def visit(node)
17
+ node&.accept(self)
18
+ end
19
+
20
+ # Visits each node in `nodes` by calling `accept` on each one.
21
+ def visit_all(nodes)
22
+ nodes.each { |node| node&.accept(self) }
23
+ end
24
+
25
+ # Visits the child nodes of `node` by calling `accept` on each one.
26
+ def visit_child_nodes(node)
27
+ node.compact_child_nodes.each { |node| node.accept(self) }
28
+ end
29
+ end
30
+
31
+ # A visitor is a class that provides a default implementation for every accept
32
+ # method defined on the nodes. This means it can walk a tree without the
33
+ # caller needing to define any special handling. This allows you to handle a
34
+ # subset of the tree, while still walking the whole tree.
35
+ #
36
+ # For example, to find all of the method calls that call the `foo` method, you
37
+ # could write:
38
+ #
39
+ # class FooCalls < Prism::Visitor
40
+ # def visit_call_node(node)
41
+ # if node.name == "foo"
42
+ # # Do something with the node
43
+ # end
44
+ #
45
+ # # Call super so that the visitor continues walking the tree
46
+ # super
47
+ # end
48
+ # end
49
+ #
50
+ class Visitor < BasicVisitor
51
+ # Visit a AliasGlobalVariableNode node
52
+ alias visit_alias_global_variable_node visit_child_nodes
53
+
54
+ # Visit a AliasMethodNode node
55
+ alias visit_alias_method_node visit_child_nodes
56
+
57
+ # Visit a AlternationPatternNode node
58
+ alias visit_alternation_pattern_node visit_child_nodes
59
+
60
+ # Visit a AndNode node
61
+ alias visit_and_node visit_child_nodes
62
+
63
+ # Visit a ArgumentsNode node
64
+ alias visit_arguments_node visit_child_nodes
65
+
66
+ # Visit a ArrayNode node
67
+ alias visit_array_node visit_child_nodes
68
+
69
+ # Visit a ArrayPatternNode node
70
+ alias visit_array_pattern_node visit_child_nodes
71
+
72
+ # Visit a AssocNode node
73
+ alias visit_assoc_node visit_child_nodes
74
+
75
+ # Visit a AssocSplatNode node
76
+ alias visit_assoc_splat_node visit_child_nodes
77
+
78
+ # Visit a BackReferenceReadNode node
79
+ alias visit_back_reference_read_node visit_child_nodes
80
+
81
+ # Visit a BeginNode node
82
+ alias visit_begin_node visit_child_nodes
83
+
84
+ # Visit a BlockArgumentNode node
85
+ alias visit_block_argument_node visit_child_nodes
86
+
87
+ # Visit a BlockLocalVariableNode node
88
+ alias visit_block_local_variable_node visit_child_nodes
89
+
90
+ # Visit a BlockNode node
91
+ alias visit_block_node visit_child_nodes
92
+
93
+ # Visit a BlockParameterNode node
94
+ alias visit_block_parameter_node visit_child_nodes
95
+
96
+ # Visit a BlockParametersNode node
97
+ alias visit_block_parameters_node visit_child_nodes
98
+
99
+ # Visit a BreakNode node
100
+ alias visit_break_node visit_child_nodes
101
+
102
+ # Visit a CallAndWriteNode node
103
+ alias visit_call_and_write_node visit_child_nodes
104
+
105
+ # Visit a CallNode node
106
+ alias visit_call_node visit_child_nodes
107
+
108
+ # Visit a CallOperatorWriteNode node
109
+ alias visit_call_operator_write_node visit_child_nodes
110
+
111
+ # Visit a CallOrWriteNode node
112
+ alias visit_call_or_write_node visit_child_nodes
113
+
114
+ # Visit a CallTargetNode node
115
+ alias visit_call_target_node visit_child_nodes
116
+
117
+ # Visit a CapturePatternNode node
118
+ alias visit_capture_pattern_node visit_child_nodes
119
+
120
+ # Visit a CaseMatchNode node
121
+ alias visit_case_match_node visit_child_nodes
122
+
123
+ # Visit a CaseNode node
124
+ alias visit_case_node visit_child_nodes
125
+
126
+ # Visit a ClassNode node
127
+ alias visit_class_node visit_child_nodes
128
+
129
+ # Visit a ClassVariableAndWriteNode node
130
+ alias visit_class_variable_and_write_node visit_child_nodes
131
+
132
+ # Visit a ClassVariableOperatorWriteNode node
133
+ alias visit_class_variable_operator_write_node visit_child_nodes
134
+
135
+ # Visit a ClassVariableOrWriteNode node
136
+ alias visit_class_variable_or_write_node visit_child_nodes
137
+
138
+ # Visit a ClassVariableReadNode node
139
+ alias visit_class_variable_read_node visit_child_nodes
140
+
141
+ # Visit a ClassVariableTargetNode node
142
+ alias visit_class_variable_target_node visit_child_nodes
143
+
144
+ # Visit a ClassVariableWriteNode node
145
+ alias visit_class_variable_write_node visit_child_nodes
146
+
147
+ # Visit a ConstantAndWriteNode node
148
+ alias visit_constant_and_write_node visit_child_nodes
149
+
150
+ # Visit a ConstantOperatorWriteNode node
151
+ alias visit_constant_operator_write_node visit_child_nodes
152
+
153
+ # Visit a ConstantOrWriteNode node
154
+ alias visit_constant_or_write_node visit_child_nodes
155
+
156
+ # Visit a ConstantPathAndWriteNode node
157
+ alias visit_constant_path_and_write_node visit_child_nodes
158
+
159
+ # Visit a ConstantPathNode node
160
+ alias visit_constant_path_node visit_child_nodes
161
+
162
+ # Visit a ConstantPathOperatorWriteNode node
163
+ alias visit_constant_path_operator_write_node visit_child_nodes
164
+
165
+ # Visit a ConstantPathOrWriteNode node
166
+ alias visit_constant_path_or_write_node visit_child_nodes
167
+
168
+ # Visit a ConstantPathTargetNode node
169
+ alias visit_constant_path_target_node visit_child_nodes
170
+
171
+ # Visit a ConstantPathWriteNode node
172
+ alias visit_constant_path_write_node visit_child_nodes
173
+
174
+ # Visit a ConstantReadNode node
175
+ alias visit_constant_read_node visit_child_nodes
176
+
177
+ # Visit a ConstantTargetNode node
178
+ alias visit_constant_target_node visit_child_nodes
179
+
180
+ # Visit a ConstantWriteNode node
181
+ alias visit_constant_write_node visit_child_nodes
182
+
183
+ # Visit a DefNode node
184
+ alias visit_def_node visit_child_nodes
185
+
186
+ # Visit a DefinedNode node
187
+ alias visit_defined_node visit_child_nodes
188
+
189
+ # Visit a ElseNode node
190
+ alias visit_else_node visit_child_nodes
191
+
192
+ # Visit a EmbeddedStatementsNode node
193
+ alias visit_embedded_statements_node visit_child_nodes
194
+
195
+ # Visit a EmbeddedVariableNode node
196
+ alias visit_embedded_variable_node visit_child_nodes
197
+
198
+ # Visit a EnsureNode node
199
+ alias visit_ensure_node visit_child_nodes
200
+
201
+ # Visit a FalseNode node
202
+ alias visit_false_node visit_child_nodes
203
+
204
+ # Visit a FindPatternNode node
205
+ alias visit_find_pattern_node visit_child_nodes
206
+
207
+ # Visit a FlipFlopNode node
208
+ alias visit_flip_flop_node visit_child_nodes
209
+
210
+ # Visit a FloatNode node
211
+ alias visit_float_node visit_child_nodes
212
+
213
+ # Visit a ForNode node
214
+ alias visit_for_node visit_child_nodes
215
+
216
+ # Visit a ForwardingArgumentsNode node
217
+ alias visit_forwarding_arguments_node visit_child_nodes
218
+
219
+ # Visit a ForwardingParameterNode node
220
+ alias visit_forwarding_parameter_node visit_child_nodes
221
+
222
+ # Visit a ForwardingSuperNode node
223
+ alias visit_forwarding_super_node visit_child_nodes
224
+
225
+ # Visit a GlobalVariableAndWriteNode node
226
+ alias visit_global_variable_and_write_node visit_child_nodes
227
+
228
+ # Visit a GlobalVariableOperatorWriteNode node
229
+ alias visit_global_variable_operator_write_node visit_child_nodes
230
+
231
+ # Visit a GlobalVariableOrWriteNode node
232
+ alias visit_global_variable_or_write_node visit_child_nodes
233
+
234
+ # Visit a GlobalVariableReadNode node
235
+ alias visit_global_variable_read_node visit_child_nodes
236
+
237
+ # Visit a GlobalVariableTargetNode node
238
+ alias visit_global_variable_target_node visit_child_nodes
239
+
240
+ # Visit a GlobalVariableWriteNode node
241
+ alias visit_global_variable_write_node visit_child_nodes
242
+
243
+ # Visit a HashNode node
244
+ alias visit_hash_node visit_child_nodes
245
+
246
+ # Visit a HashPatternNode node
247
+ alias visit_hash_pattern_node visit_child_nodes
248
+
249
+ # Visit a IfNode node
250
+ alias visit_if_node visit_child_nodes
251
+
252
+ # Visit a ImaginaryNode node
253
+ alias visit_imaginary_node visit_child_nodes
254
+
255
+ # Visit a ImplicitNode node
256
+ alias visit_implicit_node visit_child_nodes
257
+
258
+ # Visit a ImplicitRestNode node
259
+ alias visit_implicit_rest_node visit_child_nodes
260
+
261
+ # Visit a InNode node
262
+ alias visit_in_node visit_child_nodes
263
+
264
+ # Visit a IndexAndWriteNode node
265
+ alias visit_index_and_write_node visit_child_nodes
266
+
267
+ # Visit a IndexOperatorWriteNode node
268
+ alias visit_index_operator_write_node visit_child_nodes
269
+
270
+ # Visit a IndexOrWriteNode node
271
+ alias visit_index_or_write_node visit_child_nodes
272
+
273
+ # Visit a IndexTargetNode node
274
+ alias visit_index_target_node visit_child_nodes
275
+
276
+ # Visit a InstanceVariableAndWriteNode node
277
+ alias visit_instance_variable_and_write_node visit_child_nodes
278
+
279
+ # Visit a InstanceVariableOperatorWriteNode node
280
+ alias visit_instance_variable_operator_write_node visit_child_nodes
281
+
282
+ # Visit a InstanceVariableOrWriteNode node
283
+ alias visit_instance_variable_or_write_node visit_child_nodes
284
+
285
+ # Visit a InstanceVariableReadNode node
286
+ alias visit_instance_variable_read_node visit_child_nodes
287
+
288
+ # Visit a InstanceVariableTargetNode node
289
+ alias visit_instance_variable_target_node visit_child_nodes
290
+
291
+ # Visit a InstanceVariableWriteNode node
292
+ alias visit_instance_variable_write_node visit_child_nodes
293
+
294
+ # Visit a IntegerNode node
295
+ alias visit_integer_node visit_child_nodes
296
+
297
+ # Visit a InterpolatedMatchLastLineNode node
298
+ alias visit_interpolated_match_last_line_node visit_child_nodes
299
+
300
+ # Visit a InterpolatedRegularExpressionNode node
301
+ alias visit_interpolated_regular_expression_node visit_child_nodes
302
+
303
+ # Visit a InterpolatedStringNode node
304
+ alias visit_interpolated_string_node visit_child_nodes
305
+
306
+ # Visit a InterpolatedSymbolNode node
307
+ alias visit_interpolated_symbol_node visit_child_nodes
308
+
309
+ # Visit a InterpolatedXStringNode node
310
+ alias visit_interpolated_x_string_node visit_child_nodes
311
+
312
+ # Visit a KeywordHashNode node
313
+ alias visit_keyword_hash_node visit_child_nodes
314
+
315
+ # Visit a KeywordRestParameterNode node
316
+ alias visit_keyword_rest_parameter_node visit_child_nodes
317
+
318
+ # Visit a LambdaNode node
319
+ alias visit_lambda_node visit_child_nodes
320
+
321
+ # Visit a LocalVariableAndWriteNode node
322
+ alias visit_local_variable_and_write_node visit_child_nodes
323
+
324
+ # Visit a LocalVariableOperatorWriteNode node
325
+ alias visit_local_variable_operator_write_node visit_child_nodes
326
+
327
+ # Visit a LocalVariableOrWriteNode node
328
+ alias visit_local_variable_or_write_node visit_child_nodes
329
+
330
+ # Visit a LocalVariableReadNode node
331
+ alias visit_local_variable_read_node visit_child_nodes
332
+
333
+ # Visit a LocalVariableTargetNode node
334
+ alias visit_local_variable_target_node visit_child_nodes
335
+
336
+ # Visit a LocalVariableWriteNode node
337
+ alias visit_local_variable_write_node visit_child_nodes
338
+
339
+ # Visit a MatchLastLineNode node
340
+ alias visit_match_last_line_node visit_child_nodes
341
+
342
+ # Visit a MatchPredicateNode node
343
+ alias visit_match_predicate_node visit_child_nodes
344
+
345
+ # Visit a MatchRequiredNode node
346
+ alias visit_match_required_node visit_child_nodes
347
+
348
+ # Visit a MatchWriteNode node
349
+ alias visit_match_write_node visit_child_nodes
350
+
351
+ # Visit a MissingNode node
352
+ alias visit_missing_node visit_child_nodes
353
+
354
+ # Visit a ModuleNode node
355
+ alias visit_module_node visit_child_nodes
356
+
357
+ # Visit a MultiTargetNode node
358
+ alias visit_multi_target_node visit_child_nodes
359
+
360
+ # Visit a MultiWriteNode node
361
+ alias visit_multi_write_node visit_child_nodes
362
+
363
+ # Visit a NextNode node
364
+ alias visit_next_node visit_child_nodes
365
+
366
+ # Visit a NilNode node
367
+ alias visit_nil_node visit_child_nodes
368
+
369
+ # Visit a NoKeywordsParameterNode node
370
+ alias visit_no_keywords_parameter_node visit_child_nodes
371
+
372
+ # Visit a NumberedParametersNode node
373
+ alias visit_numbered_parameters_node visit_child_nodes
374
+
375
+ # Visit a NumberedReferenceReadNode node
376
+ alias visit_numbered_reference_read_node visit_child_nodes
377
+
378
+ # Visit a OptionalKeywordParameterNode node
379
+ alias visit_optional_keyword_parameter_node visit_child_nodes
380
+
381
+ # Visit a OptionalParameterNode node
382
+ alias visit_optional_parameter_node visit_child_nodes
383
+
384
+ # Visit a OrNode node
385
+ alias visit_or_node visit_child_nodes
386
+
387
+ # Visit a ParametersNode node
388
+ alias visit_parameters_node visit_child_nodes
389
+
390
+ # Visit a ParenthesesNode node
391
+ alias visit_parentheses_node visit_child_nodes
392
+
393
+ # Visit a PinnedExpressionNode node
394
+ alias visit_pinned_expression_node visit_child_nodes
395
+
396
+ # Visit a PinnedVariableNode node
397
+ alias visit_pinned_variable_node visit_child_nodes
398
+
399
+ # Visit a PostExecutionNode node
400
+ alias visit_post_execution_node visit_child_nodes
401
+
402
+ # Visit a PreExecutionNode node
403
+ alias visit_pre_execution_node visit_child_nodes
404
+
405
+ # Visit a ProgramNode node
406
+ alias visit_program_node visit_child_nodes
407
+
408
+ # Visit a RangeNode node
409
+ alias visit_range_node visit_child_nodes
410
+
411
+ # Visit a RationalNode node
412
+ alias visit_rational_node visit_child_nodes
413
+
414
+ # Visit a RedoNode node
415
+ alias visit_redo_node visit_child_nodes
416
+
417
+ # Visit a RegularExpressionNode node
418
+ alias visit_regular_expression_node visit_child_nodes
419
+
420
+ # Visit a RequiredKeywordParameterNode node
421
+ alias visit_required_keyword_parameter_node visit_child_nodes
422
+
423
+ # Visit a RequiredParameterNode node
424
+ alias visit_required_parameter_node visit_child_nodes
425
+
426
+ # Visit a RescueModifierNode node
427
+ alias visit_rescue_modifier_node visit_child_nodes
428
+
429
+ # Visit a RescueNode node
430
+ alias visit_rescue_node visit_child_nodes
431
+
432
+ # Visit a RestParameterNode node
433
+ alias visit_rest_parameter_node visit_child_nodes
434
+
435
+ # Visit a RetryNode node
436
+ alias visit_retry_node visit_child_nodes
437
+
438
+ # Visit a ReturnNode node
439
+ alias visit_return_node visit_child_nodes
440
+
441
+ # Visit a SelfNode node
442
+ alias visit_self_node visit_child_nodes
443
+
444
+ # Visit a SingletonClassNode node
445
+ alias visit_singleton_class_node visit_child_nodes
446
+
447
+ # Visit a SourceEncodingNode node
448
+ alias visit_source_encoding_node visit_child_nodes
449
+
450
+ # Visit a SourceFileNode node
451
+ alias visit_source_file_node visit_child_nodes
452
+
453
+ # Visit a SourceLineNode node
454
+ alias visit_source_line_node visit_child_nodes
455
+
456
+ # Visit a SplatNode node
457
+ alias visit_splat_node visit_child_nodes
458
+
459
+ # Visit a StatementsNode node
460
+ alias visit_statements_node visit_child_nodes
461
+
462
+ # Visit a StringNode node
463
+ alias visit_string_node visit_child_nodes
464
+
465
+ # Visit a SuperNode node
466
+ alias visit_super_node visit_child_nodes
467
+
468
+ # Visit a SymbolNode node
469
+ alias visit_symbol_node visit_child_nodes
470
+
471
+ # Visit a TrueNode node
472
+ alias visit_true_node visit_child_nodes
473
+
474
+ # Visit a UndefNode node
475
+ alias visit_undef_node visit_child_nodes
476
+
477
+ # Visit a UnlessNode node
478
+ alias visit_unless_node visit_child_nodes
479
+
480
+ # Visit a UntilNode node
481
+ alias visit_until_node visit_child_nodes
482
+
483
+ # Visit a WhenNode node
484
+ alias visit_when_node visit_child_nodes
485
+
486
+ # Visit a WhileNode node
487
+ alias visit_while_node visit_child_nodes
488
+
489
+ # Visit a XStringNode node
490
+ alias visit_x_string_node visit_child_nodes
491
+
492
+ # Visit a YieldNode node
493
+ alias visit_yield_node visit_child_nodes
494
+ end
495
+ end
data/lib/prism.rb ADDED
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The Prism Ruby parser.
4
+ #
5
+ # "Parsing Ruby is suddenly manageable!"
6
+ # - You, hopefully
7
+ #
8
+ module Prism
9
+ # There are many files in prism that are templated to handle every node type,
10
+ # which means the files can end up being quite large. We autoload them to make
11
+ # our require speed faster since consuming libraries are unlikely to use all
12
+ # of these features.
13
+
14
+ autoload :BasicVisitor, "prism/visitor"
15
+ autoload :Compiler, "prism/compiler"
16
+ autoload :Debug, "prism/debug"
17
+ autoload :DesugarCompiler, "prism/desugar_compiler"
18
+ autoload :Dispatcher, "prism/dispatcher"
19
+ autoload :DotVisitor, "prism/dot_visitor"
20
+ autoload :DSL, "prism/dsl"
21
+ autoload :LexCompat, "prism/lex_compat"
22
+ autoload :LexRipper, "prism/lex_compat"
23
+ autoload :MutationCompiler, "prism/mutation_compiler"
24
+ autoload :NodeInspector, "prism/node_inspector"
25
+ autoload :Pack, "prism/pack"
26
+ autoload :Pattern, "prism/pattern"
27
+ autoload :Serialize, "prism/serialize"
28
+ autoload :Translation, "prism/translation"
29
+ autoload :Visitor, "prism/visitor"
30
+
31
+ # Some of these constants are not meant to be exposed, so marking them as
32
+ # private here.
33
+
34
+ private_constant :Debug
35
+ private_constant :LexCompat
36
+ private_constant :LexRipper
37
+
38
+ # :call-seq:
39
+ # Prism::lex_compat(source, **options) -> ParseResult
40
+ #
41
+ # Returns a parse result whose value is an array of tokens that closely
42
+ # resembles the return value of Ripper::lex. The main difference is that the
43
+ # `:on_sp` token is not emitted.
44
+ #
45
+ # For supported options, see Prism::parse.
46
+ def self.lex_compat(source, **options)
47
+ LexCompat.new(source, **options).result
48
+ end
49
+
50
+ # :call-seq:
51
+ # Prism::lex_ripper(source) -> Array
52
+ #
53
+ # This lexes with the Ripper lex. It drops any space events but otherwise
54
+ # returns the same tokens. Raises SyntaxError if the syntax in source is
55
+ # invalid.
56
+ def self.lex_ripper(source)
57
+ LexRipper.new(source).result
58
+ end
59
+
60
+ # :call-seq:
61
+ # Prism::load(source, serialized) -> ParseResult
62
+ #
63
+ # Load the serialized AST using the source as a reference into a tree.
64
+ def self.load(source, serialized)
65
+ Serialize.load(source, serialized)
66
+ end
67
+
68
+ # :call-seq:
69
+ # Prism::parse_failure?(source, **options) -> bool
70
+ #
71
+ # Returns true if the source parses with errors.
72
+ def self.parse_failure?(source, **options)
73
+ !parse_success?(source, **options)
74
+ end
75
+
76
+ # :call-seq:
77
+ # Prism::parse_file_failure?(filepath, **options) -> bool
78
+ #
79
+ # Returns true if the file at filepath parses with errors.
80
+ def self.parse_file_failure?(filepath, **options)
81
+ !parse_file_success?(filepath, **options)
82
+ end
83
+ end
84
+
85
+ require_relative "prism/node"
86
+ require_relative "prism/node_ext"
87
+ require_relative "prism/parse_result"
88
+ require_relative "prism/parse_result/comments"
89
+ require_relative "prism/parse_result/newlines"
90
+
91
+ # This is a Ruby implementation of the prism parser. If we're running on CRuby
92
+ # and we haven't explicitly set the PRISM_FFI_BACKEND environment variable, then
93
+ # it's going to require the built library. Otherwise, it's going to require a
94
+ # module that uses FFI to call into the library.
95
+ if RUBY_ENGINE == "ruby" and !ENV["PRISM_FFI_BACKEND"]
96
+ require "prism/prism"
97
+ else
98
+ require_relative "prism/ffi"
99
+ end