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
data/lib/prism/debug.rb CHANGED
@@ -55,7 +55,7 @@ module Prism
55
55
  verbose, $VERBOSE = $VERBOSE, nil
56
56
 
57
57
  begin
58
- locals = []
58
+ locals = [] #: Array[Array[Symbol | Integer]]
59
59
  stack = [ISeq.new(RubyVM::InstructionSequence.compile(source).to_a)]
60
60
 
61
61
  while (iseq = stack.pop)
@@ -96,8 +96,8 @@ module Prism
96
96
  # For the given source, parses with prism and returns a list of all of the
97
97
  # sets of local variables that were encountered.
98
98
  def self.prism_locals(source)
99
- locals = []
100
- stack = [Prism.parse(source).value]
99
+ locals = [] #: Array[Array[Symbol | Integer]]
100
+ stack = [Prism.parse(source).value] #: Array[Prism::node]
101
101
 
102
102
  while (node = stack.pop)
103
103
  case node
@@ -202,5 +202,48 @@ module Prism
202
202
  def self.newlines(source)
203
203
  Prism.parse(source).source.offsets
204
204
  end
205
+
206
+ # A wrapping around prism's internal encoding data structures. This is used
207
+ # for reflection and debugging purposes.
208
+ class Encoding
209
+ # The name of the encoding, that can be passed to Encoding.find.
210
+ attr_reader :name
211
+
212
+ # Initialize a new encoding with the given name and whether or not it is
213
+ # a multibyte encoding.
214
+ def initialize(name, multibyte)
215
+ @name = name
216
+ @multibyte = multibyte
217
+ end
218
+
219
+ # Whether or not the encoding is a multibyte encoding.
220
+ def multibyte?
221
+ @multibyte
222
+ end
223
+
224
+ # Returns the number of bytes of the first character in the source string,
225
+ # if it is valid for the encoding. Otherwise, returns 0.
226
+ def width(source)
227
+ Encoding._width(name, source)
228
+ end
229
+
230
+ # Returns true if the first character in the source string is a valid
231
+ # alphanumeric character for the encoding.
232
+ def alnum?(source)
233
+ Encoding._alnum?(name, source)
234
+ end
235
+
236
+ # Returns true if the first character in the source string is a valid
237
+ # alphabetic character for the encoding.
238
+ def alpha?(source)
239
+ Encoding._alpha?(name, source)
240
+ end
241
+
242
+ # Returns true if the first character in the source string is a valid
243
+ # uppercase character for the encoding.
244
+ def upper?(source)
245
+ Encoding._upper?(name, source)
246
+ end
247
+ end
205
248
  end
206
249
  end
@@ -73,6 +73,8 @@ module Prism
73
73
 
74
74
  # Desugar `x += y` to `x = x + y`
75
75
  def compile
76
+ binary_operator_loc = node.binary_operator_loc.chop
77
+
76
78
  write_class.new(
77
79
  source,
78
80
  *arguments,
@@ -82,15 +84,15 @@ module Prism
82
84
  0,
83
85
  read_class.new(source, *arguments, node.name_loc),
84
86
  nil,
85
- node.operator_loc.slice.chomp("="),
86
- node.operator_loc.copy(length: node.operator_loc.length - 1),
87
+ binary_operator_loc.slice.to_sym,
88
+ binary_operator_loc,
87
89
  nil,
88
90
  ArgumentsNode.new(source, 0, [node.value], node.value.location),
89
91
  nil,
90
92
  nil,
91
93
  node.location
92
94
  ),
93
- node.operator_loc.copy(start_offset: node.operator_loc.end_offset - 1, length: 1),
95
+ node.binary_operator_loc.copy(start_offset: node.binary_operator_loc.end_offset - 1, length: 1),
94
96
  node.location
95
97
  )
96
98
  end
@@ -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/dispatcher.rb.erb
@@ -761,6 +762,14 @@ module Prism
761
762
  listeners[:on_interpolated_x_string_node_leave]&.each { |listener| listener.on_interpolated_x_string_node_leave(node) }
