prism 0.24.0 → 0.29.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/BSDmakefile +58 -0
  3. data/CHANGELOG.md +132 -1
  4. data/Makefile +25 -18
  5. data/README.md +45 -6
  6. data/config.yml +828 -25
  7. data/docs/build_system.md +31 -0
  8. data/docs/configuration.md +4 -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 +1037 -936
  16. data/ext/prism/api_pack.c +9 -0
  17. data/ext/prism/extconf.rb +62 -18
  18. data/ext/prism/extension.c +351 -71
  19. data/ext/prism/extension.h +5 -4
  20. data/include/prism/ast.h +539 -101
  21. data/include/prism/defines.h +106 -2
  22. data/include/prism/diagnostic.h +168 -74
  23. data/include/prism/encoding.h +22 -4
  24. data/include/prism/node.h +93 -0
  25. data/include/prism/options.h +84 -9
  26. data/include/prism/pack.h +11 -0
  27. data/include/prism/parser.h +213 -54
  28. data/include/prism/prettyprint.h +8 -0
  29. data/include/prism/static_literals.h +120 -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 +5 -3
  41. data/lib/prism/dispatcher.rb +29 -0
  42. data/lib/prism/dot_visitor.rb +141 -54
  43. data/lib/prism/dsl.rb +48 -36
  44. data/lib/prism/ffi.rb +82 -17
  45. data/lib/prism/inspect_visitor.rb +2156 -0
  46. data/lib/prism/lex_compat.rb +34 -15
  47. data/lib/prism/mutation_compiler.rb +13 -2
  48. data/lib/prism/node.rb +4453 -4459
  49. data/lib/prism/node_ext.rb +249 -30
  50. data/lib/prism/pack.rb +4 -0
  51. data/lib/prism/parse_result/comments.rb +35 -18
  52. data/lib/prism/parse_result/newlines.rb +2 -2
  53. data/lib/prism/parse_result.rb +218 -43
  54. data/lib/prism/pattern.rb +28 -10
  55. data/lib/prism/polyfill/byteindex.rb +13 -0
  56. data/lib/prism/polyfill/unpack1.rb +14 -0
  57. data/lib/prism/reflection.rb +411 -0
  58. data/lib/prism/serialize.rb +480 -112
  59. data/lib/prism/translation/parser/compiler.rb +376 -88
  60. data/lib/prism/translation/parser/lexer.rb +103 -22
  61. data/lib/prism/translation/parser/rubocop.rb +41 -13
  62. data/lib/prism/translation/parser.rb +123 -11
  63. data/lib/prism/translation/parser33.rb +1 -1
  64. data/lib/prism/translation/parser34.rb +1 -1
  65. data/lib/prism/translation/ripper/sexp.rb +125 -0
  66. data/lib/prism/translation/ripper/shim.rb +5 -0
  67. data/lib/prism/translation/ripper.rb +3216 -462
  68. data/lib/prism/translation/ruby_parser.rb +111 -56
  69. data/lib/prism/translation.rb +3 -1
  70. data/lib/prism/visitor.rb +10 -0
  71. data/lib/prism.rb +12 -20
  72. data/prism.gemspec +46 -14
  73. data/rbi/prism/compiler.rbi +12 -0
  74. data/rbi/prism/inspect_visitor.rbi +12 -0
  75. data/rbi/prism/node.rbi +8712 -0
  76. data/rbi/prism/node_ext.rbi +107 -0
  77. data/rbi/prism/parse_result.rbi +358 -0
  78. data/rbi/prism/reflection.rbi +58 -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.rbi +15 -0
  83. data/rbi/prism/visitor.rbi +470 -0
  84. data/rbi/prism.rbi +38 -7748
  85. data/sig/prism/compiler.rbs +9 -0
  86. data/sig/prism/dispatcher.rbs +16 -0
  87. data/sig/prism/dot_visitor.rbs +6 -0
  88. data/sig/prism/dsl.rbs +462 -0
  89. data/sig/prism/inspect_visitor.rbs +22 -0
  90. data/sig/prism/lex_compat.rbs +10 -0
  91. data/sig/prism/mutation_compiler.rbs +158 -0
  92. data/sig/prism/node.rbs +3558 -0
  93. data/sig/prism/node_ext.rbs +82 -0
  94. data/sig/prism/pack.rbs +43 -0
  95. data/sig/prism/parse_result.rbs +160 -0
  96. data/sig/prism/pattern.rbs +13 -0
  97. data/sig/prism/reflection.rbs +50 -0
  98. data/sig/prism/serialize.rbs +6 -0
  99. data/sig/prism/visitor.rbs +168 -0
  100. data/sig/prism.rbs +188 -4767
  101. data/src/diagnostic.c +636 -230
  102. data/src/encoding.c +211 -108
  103. data/src/node.c +7555 -451
  104. data/src/options.c +66 -31
  105. data/src/pack.c +33 -17
  106. data/src/prettyprint.c +1383 -1431
  107. data/src/prism.c +4734 -1310
  108. data/src/regexp.c +17 -2
  109. data/src/serialize.c +68 -46
  110. data/src/static_literals.c +638 -0
  111. data/src/token_type.c +10 -9
  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 +642 -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 -9
  121. data/docs/ripper.md +0 -36
  122. data/include/prism/util/pm_state_stack.h +0 -42
  123. data/lib/prism/node_inspector.rb +0 -68
  124. data/rbi/prism_static.rbi +0 -207
  125. data/sig/prism_static.rbs +0 -201
  126. data/src/util/pm_state_stack.c +0 -25
