prism 0.23.0 → 0.25.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/BSDmakefile +58 -0
  3. data/CHANGELOG.md +65 -1
  4. data/Makefile +5 -2
  5. data/README.md +45 -6
  6. data/config.yml +499 -4
  7. data/docs/build_system.md +31 -0
  8. data/docs/configuration.md +2 -0
  9. data/docs/cruby_compilation.md +1 -1
  10. data/docs/parser_translation.md +14 -9
  11. data/docs/releasing.md +3 -3
  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 +2342 -1801
  16. data/ext/prism/api_pack.c +9 -0
  17. data/ext/prism/extconf.rb +27 -11
  18. data/ext/prism/extension.c +313 -66
  19. data/ext/prism/extension.h +5 -4
  20. data/include/prism/ast.h +213 -64
  21. data/include/prism/defines.h +106 -2
  22. data/include/prism/diagnostic.h +134 -71
  23. data/include/prism/encoding.h +22 -4
  24. data/include/prism/node.h +93 -0
  25. data/include/prism/options.h +82 -7
  26. data/include/prism/pack.h +11 -0
  27. data/include/prism/parser.h +198 -53
  28. data/include/prism/prettyprint.h +8 -0
  29. data/include/prism/static_literals.h +118 -0
  30. data/include/prism/util/pm_buffer.h +65 -2
  31. data/include/prism/util/pm_constant_pool.h +18 -1
  32. data/include/prism/util/pm_integer.h +119 -0
  33. data/include/prism/util/pm_list.h +1 -1
  34. data/include/prism/util/pm_newline_list.h +12 -3
  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 +225 -80
  41. data/lib/prism/dispatcher.rb +29 -0
  42. data/lib/prism/dot_visitor.rb +87 -16
  43. data/lib/prism/dsl.rb +315 -300
  44. data/lib/prism/ffi.rb +165 -84
  45. data/lib/prism/lex_compat.rb +17 -15
  46. data/lib/prism/mutation_compiler.rb +11 -0
  47. data/lib/prism/node.rb +4857 -3750
  48. data/lib/prism/node_ext.rb +77 -29
  49. data/lib/prism/pack.rb +4 -0
  50. data/lib/prism/parse_result/comments.rb +34 -17
  51. data/lib/prism/parse_result/newlines.rb +3 -1
  52. data/lib/prism/parse_result.rb +88 -34
  53. data/lib/prism/pattern.rb +16 -4
  54. data/lib/prism/polyfill/string.rb +12 -0
  55. data/lib/prism/serialize.rb +960 -327
  56. data/lib/prism/translation/parser/compiler.rb +152 -50
  57. data/lib/prism/translation/parser/lexer.rb +103 -22
  58. data/lib/prism/translation/parser/rubocop.rb +47 -11
  59. data/lib/prism/translation/parser.rb +134 -10
  60. data/lib/prism/translation/parser33.rb +12 -0
  61. data/lib/prism/translation/parser34.rb +12 -0
  62. data/lib/prism/translation/ripper/sexp.rb +125 -0
  63. data/lib/prism/translation/ripper/shim.rb +5 -0
  64. data/lib/prism/translation/ripper.rb +3248 -379
  65. data/lib/prism/translation/ruby_parser.rb +35 -18
  66. data/lib/prism/translation.rb +3 -1
  67. data/lib/prism/visitor.rb +10 -0
  68. data/lib/prism.rb +8 -2
  69. data/prism.gemspec +35 -4
  70. data/rbi/prism/compiler.rbi +14 -0
  71. data/rbi/prism/desugar_compiler.rbi +5 -0
  72. data/rbi/prism/mutation_compiler.rbi +5 -0
  73. data/rbi/prism/node.rbi +8221 -0
  74. data/rbi/prism/node_ext.rbi +102 -0
  75. data/rbi/prism/parse_result.rbi +304 -0
  76. data/rbi/prism/translation/parser/compiler.rbi +13 -0
  77. data/rbi/prism/translation/ripper/ripper_compiler.rbi +5 -0
  78. data/rbi/prism/translation/ripper.rbi +25 -0
  79. data/rbi/prism/translation/ruby_parser.rbi +11 -0
  80. data/rbi/prism/visitor.rbi +470 -0
  81. data/rbi/prism.rbi +39 -7749
  82. data/sig/prism/compiler.rbs +9 -0
  83. data/sig/prism/dispatcher.rbs +16 -0
  84. data/sig/prism/dot_visitor.rbs +6 -0
  85. data/sig/prism/dsl.rbs +462 -0
  86. data/sig/prism/mutation_compiler.rbs +158 -0
  87. data/sig/prism/node.rbs +3529 -0
  88. data/sig/prism/node_ext.rbs +78 -0
  89. data/sig/prism/pack.rbs +43 -0
  90. data/sig/prism/parse_result.rbs +127 -0
  91. data/sig/prism/pattern.rbs +13 -0
  92. data/sig/prism/serialize.rbs +7 -0
  93. data/sig/prism/visitor.rbs +168 -0
  94. data/sig/prism.rbs +188 -4767
  95. data/src/diagnostic.c +575 -230
  96. data/src/encoding.c +211 -108
  97. data/src/node.c +7526 -447
  98. data/src/options.c +36 -12
  99. data/src/pack.c +33 -17
  100. data/src/prettyprint.c +1297 -1388
  101. data/src/prism.c +3665 -1121
  102. data/src/regexp.c +17 -2
  103. data/src/serialize.c +47 -28
  104. data/src/static_literals.c +552 -0
  105. data/src/token_type.c +1 -0
  106. data/src/util/pm_buffer.c +147 -20
  107. data/src/util/pm_char.c +4 -4
  108. data/src/util/pm_constant_pool.c +35 -11
  109. data/src/util/pm_integer.c +629 -0
  110. data/src/util/pm_list.c +1 -1
  111. data/src/util/pm_newline_list.c +20 -8
  112. data/src/util/pm_string.c +134 -5
  113. data/src/util/pm_string_list.c +2 -2
  114. metadata +37 -6
  115. data/docs/ripper.md +0 -36
  116. data/rbi/prism_static.rbi +0 -207
  117. data/sig/prism_static.rbs +0 -201