762
763
  end
763
764
 
765
+ # Dispatch enter and leave events for ItParametersNode nodes and continue
766
+ # walking the tree.
767
+ def visit_it_parameters_node(node)
768
+ listeners[:on_it_parameters_node_enter]&.each { |listener| listener.on_it_parameters_node_enter(node) }
769
+ super
770
+ listeners[:on_it_parameters_node_leave]&.each { |listener| listener.on_it_parameters_node_leave(node) }
771
+ end
772
+
764
773
  # Dispatch enter and leave events for KeywordHashNode nodes and continue
765
774
  # walking the tree.
766
775
  def visit_keyword_hash_node(node)
@@ -1113,6 +1122,14 @@ module Prism
1113
1122
  listeners[:on_self_node_leave]&.each { |listener| listener.on_self_node_leave(node) }
1114
1123
  end
1115
1124
 
1125
+ # Dispatch enter and leave events for ShareableConstantNode nodes and continue
1126
+ # walking the tree.
1127
+ def visit_shareable_constant_node(node)
1128
+ listeners[:on_shareable_constant_node_enter]&.each { |listener| listener.on_shareable_constant_node_enter(node) }
1129
+ super
1130
+ listeners[:on_shareable_constant_node_leave]&.each { |listener| listener.on_shareable_constant_node_leave(node) }
1131
+ end
1132
+
1116
1133
  # Dispatch enter and leave events for SingletonClassNode nodes and continue
1117
1134
  # walking the tree.
1118
1135
  def visit_singleton_class_node(node)
@@ -1778,6 +1795,12 @@ module Prism
1778
1795
  listeners[:on_interpolated_x_string_node_leave]&.each { |listener| listener.on_interpolated_x_string_node_leave(node) }
1779
1796
  end
1780
1797
 
1798
+ # Dispatch enter and leave events for ItParametersNode nodes.
1799
+ def visit_it_parameters_node(node)
1800
+ listeners[:on_it_parameters_node_enter]&.each { |listener| listener.on_it_parameters_node_enter(node) }
1801
+ listeners[:on_it_parameters_node_leave]&.each { |listener| listener.on_it_parameters_node_leave(node) }
1802
+ end
1803
+
1781
1804
  # Dispatch enter and leave events for KeywordHashNode nodes.
1782
1805
  def visit_keyword_hash_node(node)
1783
1806
  listeners[:on_keyword_hash_node_enter]&.each { |listener| listener.on_keyword_hash_node_enter(node) }
@@ -2042,6 +2065,12 @@ module Prism
2042
2065
  listeners[:on_self_node_leave]&.each { |listener| listener.on_self_node_leave(node) }
2043
2066
  end
2044
2067
 
2068
+ # Dispatch enter and leave events for ShareableConstantNode nodes.
2069
+ def visit_shareable_constant_node(node)
2070
+ listeners[:on_shareable_constant_node_enter]&.each { |listener| listener.on_shareable_constant_node_enter(node) }
2071
+ listeners[:on_shareable_constant_node_leave]&.each { |listener| listener.on_shareable_constant_node_leave(node) }
2072
+ end
2073
+
2045
2074
  # Dispatch enter and leave events for SingletonClassNode nodes.
2046
2075
  def visit_singleton_class_node(node)
2047
2076
  listeners[:on_singleton_class_node_enter]&.each { |listener| listener.on_singleton_class_node_enter(node) }
@@ -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
@@ -764,11 +765,11 @@ module Prism
764
765
  # write_name
765
766
  table.field("write_name", node.write_name.inspect)
766
767
 
767
- # operator
768
- table.field("operator", node.operator.inspect)
768
+ # binary_operator
769
+ table.field("binary_operator", node.binary_operator.inspect)
769
770
 
770
- # operator_loc
771
- table.field("operator_loc", location_inspect(node.operator_loc))
771
+ # binary_operator_loc
772
+ table.field("binary_operator_loc", location_inspect(node.binary_operator_loc))
772
773
 