@@ -6,7 +6,7 @@ module Prism
6
6
  module Translation
7
7
  # This module is the entry-point for converting a prism syntax tree into the
8
8
  # seattlerb/ruby_parser gem's syntax tree.
9
- module RubyParser
9
+ class RubyParser
10
10
  # A prism visitor that builds Sexp objects.
11
11
  class Compiler < ::Prism::Compiler
12
12
  # This is the name of the file that we are compiling. We set it on every
@@ -192,19 +192,19 @@ module Prism
192
192
 
193
193
  if node.opening == "("
194
194
  result.line = node.opening_loc.start_line
195
- result.max_line = node.closing_loc.end_line
195
+ result.line_max = node.closing_loc.end_line
196
196
  shadow_loc = false
197
197
  end
198
198
 
199
199
  if node.locals.any?
200
200
  shadow = s(node, :shadow).concat(visit_all(node.locals))
201
201
  shadow.line = node.locals.first.location.start_line
202
- shadow.max_line = node.locals.last.location.end_line
202
+ shadow.line_max = node.locals.last.location.end_line
203
203
  result << shadow
204
204
 
205
205
  if shadow_loc
206
206
  result.line = shadow.line
207
- result.max_line = shadow.max_line
207
+ result.line_max = shadow.line_max
208
208
  end
209
209
  end
210
210
 
@@ -271,9 +271,9 @@ module Prism
271
271
  # ^^^^^^^^^^^^^^^
272
272
  def visit_call_operator_write_node(node)
273
273
  if op_asgn?(node)
274
- s(node, op_asgn_type(node, :op_asgn), visit(node.receiver), visit_write_value(node.value), node.read_name, node.operator)
274
+ s(node, op_asgn_type(node, :op_asgn), visit(node.receiver), visit_write_value(node.value), node.read_name, node.binary_operator)
275
275
  else
276
- s(node, op_asgn_type(node, :op_asgn2), visit(node.receiver), node.write_name, node.operator, visit_write_value(node.value))
276
+ s(node, op_asgn_type(node, :op_asgn2), visit(node.receiver), node.write_name, node.binary_operator, visit_write_value(node.value))
277
277
  end
278
278
  end
279
279
 
@@ -372,7 +372,7 @@ module Prism
372
372
  # @@foo += bar
373
373
  # ^^^^^^^^^^^^
374
374
  def visit_class_variable_operator_write_node(node)
375
- s(node, class_variable_write_type, node.name, s(node, :call, s(node, :cvar, node.name), node.operator, visit_write_value(node.value)))
375
+ s(node, class_variable_write_type, node.name, s(node, :call, s(node, :cvar, node.name), node.binary_operator, visit_write_value(node.value)))
376
376
  end
377
377
 
378
378
  # @@foo &&= bar
@@ -417,7 +417,7 @@ module Prism
417
417
  # Foo += bar
418
418
  # ^^^^^^^^^^^
419
419
  def visit_constant_operator_write_node(node)
420
- s(node, :cdecl, node.name, s(node, :call, s(node, :const, node.name), node.operator, visit_write_value(node.value)))
420
+ s(node, :cdecl, node.name, s(node, :call, s(node, :const, node.name), node.binary_operator, visit_write_value(node.value)))
421
421
  end