@@ -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/dot_visitor.rb.erb
@@ -24,7 +25,7 @@ module Prism
24
25
  if port
25
26
  "<tr><td align=\"left\" colspan=\"2\" port=\"#{name}\">#{name}</td></tr>"
26
27
  else
27
- "<tr><td align=\"left\">#{name}</td><td>#{CGI.escapeHTML(value)}</td></tr>"
28
+ "<tr><td align=\"left\">#{name}</td><td>#{CGI.escapeHTML(value || raise)}</td></tr>"
28
29
  end
29
30
  end
30
31
  end
@@ -1155,9 +1156,7 @@ module Prism
1155
1156
  digraph.edge("#{id}:value -> #{node_id(node.value)};")
1156
1157
 
1157
1158
  # operator_loc
1158
- unless (operator_loc = node.operator_loc).nil?
1159
- table.field("operator_loc", location_inspect(operator_loc))
1160
- end
1159
+ table.field("operator_loc", location_inspect(node.operator_loc))
1161
1160
 
1162
1161
  digraph.nodes << <<~DOT
1163
1162
  #{id} [
@@ -1773,6 +1772,9 @@ module Prism
1773
1772
  table = Table.new("FloatNode")
1774
1773
  id = node_id(node)
1775
1774
 
1775
+ # value
1776
+ table.field("value", node.value.inspect)
1777
+
1776
1778
  digraph.nodes << <<~DOT
1777
1779
  #{id} [
1778
1780
  label=<#{table.to_dot.gsub(/\n/, "\n ")}>
@@ -2580,6 +2582,9 @@ module Prism
2580
2582
  # flags
2581
2583
  table.field("flags", integer_base_flags_inspect(node))
2582
2584
 
2585
+ # value
2586
+ table.field("value", node.value.inspect)
2587
+
2583
2588
  digraph.nodes << <<~DOT
2584
2589
  #{id} [
2585
2590
  label=<#{table.to_dot.gsub(/\n/, "\n ")}>
@@ -2666,6 +2671,9 @@ module Prism
2666
2671
  table = Table.new("InterpolatedStringNode")
2667
2672
  id = node_id(node)
2668
2673
 
2674
+ # flags
2675
+ table.field("flags", interpolated_string_node_flags_inspect(node))
2676
+
2669
2677
  # opening_loc
2670
2678
  unless (opening_loc = node.opening_loc).nil?
2671
2679
  table.field("opening_loc", location_inspect(opening_loc))
@@ -2768,6 +2776,20 @@ module Prism
2768
2776
  super
2769
2777
  end
2770
2778
 
2779
+ # Visit a ItParametersNode node.
2780
+ def visit_it_parameters_node(node)
2781
+ table = Table.new("ItParametersNode")
2782
+ id = node_id(node)
2783
+
2784
+ digraph.nodes << <<~DOT
2785
+ #{id} [
2786
+ label=<#{table.to_dot.gsub(/\n/, "\n ")}>
2787
+ ];
2788
+ DOT
2789
+
2790
+ super
2791
+ end
2792
+
2771
2793
  # Visit a KeywordHashNode node.