773
774
  # value
774
775
  table.field("value", port: true)
@@ -1059,15 +1060,15 @@ module Prism
1059
1060
  # name_loc
1060
1061
  table.field("name_loc", location_inspect(node.name_loc))
1061
1062
 
1062
- # operator_loc
1063
- table.field("operator_loc", location_inspect(node.operator_loc))
1063
+ # binary_operator_loc
1064
+ table.field("binary_operator_loc", location_inspect(node.binary_operator_loc))
1064
1065
 
1065
1066
  # value
1066
1067
  table.field("value", port: true)
1067
1068
  digraph.edge("#{id}:value -> #{node_id(node.value)};")
1068
1069
 
1069
- # operator
1070
- table.field("operator", node.operator.inspect)
1070
+ # binary_operator
1071
+ table.field("binary_operator", node.binary_operator.inspect)
1071
1072
 
1072
1073
  digraph.nodes << <<~DOT
1073
1074
  #{id} [
@@ -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} [
@@ -1206,15 +1205,15 @@ module Prism
1206
1205
  # name_loc
1207
1206
  table.field("name_loc", location_inspect(node.name_loc))
1208
1207
 
1209
- # operator_loc
1210
- table.field("operator_loc", location_inspect(node.operator_loc))
1208
+ # binary_operator_loc
1209
+ table.field("binary_operator_loc", location_inspect(node.binary_operator_loc))
1211
1210
 
1212
1211
  # value
1213
1212
  table.field("value", port: true)
1214
1213
  digraph.edge("#{id}:value -> #{node_id(node.value)};")
1215
1214
 
1216
- # operator
1217
- table.field("operator", node.operator.inspect)
1215
+ # binary_operator
1216
+ table.field("binary_operator", node.binary_operator.inspect)
1218
1217
 
1219
1218
  digraph.nodes << <<~DOT
1220
1219
  #{id} [
@@ -1288,13 +1287,15 @@ module Prism
1288
1287
  digraph.edge("#{id}:parent -> #{node_id(parent)};")
1289
1288
  end
1290
1289
 
1291
- # child
1292
- table.field("child", port: true)
1293
- digraph.edge("#{id}:child -> #{node_id(node.child)};")
1290
+ # name
1291
+ table.field("name", node.name.inspect)
1294
1292
 
1295
1293
  # delimiter_loc
1296
1294
  table.field("delimiter_loc", location_inspect(node.delimiter_loc))
1297
1295
 
1296
+ # name_loc
1297
+ table.field("name_loc", location_inspect(node.name_loc))
1298
+
1298
1299
  digraph.nodes << <<~DOT
1299
1300
  #{id} [
1300
1301
  label=<#{table.to_dot.gsub(/\n/, "\n ")}>
@@ -1313,15 +1314,15 @@ module Prism
1313
1314
  table.field("target", port: true)
1314
1315
  digraph.edge("#{id}:target -> #{node_id(node.target)};")
1315
1316
 
1316
- # operator_loc
1317
- table.field("operator_loc", location_inspect(node.operator_loc))
1317
+ # binary_operator_loc
1318
+ table.field("binary_operator_loc", location_inspect(node.binary_operator_loc))
1318
1319
 
1319
1320
  # value
1320
1321
  table.field("value", port: true)
1321
1322
  digraph.edge("#{id}:value -> #{node_id(node.value)};")
1322
1323
 
1323
- # operator
1324
- table.field("operator", node.operator.inspect)
1324
+ # binary_operator
1325
+ table.field("binary_operator", node.binary_operator.inspect)
1325
1326
 
1326
1327
  digraph.nodes << <<~DOT
1327
1328
  #{id} [
@@ -1368,13 +1369,15 @@ module Prism
1368
1369
  digraph.edge("#{id}:parent -> #{node_id(parent)};")
1369
1370
  end
1370
1371
 
1371
- # child
1372
- table.field("child", port: true)
1373
- digraph.edge("#{id}:child -> #{node_id(node.child)};")
1372
+ # name
1373
+ table.field("name", node.name.inspect)
1374
1374
 
1375
1375
  # delimiter_loc
1376
1376
  table.field("delimiter_loc", location_inspect(node.delimiter_loc))
1377
1377
 
1378
+ # name_loc
1379
+ table.field("name_loc", location_inspect(node.name_loc))
1380
+
1378
1381
  digraph.nodes << <<~DOT
1379
1382
  #{id} [
1380
1383
  label=<#{table.to_dot.gsub(/\n/, "\n ")}>
@@ -1773,6 +1776,9 @@ module Prism
1773
1776
  table = Table.new("FloatNode")
1774
1777
  id = node_id(node)
1775
1778
 
1779
+ # value
1780
+ table.field("value", node.value.inspect)
1781
+
1776
1782
  digraph.nodes << <<~DOT
1777
1783
  #{id} [
1778
1784
  label=<#{table.to_dot.gsub(/\n/, "\n ")}>
@@ -1910,15 +1916,15 @@ module Prism
1910
1916
  # name_loc
1911
1917
  table.field("name_loc", location_inspect(node.name_loc))
1912
1918
 
1913
- # operator_loc
1914
- table.field("operator_loc", location_inspect(node.operator_loc))
1919
+ # binary_operator_loc
1920
+ table.field("binary_operator_loc", location_inspect(node.binary_operator_loc))
1915
1921
 
1916
1922
  # value
1917
1923
  table.field("value", port: true)
1918
1924
  digraph.edge("#{id}:value -> #{node_id(node.value)};")
1919
1925
 
1920
- # operator
1921
- table.field("operator", node.operator.inspect)
1926
+ # binary_operator
1927
+ table.field("binary_operator", node.binary_operator.inspect)
1922
1928
 
1923
1929
  digraph.nodes << <<~DOT
1924
1930
  #{id} [
@@ -2316,11 +2322,11 @@ module Prism
2316
2322
  digraph.edge("#{id}:block -> #{node_id(block)};")
2317
2323
  end
2318
2324
 
2319
- # operator
2320
- table.field("operator", node.operator.inspect)
2325
+ # binary_operator
2326
+ table.field("binary_operator", node.binary_operator.inspect)
2321
2327
 
2322
- # operator_loc
2323
- table.field("operator_loc", location_inspect(node.operator_loc))
2328
+ # binary_operator_loc
2329
+ table.field("binary_operator_loc", location_inspect(node.binary_operator_loc))
2324
2330
 
2325
2331
  # value
2326
2332
  table.field("value", port: true)
@@ -2465,15 +2471,15 @@ module Prism
2465
2471
  # name_loc
2466
2472
  table.field("name_loc", location_inspect(node.name_loc))
2467
2473
 
2468
- # operator_loc
2469
- table.field("operator_loc", location_inspect(node.operator_loc))
2474
+ # binary_operator_loc
2475
+ table.field("binary_operator_loc", location_inspect(node.binary_operator_loc))
2470
2476
 
2471
2477
  # value
2472
2478
  table.field("value", port: true)
2473
2479
  digraph.edge("#{id}:value -> #{node_id(node.value)};")
2474
2480
 
2475
- # operator
2476
- table.field("operator", node.operator.inspect)
2481
+ # binary_operator
2482
+ table.field("binary_operator", node.binary_operator.inspect)
2477
2483
 
2478
2484
  digraph.nodes << <<~DOT
2479
2485
  #{id} [
@@ -2580,6 +2586,9 @@ module Prism
2580
2586
  # flags
2581
2587
  table.field("flags", integer_base_flags_inspect(node))
2582
2588
 
2589
+ # value
2590
+ table.field("value", node.value.inspect)
2591
+
2583
2592
  digraph.nodes << <<~DOT
2584
2593
  #{id} [
2585
2594
  label=<#{table.to_dot.gsub(/\n/, "\n ")}>
@@ -2666,6 +2675,9 @@ module Prism
2666
2675
  table = Table.new("InterpolatedStringNode")
2667
2676
  id = node_id(node)
2668
2677
 
2678
+ # flags
2679
+ table.field("flags", interpolated_string_node_flags_inspect(node))
2680
+
2669
2681
  # opening_loc
2670
2682
  unless (opening_loc = node.opening_loc).nil?
2671
2683
  table.field("opening_loc", location_inspect(opening_loc))
@@ -2768,6 +2780,20 @@ module Prism
2768
2780
  super
2769
2781
  end
2770
2782
 
2783
+ # Visit a ItParametersNode node.
2784
+ def visit_it_parameters_node(node)
2785
+ table = Table.new("ItParametersNode")
2786
+ id = node_id(node)
2787
+
2788
+ digraph.nodes << <<~DOT
2789
+ #{id} [
2790
+ label=<#{table.to_dot.gsub(/\n/, "\n ")}>
2791
+ ];
2792
+ DOT
2793
+
2794
+ super
2795
+ end
2796
+
2771
2797
  # Visit a KeywordHashNode node.