422
422
 
423
423
  # Foo &&= bar
@@ -442,9 +442,9 @@ module Prism
442
442
  # ^^^^^^^^
443
443
  def visit_constant_path_node(node)
444
444
  if node.parent.nil?
445
- s(node, :colon3, node.child.name)
445
+ s(node, :colon3, node.name)
446
446
  else
447
- s(node, :colon2, visit(node.parent), node.child.name)
447
+ s(node, :colon2, visit(node.parent), node.name)
448
448
  end
449
449
  end
450
450
 
@@ -460,7 +460,7 @@ module Prism
460
460
  # Foo::Bar += baz
461
461
  # ^^^^^^^^^^^^^^^
462
462
  def visit_constant_path_operator_write_node(node)
463
- s(node, :op_asgn, visit(node.target), node.operator, visit_write_value(node.value))
463
+ s(node, :op_asgn, visit(node.target), node.binary_operator, visit_write_value(node.value))
464
464
  end
465
465
 
466
466
  # Foo::Bar &&= baz
@@ -627,7 +627,7 @@ module Prism
627
627
  # $foo += bar
628
628
  # ^^^^^^^^^^^
629
629
  def visit_global_variable_operator_write_node(node)
630
- s(node, :gasgn, node.name, s(node, :call, s(node, :gvar, node.name), node.operator, visit(node.value)))
630
+ s(node, :gasgn, node.name, s(node, :call, s(node, :gvar, node.name), node.binary_operator, visit(node.value)))
631
631
  end
632
632
 
633
633
  # $foo &&= bar
@@ -719,7 +719,7 @@ module Prism
719
719
  arglist << visit(node.block) if !node.block.nil?
720
720
  end
721
721
 
722
- s(node, :op_asgn1, visit(node.receiver), arglist, node.operator, visit_write_value(node.value))
722
+ s(node, :op_asgn1, visit(node.receiver), arglist, node.binary_operator, visit_write_value(node.value))
723
723
  end
724
724
 
725
725
  # foo[bar] &&= baz
@@ -775,7 +775,7 @@ module Prism
775
775
  # @foo += bar
776
776
  # ^^^^^^^^^^^
777
777
  def visit_instance_variable_operator_write_node(node)
778
- s(node, :iasgn, node.name, s(node, :call, s(node, :ivar, node.name), node.operator, visit_write_value(node.value)))
778
+ s(node, :iasgn, node.name, s(node, :call, s(node, :ivar, node.name), node.binary_operator, visit_write_value(node.value)))
779
779
  end
780
780
 
781
781
  # @foo &&= bar
@@ -805,17 +805,29 @@ module Prism
805
805
  # if /foo #{bar}/ then end
806
806
  # ^^^^^^^^^^^^
807
807
  def visit_interpolated_match_last_line_node(node)
808
- s(node, :match, s(node, :dregx).concat(visit_interpolated_parts(node.parts)))
808
+ parts = visit_interpolated_parts(node.parts)
809
+ regexp =
810
+ if parts.length == 1
811
+ s(node, :lit, Regexp.new(parts.first, node.options))
812
+ else
813
+ s(node, :dregx).concat(parts).tap do |result|
814
+ options = node.options
815
+ result << options if options != 0
816
+ end
817
+ end
818
+
819
+ s(node, :match, regexp)
809
820
  end
810
821
 
811
822
  # /foo #{bar}/
812
823
  # ^^^^^^^^^^^^
813
824
  def visit_interpolated_regular_expression_node(node)
814
- if node.parts.all? { |part| part.is_a?(StringNode) || (part.is_a?(EmbeddedStatementsNode) && part.statements&.body&.length == 1 && part.statements.body.first.is_a?(StringNode)) }
815
- unescaped = node.parts.map { |part| part.is_a?(StringNode) ? part.unescaped : part.statements.body.first.unescaped }.join
816
- s(node, :lit, Regexp.new(unescaped, node.options))
825
+ parts = visit_interpolated_parts(node.parts)
826
+
827
+ if parts.length == 1
828
+ s(node, :lit, Regexp.new(parts.first, node.options))
817
829
  else
818
- s(node, :dregx).concat(visit_interpolated_parts(node.parts)).tap do |result|
830
+ s(node, :dregx).concat(parts).tap do |result|
819
831
  options = node.options