2772
2794
  def visit_keyword_hash_node(node)
2773
2795
  table = Table.new("KeywordHashNode")
@@ -4009,6 +4031,27 @@ module Prism
4009
4031
  super
4010
4032
  end
4011
4033
 
4034
+ # Visit a ShareableConstantNode node.
4035
+ def visit_shareable_constant_node(node)
4036
+ table = Table.new("ShareableConstantNode")
4037
+ id = node_id(node)
4038
+
4039
+ # flags
4040
+ table.field("flags", shareable_constant_node_flags_inspect(node))
4041
+
4042
+ # write
4043
+ table.field("write", port: true)
4044
+ digraph.edge("#{id}:write -> #{node_id(node.write)};")
4045
+
4046
+ digraph.nodes << <<~DOT
4047
+ #{id} [
4048
+ label=<#{table.to_dot.gsub(/\n/, "\n ")}>
4049
+ ];
4050
+ DOT
4051
+
4052
+ super
4053
+ end
4054
+
4012
4055
  # Visit a SingletonClassNode node.
4013
4056
  def visit_singleton_class_node(node)
4014
4057
  table = Table.new("SingletonClassNode")
@@ -4064,6 +4107,9 @@ module Prism
4064
4107
  table = Table.new("SourceFileNode")
4065
4108
  id = node_id(node)
4066
4109
 
4110
+ # flags
4111
+ table.field("flags", string_flags_inspect(node))
4112
+
4067
4113
  # filepath
4068
4114
  table.field("filepath", node.filepath.inspect)
4069
4115
 
@@ -4390,6 +4436,11 @@ module Prism
4390
4436
  table.field("conditions", "[]")
4391
4437
  end
4392
4438
 
4439
+ # then_keyword_loc
4440
+ unless (then_keyword_loc = node.then_keyword_loc).nil?
4441
+ table.field("then_keyword_loc", location_inspect(then_keyword_loc))
4442
+ end
4443
+
4393
4444
  # statements
4394
4445
  unless (statements = node.statements).nil?
4395
4446
  table.field("statements", port: true)
@@ -4517,7 +4568,7 @@ module Prism
4517
4568
  # Inspect a node that has arguments_node_flags flags to display the flags as a
4518
4569
  # comma-separated list.
4519
4570
  def arguments_node_flags_inspect(node)
4520
- flags = []
4571
+ flags = [] #: Array[String]
4521
4572
  flags << "contains_keyword_splat" if node.contains_keyword_splat?
4522
4573
  flags.join(", ")
4523
4574
  end
@@ -4525,7 +4576,7 @@ module Prism
4525
4576
  # Inspect a node that has array_node_flags flags to display the flags as a
4526
4577
  # comma-separated list.
4527
4578
  def array_node_flags_inspect(node)
4528
- flags = []
4579
+ flags = [] #: Array[String]
4529
4580
  flags << "contains_splat" if node.contains_splat?
4530
4581
  flags.join(", ")
4531
4582
  end
@@ -4533,7 +4584,7 @@ module Prism
4533
4584
  # Inspect a node that has call_node_flags flags to display the flags as a
4534
4585
  # comma-separated list.
4535
4586
  def call_node_flags_inspect(node)
4536
- flags = []
4587
+ flags = [] #: Array[String]
4537
4588
  flags << "safe_navigation" if node.safe_navigation?
4538
4589
  flags << "variable_call" if node.variable_call?
4539
4590
  flags << "attribute_write" if node.attribute_write?
@@ -4544,7 +4595,7 @@ module Prism
4544
4595
  # Inspect a node that has encoding_flags flags to display the flags as a
4545
4596
  # comma-separated list.
4546
4597
  def encoding_flags_inspect(node)
4547
- flags = []
4598
+ flags = [] #: Array[String]
4548
4599
  flags << "forced_utf8_encoding" if node.forced_utf8_encoding?
4549
4600
  flags << "forced_binary_encoding" if node.forced_binary_encoding?
4550
4601
  flags.join(", ")
@@ -4553,7 +4604,7 @@ module Prism
4553
4604
  # Inspect a node that has integer_base_flags flags to display the flags as a
4554
4605
  # comma-separated list.
4555
4606
  def integer_base_flags_inspect(node)
4556
- flags = []
4607
+ flags = [] #: Array[String]
4557
4608
  flags << "binary" if node.binary?
4558
4609
  flags << "decimal" if node.decimal?