2772
2798
  def visit_keyword_hash_node(node)
2773
2799
  table = Table.new("KeywordHashNode")
@@ -2902,8 +2928,8 @@ module Prism
2902
2928
  # name_loc
2903
2929
  table.field("name_loc", location_inspect(node.name_loc))
2904
2930
 
2905
- # operator_loc
2906
- table.field("operator_loc", location_inspect(node.operator_loc))
2931
+ # binary_operator_loc
2932
+ table.field("binary_operator_loc", location_inspect(node.binary_operator_loc))
2907
2933
 
2908
2934
  # value
2909
2935
  table.field("value", port: true)
@@ -2912,8 +2938,8 @@ module Prism
2912
2938
  # name
2913
2939
  table.field("name", node.name.inspect)
2914
2940
 
2915
- # operator
2916
- table.field("operator", node.operator.inspect)
2941
+ # binary_operator
2942
+ table.field("binary_operator", node.binary_operator.inspect)
2917
2943
 
2918
2944
  # depth
2919
2945
  table.field("depth", node.depth.inspect)
@@ -3977,6 +4003,9 @@ module Prism
3977
4003
  table = Table.new("ReturnNode")
3978
4004
  id = node_id(node)
3979
4005
 
4006
+ # flags
4007
+ table.field("flags", return_node_flags_inspect(node))
4008
+
3980
4009
  # keyword_loc