820
832
  result << options if options != 0
821
833
  end
@@ -825,45 +837,71 @@ module Prism
825
837
  # "foo #{bar}"
826
838
  # ^^^^^^^^^^^^
827
839
  def visit_interpolated_string_node(node)
828
- if (node.parts.all? { |part| part.is_a?(StringNode) || (part.is_a?(EmbeddedStatementsNode) && part.statements&.body&.length == 1 && part.statements.body.first.is_a?(StringNode)) }) ||
829
- (node.opening.nil? && node.parts.all? { |part| part.is_a?(StringNode) && !part.opening_loc.nil? })
830
- unescaped = node.parts.map { |part| part.is_a?(StringNode) ? part.unescaped : part.statements.body.first.unescaped }.join
831
- s(node, :str, unescaped)
832
- else
833
- s(node, :dstr).concat(visit_interpolated_parts(node.parts))
834
- end
840
+ parts = visit_interpolated_parts(node.parts)
841
+ parts.length == 1 ? s(node, :str, parts.first) : s(node, :dstr).concat(parts)
835
842
  end
836
843
 
837
844
  # :"foo #{bar}"
838
845
  # ^^^^^^^^^^^^^
839
846
  def visit_interpolated_symbol_node(node)
840
- if node.parts.all? { |part| part.is_a?(StringNode) || (part.is_a?(EmbeddedStatementsNode) && part.statements&.body&.length == 1 && part.statements.body.first.is_a?(StringNode)) }
841
- unescaped = node.parts.map { |part| part.is_a?(StringNode) ? part.unescaped : part.statements.body.first.unescaped }.join
842
- s(node, :lit, unescaped.to_sym)
843
- else
844
- s(node, :dsym).concat(visit_interpolated_parts(node.parts))
845
- end
847
+ parts = visit_interpolated_parts(node.parts)
848
+ parts.length == 1 ? s(node, :lit, parts.first.to_sym) : s(node, :dsym).concat(parts)
846
849
  end
847
850
 
848
851
  # `foo #{bar}`
849
852
  # ^^^^^^^^^^^^
850
853
  def visit_interpolated_x_string_node(node)
851
- children = visit_interpolated_parts(node.parts)
852
- s(node.heredoc? ? node.parts.first : node, :dxstr).concat(children)
854
+ source = node.heredoc? ? node.parts.first : node
855
+ parts = visit_interpolated_parts(node.parts)
856
+ parts.length == 1 ? s(source, :xstr, parts.first) : s(source, :dxstr).concat(parts)
853
857
  end
854
858
 
855
859
  # Visit the interpolated content of the string-like node.
856
860
  private def visit_interpolated_parts(parts)
857
- parts.each_with_object([]).with_index do |(part, results), index|
858
- if index == 0
859
- if part.is_a?(StringNode)
860
- results << part.unescaped
861
+ visited = []
862
+ parts.each do |part|
863
+ result = visit(part)
864
+
865
+ if result[0] == :evstr && result[1]
866
+ if result[1][0] == :str
867
+ visited << result[1]
868
+ elsif result[1][0] == :dstr
869
+ visited.concat(result[1][1..-1])
870
+ else
871
+ visited << result
872
+ end
873
+ else
874
+ visited << result
875
+ end
876
+ end
877
+
878
+ state = :beginning #: :beginning | :string_content | :interpolated_content
879
+
880
+ visited.each_with_object([]) do |result, results|
881
+ case state
882
+ when :beginning
883
+ if result.is_a?(String)
884
+ results << result
885
+ state = :string_content
886
+ elsif result.is_a?(Array) && result[0] == :str
887
+ results << result[1]
888
+ state = :string_content
861
889
  else
862
890
  results << ""
863
- results << visit(part)
891
+ results << result
892
+ state = :interpolated_content
893
+ end
894
+ when :string_content
895
+ if result.is_a?(String)
896
+ results[0] << result
897
+ elsif result.is_a?(Array) && result[0] == :str
898
+ results[0] << result[1]
899
+ else
900
+ results << result
901
+ state = :interpolated_content
864
902
  end
865
903
  else
866
- results << visit(part)
904
+ results << result
867
905
  end
868
906
  end
869
907
  end
@@ -922,7 +960,7 @@ module Prism
922
960
  # foo += bar
923
961
  # ^^^^^^^^^^