4559
4610
  flags << "octal" if node.octal?
@@ -4561,10 +4612,19 @@ module Prism
4561
4612
  flags.join(", ")
4562
4613
  end
4563
4614
 
4615
+ # Inspect a node that has interpolated_string_node_flags flags to display the flags as a
4616
+ # comma-separated list.
4617
+ def interpolated_string_node_flags_inspect(node)
4618
+ flags = [] #: Array[String]
4619
+ flags << "frozen" if node.frozen?
4620
+ flags << "mutable" if node.mutable?
4621
+ flags.join(", ")
4622
+ end
4623
+
4564
4624
  # Inspect a node that has keyword_hash_node_flags flags to display the flags as a
4565
4625
  # comma-separated list.
4566
4626
  def keyword_hash_node_flags_inspect(node)
4567
- flags = []
4627
+ flags = [] #: Array[String]
4568
4628
  flags << "symbol_keys" if node.symbol_keys?
4569
4629
  flags.join(", ")
4570
4630
  end
@@ -4572,7 +4632,7 @@ module Prism
4572
4632
  # Inspect a node that has loop_flags flags to display the flags as a
4573
4633
  # comma-separated list.
4574
4634
  def loop_flags_inspect(node)
4575
- flags = []
4635
+ flags = [] #: Array[String]
4576
4636
  flags << "begin_modifier" if node.begin_modifier?
4577
4637
  flags.join(", ")
4578
4638
  end
@@ -4580,7 +4640,7 @@ module Prism
4580
4640
  # Inspect a node that has parameter_flags flags to display the flags as a
4581
4641
  # comma-separated list.
4582
4642
  def parameter_flags_inspect(node)
4583
- flags = []
4643
+ flags = [] #: Array[String]
4584
4644
  flags << "repeated_parameter" if node.repeated_parameter?
4585
4645
  flags.join(", ")
4586
4646
  end
@@ -4588,7 +4648,7 @@ module Prism
4588
4648
  # Inspect a node that has range_flags flags to display the flags as a
4589
4649
  # comma-separated list.
4590
4650
  def range_flags_inspect(node)
4591
- flags = []
4651
+ flags = [] #: Array[String]
4592
4652
  flags << "exclude_end" if node.exclude_end?
4593
4653
  flags.join(", ")
4594
4654
  end
@@ -4596,7 +4656,7 @@ module Prism
4596
4656
  # Inspect a node that has regular_expression_flags flags to display the flags as a
4597
4657
  # comma-separated list.
4598
4658
  def regular_expression_flags_inspect(node)
4599
- flags = []
4659
+ flags = [] #: Array[String]
4600
4660
  flags << "ignore_case" if node.ignore_case?
4601
4661
  flags << "extended" if node.extended?
4602
4662
  flags << "multi_line" if node.multi_line?
@@ -4611,20 +4671,31 @@ module Prism
4611
4671
  flags.join(", ")
4612
4672
  end
4613
4673
 
4674
+ # Inspect a node that has shareable_constant_node_flags flags to display the flags as a
4675
+ # comma-separated list.
4676
+ def shareable_constant_node_flags_inspect(node)
4677
+ flags = [] #: Array[String]
4678
+ flags << "literal" if node.literal?
4679
+ flags << "experimental_everything" if node.experimental_everything?
4680
+ flags << "experimental_copy" if node.experimental_copy?
4681
+ flags.join(", ")
4682
+ end
4683
+
4614
4684
  # Inspect a node that has string_flags flags to display the flags as a
4615
4685
  # comma-separated list.
4616
4686
  def string_flags_inspect(node)
4617
- flags = []
4687
+ flags = [] #: Array[String]
4618
4688
  flags << "forced_utf8_encoding" if node.forced_utf8_encoding?
4619
4689
  flags << "forced_binary_encoding" if node.forced_binary_encoding?
4620
4690
  flags << "frozen" if node.frozen?
4691
+ flags << "mutable" if node.mutable?
4621
4692
  flags.join(", ")
4622
4693
  end
4623
4694
 
4624
4695
  # Inspect a node that has symbol_flags flags to display the flags as a
4625
4696
  # comma-separated list.
4626
4697
  def symbol_flags_inspect(node)
4627
- flags = []
4698
+ flags = [] #: Array[String]
4628
4699
  flags << "forced_utf8_encoding" if node.forced_utf8_encoding?
4629
4700
  flags << "forced_binary_encoding" if node.forced_binary_encoding?
4630
4701
  flags << "forced_us_ascii_encoding" if node.forced_us_ascii_encoding?