3981
4010
  table.field("keyword_loc", location_inspect(node.keyword_loc))
3982
4011
 
@@ -4009,6 +4038,27 @@ module Prism
4009
4038
  super
4010
4039
  end
4011
4040
 
4041
+ # Visit a ShareableConstantNode node.
4042
+ def visit_shareable_constant_node(node)
4043
+ table = Table.new("ShareableConstantNode")
4044
+ id = node_id(node)
4045
+
4046
+ # flags
4047
+ table.field("flags", shareable_constant_node_flags_inspect(node))
4048
+
4049
+ # write
4050
+ table.field("write", port: true)
4051
+ digraph.edge("#{id}:write -> #{node_id(node.write)};")
4052
+
4053
+ digraph.nodes << <<~DOT
4054
+ #{id} [
4055
+ label=<#{table.to_dot.gsub(/\n/, "\n ")}>
4056
+ ];
4057
+ DOT
4058
+
4059
+ super
4060
+ end
4061
+
4012
4062
  # Visit a SingletonClassNode node.
4013
4063
  def visit_singleton_class_node(node)
4014
4064
  table = Table.new("SingletonClassNode")
@@ -4064,6 +4114,9 @@ module Prism
4064
4114
  table = Table.new("SourceFileNode")
4065
4115
  id = node_id(node)
4066
4116
 
4117
+ # flags
4118
+ table.field("flags", string_flags_inspect(node))
4119
+
4067
4120
  # filepath