924
962
  def visit_local_variable_operator_write_node(node)
925
- s(node, :lasgn, node.name, s(node, :call, s(node, :lvar, node.name), node.operator, visit_write_value(node.value)))
963
+ s(node, :lasgn, node.name, s(node, :call, s(node, :lvar, node.name), node.binary_operator, visit_write_value(node.value)))
926
964
  end
927
965
 
928
966
  # foo &&= bar
@@ -1274,6 +1312,11 @@ module Prism
1274
1312
  s(node, :self)
1275
1313
  end
1276
1314
 
1315
+ # A shareable constant.
1316
+ def visit_shareable_constant_node(node)
1317
+ visit(node.write)
1318
+ end
1319
+
1277
1320
  # class << self; end
1278
1321
  # ^^^^^^^^^^^^^^^^^^
1279
1322
  def visit_singleton_class_node(node)
@@ -1292,7 +1335,7 @@ module Prism
1292
1335
  # __FILE__
1293
1336
  # ^^^^^^^^
1294
1337
  def visit_source_file_node(node)
1295
- s(node, :str, file)
1338
+ s(node, :str, node.filepath)
1296
1339
  end
1297
1340
 
1298
1341
  # __LINE__
@@ -1407,7 +1450,7 @@ module Prism
1407
1450
 
1408
1451
  if node.heredoc?
1409
1452
  result.line = node.content_loc.start_line
1410
- result.max_line = node.content_loc.end_line
1453
+ result.line_max = node.content_loc.end_line
1411
1454
  end
1412
1455
 
1413
1456
  result
@@ -1434,7 +1477,7 @@ module Prism
1434
1477
  result = Sexp.new(*arguments)
1435
1478
  result.file = file
1436
1479
  result.line = node.location.start_line
1437
- result.max_line = node.location.end_line
1480
+ result.line_max = node.location.end_line
1438
1481
  result
1439
1482
  end
1440
1483
 
@@ -1490,31 +1533,43 @@ module Prism
1490
1533
 
1491
1534
  private_constant :Compiler
1492
1535
 
1536
+ # Parse the given source and translate it into the seattlerb/ruby_parser
1537
+ # gem's Sexp format.
1538
+ def parse(source, filepath = "(string)")
1539
+ translate(Prism.parse(source, filepath: filepath, scopes: [[]]), filepath)
1540
+ end
1541
+
1542
+ # Parse the given file and translate it into the seattlerb/ruby_parser
1543
+ # gem's Sexp format.
1544
+ def parse_file(filepath)
1545
+ translate(Prism.parse_file(filepath, scopes: [[]]), filepath)
1546
+ end
1547
+
1493
1548
  class << self
1494
1549
  # Parse the given source and translate it into the seattlerb/ruby_parser
1495
1550
  # gem's Sexp format.
1496
1551
  def parse(source, filepath = "(string)")
1497
- translate(Prism.parse(source), filepath)
1552
+ new.parse(source, filepath)
1498
1553
  end
1499
1554
 
1500
1555
  # Parse the given file and translate it into the seattlerb/ruby_parser
1501
1556
  # gem's Sexp format.
1502
1557
  def parse_file(filepath)
1503
- translate(Prism.parse_file(filepath), filepath)
1558
+ new.parse_file(filepath)
1504
1559
  end
1560
+ end
1505
1561
 
1506
- private
1507
-
1508
- # Translate the given parse result and filepath into the
1509
- # seattlerb/ruby_parser gem's Sexp format.
1510
- def translate(result, filepath)
1511
- if result.failure?
1512
- error = result.errors.first
1513
- raise ::RubyParser::SyntaxError, "#{filepath}:#{error.location.start_line} :: #{error.message}"
1514
- end
1562
+ private
1515
1563
 
1516
- result.value.accept(Compiler.new(filepath))
1564
+ # Translate the given parse result and filepath into the
1565
+ # seattlerb/ruby_parser gem's Sexp format.
1566
+ def translate(result, filepath)
1567
+ if result.failure?
1568
+ error = result.errors.first
1569
+ raise ::RubyParser::SyntaxError, "#{filepath}:#{error.location.start_line} :: #{error.message}"
1517
1570
  end
1571
+
1572
+ result.value.accept(Compiler.new(filepath))
1518
1573
  end
1519
1574
  end
1520
1575
  end
@@ -3,8 +3,10 @@
3
3
  module Prism
