prism 0.13.0

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