4068
4121
  table.field("filepath", node.filepath.inspect)
4069
4122
 
@@ -4390,6 +4443,11 @@ module Prism
4390
4443
  table.field("conditions", "[]")
4391
4444
  end
4392
4445
 
4446
+ # then_keyword_loc
4447
+ unless (then_keyword_loc = node.then_keyword_loc).nil?
4448
+ table.field("then_keyword_loc", location_inspect(then_keyword_loc))
4449
+ end
4450
+
4393
4451
  # statements
4394
4452
  unless (statements = node.statements).nil?
4395
4453
  table.field("statements", port: true)
@@ -4517,7 +4575,8 @@ module Prism
4517
4575
  # Inspect a node that has arguments_node_flags flags to display the flags as a
4518
4576
  # comma-separated list.
4519
4577
  def arguments_node_flags_inspect(node)
4520
- flags = []
4578
+ flags = [] #: Array[String]
4579
+ flags << "contains_keywords" if node.contains_keywords?
4521
4580
  flags << "contains_keyword_splat" if node.contains_keyword_splat?
4522
4581
  flags.join(", ")
4523
4582
  end
@@ -4525,7 +4584,7 @@ module Prism
4525
4584
  # Inspect a node that has array_node_flags flags to display the flags as a
4526
4585
  # comma-separated list.
4527
4586
  def array_node_flags_inspect(node)
4528
- flags = []
4587
+ flags = [] #: Array[String]
4529
4588
  flags << "contains_splat" if node.contains_splat?
4530
4589
  flags.join(", ")
4531
4590
  end
@@ -4533,7 +4592,7 @@ module Prism
4533
4592
  # Inspect a node that has call_node_flags flags to display the flags as a
4534
4593
  # comma-separated list.
4535
4594
  def call_node_flags_inspect(node)
4536
- flags = []
4595
+ flags = [] #: Array[String]
4537
4596
  flags << "safe_navigation" if node.safe_navigation?
4538
4597
  flags << "variable_call" if node.variable_call?
4539
4598
  flags << "attribute_write" if node.attribute_write?
@@ -4544,7 +4603,7 @@ module Prism
4544
4603
  # Inspect a node that has encoding_flags flags to display the flags as a
4545
4604
  # comma-separated list.
4546
4605
  def encoding_flags_inspect(node)
4547
- flags = []
4606
+ flags = [] #: Array[String]
4548
4607
  flags << "forced_utf8_encoding" if node.forced_utf8_encoding?
4549
4608
  flags << "forced_binary_encoding" if node.forced_binary_encoding?
4550
4609
  flags.join(", ")
@@ -4553,7 +4612,7 @@ module Prism
4553
4612
  # Inspect a node that has integer_base_flags flags to display the flags as a
4554
4613
  # comma-separated list.
4555
4614
  def integer_base_flags_inspect(node)
4556
- flags = []
4615
+ flags = [] #: Array[String]
4557
4616
  flags << "binary" if node.binary?
4558
4617
  flags << "decimal" if node.decimal?
4559
4618
  flags << "octal" if node.octal?
@@ -4561,10 +4620,19 @@ module Prism
4561
4620
  flags.join(", ")
4562
4621
  end
4563
4622
 
4623
+ # Inspect a node that has interpolated_string_node_flags flags to display the flags as a
4624
+ # comma-separated list.
4625
+ def interpolated_string_node_flags_inspect(node)
4626
+ flags = [] #: Array[String]
4627
+ flags << "frozen" if node.frozen?
4628
+ flags << "mutable" if node.mutable?
4629
+ flags.join(", ")
4630
+ end
4631
+
4564
4632
  # Inspect a node that has keyword_hash_node_flags flags to display the flags as a
4565
4633
  # comma-separated list.
4566
4634
  def keyword_hash_node_flags_inspect(node)
4567
- flags = []
4635
+ flags = [] #: Array[String]
4568
4636
  flags << "symbol_keys" if node.symbol_keys?