4
4
  # This module is responsible for converting the prism syntax tree into other
5
5
  # syntax trees.
6
- module Translation
6
+ module Translation # steep:ignore
7
7
  autoload :Parser, "prism/translation/parser"
8
+ autoload :Parser33, "prism/translation/parser33"
9
+ autoload :Parser34, "prism/translation/parser34"
8
10
  autoload :Ripper, "prism/translation/ripper"
9
11
  autoload :RubyParser, "prism/translation/ruby_parser"
10
12
  end
data/lib/prism/visitor.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  =begin
3
4
  This file is generated by the templates/template.rb script and should not be
4
5
  modified manually. See templates/lib/prism/visitor.rb.erb
@@ -14,16 +15,19 @@ module Prism
14
15
  # Calls `accept` on the given node if it is not `nil`, which in turn should
15
16
  # call back into this visitor by calling the appropriate `visit_*` method.
16
17
  def visit(node)
18
+ # @type self: _Visitor
17
19
  node&.accept(self)
18
20
  end
19
21
 
20
22
  # Visits each node in `nodes` by calling `accept` on each one.
21
23
  def visit_all(nodes)
24
+ # @type self: _Visitor
22
25
  nodes.each { |node| node&.accept(self) }
23
26
  end
24
27
 
25
28
  # Visits the child nodes of `node` by calling `accept` on each one.
26
29
  def visit_child_nodes(node)
30
+ # @type self: _Visitor
27
31
  node.compact_child_nodes.each { |node| node.accept(self) }
28
32
  end
29
33
  end
@@ -309,6 +313,9 @@ module Prism
309
313
  # Visit a InterpolatedXStringNode node
310
314
  alias visit_interpolated_x_string_node visit_child_nodes
311
315
 
316
+ # Visit a ItParametersNode node
317
+ alias visit_it_parameters_node visit_child_nodes
318
+
312
319
  # Visit a KeywordHashNode node
313
320
  alias visit_keyword_hash_node visit_child_nodes
314
321
 
@@ -441,6 +448,9 @@ module Prism
441
448
  # Visit a SelfNode node
442
449
  alias visit_self_node visit_child_nodes
443
450
 
451
+ # Visit a ShareableConstantNode node
452
+ alias visit_shareable_constant_node visit_child_nodes
453
+
444
454
  # Visit a SingletonClassNode node
445
455
  alias visit_singleton_class_node visit_child_nodes
446
456
 
data/lib/prism.rb CHANGED
@@ -18,12 +18,13 @@ module Prism
18
18
  autoload :Dispatcher, "prism/dispatcher"
19
19
  autoload :DotVisitor, "prism/dot_visitor"
20
20
  autoload :DSL, "prism/dsl"
21
+ autoload :InspectVisitor, "prism/inspect_visitor"
21
22
  autoload :LexCompat, "prism/lex_compat"
22
23
  autoload :LexRipper, "prism/lex_compat"
23
24
  autoload :MutationCompiler, "prism/mutation_compiler"
24
- autoload :NodeInspector, "prism/node_inspector"
25
25
  autoload :Pack, "prism/pack"
26
26
  autoload :Pattern, "prism/pattern"
27
+ autoload :Reflection, "prism/reflection"
27
28
  autoload :Serialize, "prism/serialize"
28
29
  autoload :Translation, "prism/translation"
29
30
  autoload :Visitor, "prism/visitor"
@@ -36,7 +37,7 @@ module Prism
36
37
  private_constant :LexRipper
37
38
 
38
39
  # :call-seq:
39
- # Prism::lex_compat(source, **options) -> ParseResult
40
+ # Prism::lex_compat(source, **options) -> LexCompat::Result
40
41
  #
41
42
  # Returns a parse result whose value is an array of tokens that closely
42
43
  # resembles the return value of Ripper::lex. The main difference is that the
@@ -44,7 +45,7 @@ module Prism
44
45
  #
45
46
  # For supported options, see Prism::parse.
46
47
  def self.lex_compat(source, **options)
47
- LexCompat.new(source, **options).result
48
+ LexCompat.new(source, **options).result # steep:ignore
48
49
  end
49
50
 
50
51
  # :call-seq:
@@ -54,7 +55,7 @@ module Prism
54
55
  # returns the same tokens. Raises SyntaxError if the syntax in source is
55
56
  # invalid.
56
57
  def self.lex_ripper(source)
57
- LexRipper.new(source).result
58
+ LexRipper.new(source).result # steep:ignore
58
59
  end
59
60
 
60
61
  # :call-seq:
@@ -64,24 +65,9 @@ module Prism
64
65
  def self.load(source, serialized)
65
66
  Serialize.load(source, serialized)
66
67
  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
68
  end
84
69
 
70
+ require_relative "prism/polyfill/byteindex"
85
71
  require_relative "prism/node"
86
72
  require_relative "prism/node_ext"
87
73
  require_relative "prism/parse_result"
@@ -94,6 +80,12 @@ require_relative "prism/parse_result/newlines"
94
80
  # module that uses FFI to call into the library.
95
81
  if RUBY_ENGINE == "ruby" and !ENV["PRISM_FFI_BACKEND"]
96
82
  require "prism/prism"
83
+
84
+ # The C extension is the default backend on CRuby.
85
+ Prism::BACKEND = :CEXT
97
86
  else
98
87
  require_relative "prism/ffi"
88
+
89
+ # The FFI backend is used on other Ruby implementations.
90
+ Prism::BACKEND = :FFI
99
91
  end
data/prism.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "prism"
5
- spec.version = "0.24.0"
5
+ spec.version = "0.29.0"
6
6
  spec.authors = ["Shopify"]
7
7
  spec.email = ["ruby@shopify.com"]
8
8
 
@@ -14,6 +14,7 @@ Gem::Specification.new do |spec|
14
14
 
15
15
  spec.require_paths = ["lib"]