4569
4637
  flags.join(", ")
4570
4638
  end
@@ -4572,7 +4640,7 @@ module Prism
4572
4640
  # Inspect a node that has loop_flags flags to display the flags as a
4573
4641
  # comma-separated list.
4574
4642
  def loop_flags_inspect(node)
4575
- flags = []
4643
+ flags = [] #: Array[String]
4576
4644
  flags << "begin_modifier" if node.begin_modifier?
4577
4645
  flags.join(", ")
4578
4646
  end
@@ -4580,7 +4648,7 @@ module Prism
4580
4648
  # Inspect a node that has parameter_flags flags to display the flags as a
4581
4649
  # comma-separated list.
4582
4650
  def parameter_flags_inspect(node)
4583
- flags = []
4651
+ flags = [] #: Array[String]
4584
4652
  flags << "repeated_parameter" if node.repeated_parameter?
4585
4653
  flags.join(", ")
4586
4654
  end
@@ -4588,7 +4656,7 @@ module Prism
4588
4656
  # Inspect a node that has range_flags flags to display the flags as a
4589
4657
  # comma-separated list.
4590
4658
  def range_flags_inspect(node)
4591
- flags = []
4659
+ flags = [] #: Array[String]
4592
4660
  flags << "exclude_end" if node.exclude_end?
4593
4661
  flags.join(", ")
4594
4662
  end
@@ -4596,7 +4664,7 @@ module Prism
4596
4664
  # Inspect a node that has regular_expression_flags flags to display the flags as a
4597
4665
  # comma-separated list.
4598
4666
  def regular_expression_flags_inspect(node)
4599
- flags = []
4667
+ flags = [] #: Array[String]
4600
4668
  flags << "ignore_case" if node.ignore_case?
4601
4669
  flags << "extended" if node.extended?
4602
4670
  flags << "multi_line" if node.multi_line?
@@ -4611,20 +4679,39 @@ module Prism
4611
4679
  flags.join(", ")
4612
4680
  end
4613
4681
 
4682
+ # Inspect a node that has return_node_flags flags to display the flags as a
4683
+ # comma-separated list.
4684
+ def return_node_flags_inspect(node)
4685
+ flags = [] #: Array[String]
4686
+ flags << "redundant" if node.redundant?
4687
+ flags.join(", ")
4688
+ end
4689
+
4690
+ # Inspect a node that has shareable_constant_node_flags flags to display the flags as a
4691
+ # comma-separated list.
4692
+ def shareable_constant_node_flags_inspect(node)
4693
+ flags = [] #: Array[String]
4694
+ flags << "literal" if node.literal?
4695
+ flags << "experimental_everything" if node.experimental_everything?
4696
+ flags << "experimental_copy" if node.experimental_copy?
4697
+ flags.join(", ")
4698
+ end
4699
+
4614
4700
  # Inspect a node that has string_flags flags to display the flags as a
4615
4701
  # comma-separated list.
4616
4702
  def string_flags_inspect(node)
4617
- flags = []
4703
+ flags = [] #: Array[String]
4618
4704
  flags << "forced_utf8_encoding" if node.forced_utf8_encoding?
4619
4705
  flags << "forced_binary_encoding" if node.forced_binary_encoding?
4620
4706
  flags << "frozen" if node.frozen?
4707
+ flags << "mutable" if node.mutable?
4621
4708
  flags.join(", ")
4622
4709
  end
4623
4710
 
4624
4711
  # Inspect a node that has symbol_flags flags to display the flags as a
4625
4712
  # comma-separated list.
4626
4713
  def symbol_flags_inspect(node)
4627
- flags = []
4714
+ flags = [] #: Array[String]
4628
4715
  flags << "forced_utf8_encoding" if node.forced_utf8_encoding?
4629
4716
  flags << "forced_binary_encoding" if node.forced_binary_encoding?
4630
4717
  flags << "forced_us_ascii_encoding" if node.forced_us_ascii_encoding?