16
16
  spec.files = [
17
+ "BSDmakefile",
17
18
  "CHANGELOG.md",
18
19
  "CODE_OF_CONDUCT.md",
19
20
  "CONTRIBUTING.md",
@@ -34,7 +35,7 @@ Gem::Specification.new do |spec|
34
35
  "docs/parser_translation.md",
35
36
  "docs/parsing_rules.md",
36
37
  "docs/releasing.md",
37
- "docs/ripper.md",
38
+ "docs/ripper_translation.md",
38
39
  "docs/ruby_api.md",
39
40
  "docs/ruby_parser_translation.md",
40
41
  "docs/serialization.md",
@@ -54,13 +55,14 @@ Gem::Specification.new do |spec|
54
55
  "include/prism/parser.h",
55
56
  "include/prism/prettyprint.h",
56
57
  "include/prism/regexp.h",
58
+ "include/prism/static_literals.h",
57
59
  "include/prism/util/pm_buffer.h",
58
60
  "include/prism/util/pm_char.h",
59
61
  "include/prism/util/pm_constant_pool.h",
62
+ "include/prism/util/pm_integer.h",
60
63
  "include/prism/util/pm_list.h",
61
64
  "include/prism/util/pm_memchr.h",
62
65
  "include/prism/util/pm_newline_list.h",
63
- "include/prism/util/pm_state_stack.h",
64
66
  "include/prism/util/pm_strncasecmp.h",
65
67
  "include/prism/util/pm_string.h",
66
68
  "include/prism/util/pm_string_list.h",
@@ -74,16 +76,19 @@ Gem::Specification.new do |spec|
74
76
  "lib/prism/dot_visitor.rb",
75
77
  "lib/prism/dsl.rb",
76
78
  "lib/prism/ffi.rb",
79
+ "lib/prism/inspect_visitor.rb",
77
80
  "lib/prism/lex_compat.rb",
78
81
  "lib/prism/mutation_compiler.rb",
79
82
  "lib/prism/node_ext.rb",
80
- "lib/prism/node_inspector.rb",
81
83
  "lib/prism/node.rb",
82
84
  "lib/prism/pack.rb",
83
85
  "lib/prism/parse_result.rb",
84
86
  "lib/prism/parse_result/comments.rb",
85
87
  "lib/prism/parse_result/newlines.rb",
86
88
  "lib/prism/pattern.rb",
89
+ "lib/prism/polyfill/byteindex.rb",
90
+ "lib/prism/polyfill/unpack1.rb",
91
+ "lib/prism/reflection.rb",
87
92
  "lib/prism/serialize.rb",
88
93
  "lib/prism/translation.rb",
89
94
  "lib/prism/translation/parser.rb",
@@ -93,34 +98,61 @@ Gem::Specification.new do |spec|
93
98
  "lib/prism/translation/parser/lexer.rb",
94
99
  "lib/prism/translation/parser/rubocop.rb",
95
100
  "lib/prism/translation/ripper.rb",
101
+ "lib/prism/translation/ripper/sexp.rb",
102
+ "lib/prism/translation/ripper/shim.rb",
96
103
  "lib/prism/translation/ruby_parser.rb",
97
104
  "lib/prism/visitor.rb",
105
+ "prism.gemspec",
106
+ "rbi/prism.rbi",
107
+ "rbi/prism/compiler.rbi",
108
+ "rbi/prism/inspect_visitor.rbi",
109
+ "rbi/prism/node_ext.rbi",
110
+ "rbi/prism/node.rbi",
111
+ "rbi/prism/parse_result.rbi",
112
+ "rbi/prism/reflection.rbi",
113
+ "rbi/prism/translation/parser.rbi",
114
+ "rbi/prism/translation/parser33.rbi",
115
+ "rbi/prism/translation/parser34.rbi",
116
+ "rbi/prism/translation/ripper.rbi",
117
+ "rbi/prism/visitor.rbi",
118
+ "sig/prism.rbs",
119
+ "sig/prism/compiler.rbs",
120
+ "sig/prism/dispatcher.rbs",
121
+ "sig/prism/dot_visitor.rbs",
122
+ "sig/prism/dsl.rbs",
123
+ "sig/prism/inspect_visitor.rbs",
124
+ "sig/prism/lex_compat.rbs",
125
+ "sig/prism/mutation_compiler.rbs",
126
+ "sig/prism/node_ext.rbs",
127
+ "sig/prism/node.rbs",
128
+ "sig/prism/pack.rbs",
129
+ "sig/prism/parse_result.rbs",
130
+ "sig/prism/pattern.rbs",
131
+ "sig/prism/reflection.rbs",
132
+ "sig/prism/serialize.rbs",
133
+ "sig/prism/visitor.rbs",
98
134
  "src/diagnostic.c",
99
135
  "src/encoding.c",
100
136
  "src/node.c",
137
+ "src/options.c",
101
138
  "src/pack.c",
102
139
  "src/prettyprint.c",
140
+ "src/prism.c",
103
141
  "src/regexp.c",
104
142
  "src/serialize.c",
143
+ "src/static_literals.c",
105
144
  "src/token_type.c",
106
145
  "src/util/pm_buffer.c",
107
146
  "src/util/pm_char.c",
108
147
  "src/util/pm_constant_pool.c",
148
+ "src/util/pm_integer.c",
109
149
  "src/util/pm_list.c",
110
150
  "src/util/pm_memchr.c",
111
151
  "src/util/pm_newline_list.c",
112
- "src/util/pm_state_stack.c",
113
- "src/util/pm_string.c",
114
152
  "src/util/pm_string_list.c",
153
+ "src/util/pm_string.c",
115
154
  "src/util/pm_strncasecmp.c",
116
- "src/util/pm_strpbrk.c",
117
- "src/options.c",
118
- "src/prism.c",
119
- "prism.gemspec",
120
- "sig/prism.rbs",
121
- "sig/prism_static.rbs",
122
- "rbi/prism.rbi",
123
- "rbi/prism_static.rbi"
155
+ "src/util/pm_strpbrk.c"
124
156
  ]
125
157
 
126
158
  spec.extensions = ["ext/prism/extconf.rb"]
@@ -0,0 +1,12 @@
1
+ # typed: strict
2
+
3
+ class Prism::Compiler
4
+ sig { params(node: T.nilable(Prism::Node)).returns(T.untyped) }
5
+ def visit(node); end
6
+
7
+ sig { params(nodes: T::Array[T.nilable(Prism::Node)]).returns(T::Array[T.untyped]) }
8
+ def visit_all(nodes); end
9
+
10
+ sig { params(node: Prism::Node).returns(T::Array[T.untyped]) }
11
+ def visit_child_nodes(node); end
12
+ end
@@ -0,0 +1,12 @@
1
+ # typed: strict
2
+
3
+ class Prism::InspectVisitor < Prism::Visitor
4
+ sig { params(indent: String).void }
5
+ def initialize(indent = ""); end
6
+
7
+ sig { params(node: Prism::Node).returns(String) }
8
+ def self.compose(node); end
9
+
10
+ sig { returns(String) }
11
+ def compose; end
12
+ end