prism 0.27.0 → 0.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +45 -1
  3. data/config.yml +68 -44
  4. data/docs/configuration.md +1 -0
  5. data/ext/prism/api_node.c +854 -847
  6. data/ext/prism/extconf.rb +27 -23
  7. data/ext/prism/extension.c +5 -3
  8. data/ext/prism/extension.h +1 -1
  9. data/include/prism/ast.h +70 -48
  10. data/include/prism/diagnostic.h +23 -6
  11. data/include/prism/options.h +2 -2
  12. data/include/prism/parser.h +10 -0
  13. data/include/prism/static_literals.h +8 -6
  14. data/include/prism/version.h +2 -2
  15. data/lib/prism/desugar_compiler.rb +4 -4
  16. data/lib/prism/dot_visitor.rb +54 -38
  17. data/lib/prism/dsl.rb +24 -24
  18. data/lib/prism/ffi.rb +4 -4
  19. data/lib/prism/inspect_visitor.rb +2156 -0
  20. data/lib/prism/lex_compat.rb +1 -1
  21. data/lib/prism/mutation_compiler.rb +2 -2
  22. data/lib/prism/node.rb +737 -1863
  23. data/lib/prism/node_ext.rb +176 -5
  24. data/lib/prism/parse_result/comments.rb +1 -1
  25. data/lib/prism/parse_result/newlines.rb +1 -1
  26. data/lib/prism/parse_result.rb +78 -0
  27. data/lib/prism/pattern.rb +12 -6
  28. data/lib/prism/polyfill/byteindex.rb +13 -0
  29. data/lib/prism/polyfill/unpack1.rb +14 -0
  30. data/lib/prism/reflection.rb +20 -20
  31. data/lib/prism/serialize.rb +32 -15
  32. data/lib/prism/translation/parser/compiler.rb +156 -26
  33. data/lib/prism/translation/parser.rb +7 -7
  34. data/lib/prism/translation/ripper.rb +29 -25
  35. data/lib/prism/translation/ruby_parser.rb +13 -13
  36. data/lib/prism.rb +2 -1
  37. data/prism.gemspec +37 -38
  38. data/rbi/prism/compiler.rbi +3 -5
  39. data/rbi/prism/inspect_visitor.rbi +12 -0
  40. data/rbi/prism/node.rbi +405 -370
  41. data/rbi/prism/node_ext.rbi +5 -0
  42. data/rbi/prism/parse_result.rbi +23 -0
  43. data/rbi/prism/translation/ripper.rbi +1 -11
  44. data/sig/prism/dsl.rbs +12 -12
  45. data/sig/prism/inspect_visitor.rbs +22 -0
  46. data/sig/prism/lex_compat.rbs +10 -0
  47. data/sig/prism/node.rbs +108 -91
  48. data/sig/prism/node_ext.rbs +4 -0
  49. data/sig/prism/parse_result.rbs +12 -0
  50. data/src/diagnostic.c +66 -33
  51. data/src/node.c +89 -64
  52. data/src/options.c +2 -2
  53. data/src/prettyprint.c +109 -66
  54. data/src/prism.c +862 -317
  55. data/src/serialize.c +21 -18
  56. data/src/static_literals.c +120 -34
  57. data/src/token_type.c +6 -6
  58. metadata +8 -9
  59. data/lib/prism/node_inspector.rb +0 -68
  60. data/lib/prism/polyfill/string.rb +0 -12
  61. data/rbi/prism/desugar_compiler.rbi +0 -5
  62. data/rbi/prism/mutation_compiler.rbi +0 -5
  63. data/rbi/prism/translation/parser/compiler.rbi +0 -13
  64. data/rbi/prism/translation/ripper/ripper_compiler.rbi +0 -5
  65. data/rbi/prism/translation/ruby_parser.rbi +0 -11
@@ -765,11 +765,11 @@ module Prism
765
765
  # write_name
766
766
  table.field("write_name", node.write_name.inspect)
767
767
 
768
- # operator
769
- table.field("operator", node.operator.inspect)
768
+ # binary_operator
769
+ table.field("binary_operator", node.binary_operator.inspect)
770
770
 
771
- # operator_loc
772
- 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))
773
773
 
774
774
  # value
775
775
  table.field("value", port: true)
@@ -1060,15 +1060,15 @@ module Prism
1060
1060
  # name_loc
1061
1061
  table.field("name_loc", location_inspect(node.name_loc))
1062
1062
 
1063
- # operator_loc
1064
- 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))
1065
1065
 
1066
1066
  # value
1067
1067
  table.field("value", port: true)
1068
1068
  digraph.edge("#{id}:value -> #{node_id(node.value)};")
1069
1069
 
1070
- # operator
1071
- table.field("operator", node.operator.inspect)
1070
+ # binary_operator
1071
+ table.field("binary_operator", node.binary_operator.inspect)
1072
1072
 
1073
1073
  digraph.nodes << <<~DOT
1074
1074
  #{id} [
@@ -1205,15 +1205,15 @@ module Prism
1205
1205
  # name_loc
1206
1206
  table.field("name_loc", location_inspect(node.name_loc))
1207
1207
 
1208
- # operator_loc
1209
- 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))
1210
1210
 
1211
1211
  # value
1212
1212
  table.field("value", port: true)
1213
1213
  digraph.edge("#{id}:value -> #{node_id(node.value)};")
1214
1214
 
1215
- # operator
1216
- table.field("operator", node.operator.inspect)
1215
+ # binary_operator
1216
+ table.field("binary_operator", node.binary_operator.inspect)
1217
1217
 
1218
1218
  digraph.nodes << <<~DOT
1219
1219
  #{id} [
@@ -1287,13 +1287,15 @@ module Prism
1287
1287
  digraph.edge("#{id}:parent -> #{node_id(parent)};")
1288
1288
  end
1289
1289
 
1290
- # child
1291
- table.field("child", port: true)
1292
- digraph.edge("#{id}:child -> #{node_id(node.child)};")
1290
+ # name
1291
+ table.field("name", node.name.inspect)
1293
1292
 
1294
1293
  # delimiter_loc
1295
1294
  table.field("delimiter_loc", location_inspect(node.delimiter_loc))
1296
1295
 
1296
+ # name_loc
1297
+ table.field("name_loc", location_inspect(node.name_loc))
1298
+
1297
1299
  digraph.nodes << <<~DOT
1298
1300
  #{id} [
1299
1301
  label=<#{table.to_dot.gsub(/\n/, "\n ")}>
@@ -1312,15 +1314,15 @@ module Prism
1312
1314
  table.field("target", port: true)
1313
1315
  digraph.edge("#{id}:target -> #{node_id(node.target)};")
1314
1316
 
1315
- # operator_loc
1316
- 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))
1317
1319
 
1318
1320
  # value
1319
1321
  table.field("value", port: true)
1320
1322
  digraph.edge("#{id}:value -> #{node_id(node.value)};")
1321
1323
 
1322
- # operator
1323
- table.field("operator", node.operator.inspect)
1324
+ # binary_operator
1325
+ table.field("binary_operator", node.binary_operator.inspect)
1324
1326
 
1325
1327
  digraph.nodes << <<~DOT
1326
1328
  #{id} [
@@ -1367,13 +1369,15 @@ module Prism
1367
1369
  digraph.edge("#{id}:parent -> #{node_id(parent)};")
1368
1370
  end
1369
1371
 
1370
- # child
1371
- table.field("child", port: true)
1372
- digraph.edge("#{id}:child -> #{node_id(node.child)};")
1372
+ # name
1373
+ table.field("name", node.name.inspect)
1373
1374
 
1374
1375
  # delimiter_loc
1375
1376
  table.field("delimiter_loc", location_inspect(node.delimiter_loc))
1376
1377
 
1378
+ # name_loc
1379
+ table.field("name_loc", location_inspect(node.name_loc))
1380
+
1377
1381
  digraph.nodes << <<~DOT
1378
1382
  #{id} [
1379
1383
  label=<#{table.to_dot.gsub(/\n/, "\n ")}>
@@ -1912,15 +1916,15 @@ module Prism
1912
1916
  # name_loc
1913
1917
  table.field("name_loc", location_inspect(node.name_loc))
1914
1918
 
1915
- # operator_loc
1916
- 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))
1917
1921
 
1918
1922
  # value
1919
1923
  table.field("value", port: true)
1920
1924
  digraph.edge("#{id}:value -> #{node_id(node.value)};")
1921
1925
 
1922
- # operator
1923
- table.field("operator", node.operator.inspect)
1926
+ # binary_operator
1927
+ table.field("binary_operator", node.binary_operator.inspect)
1924
1928
 
1925
1929
  digraph.nodes << <<~DOT
1926
1930
  #{id} [
@@ -2318,11 +2322,11 @@ module Prism
2318
2322
  digraph.edge("#{id}:block -> #{node_id(block)};")
2319
2323
  end
2320
2324
 
2321
- # operator
2322
- table.field("operator", node.operator.inspect)
2325
+ # binary_operator
2326
+ table.field("binary_operator", node.binary_operator.inspect)
2323
2327
 
2324
- # operator_loc
2325
- 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))
2326
2330
 
2327
2331
  # value
2328
2332
  table.field("value", port: true)
@@ -2467,15 +2471,15 @@ module Prism
2467
2471
  # name_loc
2468
2472
  table.field("name_loc", location_inspect(node.name_loc))
2469
2473
 
2470
- # operator_loc
2471
- 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))
2472
2476
 
2473
2477
  # value
2474
2478
  table.field("value", port: true)
2475
2479
  digraph.edge("#{id}:value -> #{node_id(node.value)};")
2476
2480
 
2477
- # operator
2478
- table.field("operator", node.operator.inspect)
2481
+ # binary_operator
2482
+ table.field("binary_operator", node.binary_operator.inspect)
2479
2483
 
2480
2484
  digraph.nodes << <<~DOT
2481
2485
  #{id} [
@@ -2924,8 +2928,8 @@ module Prism
2924
2928
  # name_loc
2925
2929
  table.field("name_loc", location_inspect(node.name_loc))
2926
2930
 
2927
- # operator_loc
2928
- 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))
2929
2933
 
2930
2934
  # value
2931
2935
  table.field("value", port: true)
@@ -2934,8 +2938,8 @@ module Prism
2934
2938
  # name
2935
2939
  table.field("name", node.name.inspect)
2936
2940
 
2937
- # operator
2938
- table.field("operator", node.operator.inspect)
2941
+ # binary_operator
2942
+ table.field("binary_operator", node.binary_operator.inspect)
2939
2943
 
2940
2944
  # depth
2941
2945
  table.field("depth", node.depth.inspect)
@@ -3999,6 +4003,9 @@ module Prism
3999
4003
  table = Table.new("ReturnNode")
4000
4004
  id = node_id(node)
4001
4005
 
4006
+ # flags
4007
+ table.field("flags", return_node_flags_inspect(node))
4008
+
4002
4009
  # keyword_loc
4003
4010
  table.field("keyword_loc", location_inspect(node.keyword_loc))
4004
4011
 
@@ -4569,6 +4576,7 @@ module Prism
4569
4576
  # comma-separated list.
4570
4577
  def arguments_node_flags_inspect(node)
4571
4578
  flags = [] #: Array[String]
4579
+ flags << "contains_keywords" if node.contains_keywords?
4572
4580
  flags << "contains_keyword_splat" if node.contains_keyword_splat?
4573
4581
  flags.join(", ")
4574
4582
  end
@@ -4671,6 +4679,14 @@ module Prism
4671
4679
  flags.join(", ")
4672
4680
  end
4673
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
+
4674
4690
  # Inspect a node that has shareable_constant_node_flags flags to display the flags as a
4675
4691
  # comma-separated list.
4676
4692
  def shareable_constant_node_flags_inspect(node)
data/lib/prism/dsl.rb CHANGED
@@ -10,7 +10,7 @@ module Prism
10
10
  # The DSL module provides a set of methods that can be used to create prism
11
11
  # nodes in a more concise manner. For example, instead of writing:
12
12
  #
13
- # source = Prism::Source.new("[1]")
13
+ # source = Prism::Source.for("[1]")
14
14
  #
15
15
  # Prism::ArrayNode.new(
16
16
  # [
@@ -28,7 +28,7 @@ module Prism
28
28
  #
29
29
  # you could instead write:
30
30
  #
31
- # source = Prism::Source.new("[1]")
31
+ # source = Prism::Source.for("[1]")
32
32
  #
33
33
  # ArrayNode(
34
34
  # IntegerNode(Prism::IntegerBaseFlags::DECIMAL, 1, Location(source, 1, 1)), source),
@@ -143,8 +143,8 @@ module Prism
143
143
  end
144
144
 
145
145
  # Create a new CallOperatorWriteNode node
146
- def CallOperatorWriteNode(flags, receiver, call_operator_loc, message_loc, read_name, write_name, operator, operator_loc, value, source = nil, location = Location())
147
- CallOperatorWriteNode.new(source, flags, receiver, call_operator_loc, message_loc, read_name, write_name, operator, operator_loc, value, location)
146
+ def CallOperatorWriteNode(flags, receiver, call_operator_loc, message_loc, read_name, write_name, binary_operator, binary_operator_loc, value, source = nil, location = Location())
147
+ CallOperatorWriteNode.new(source, flags, receiver, call_operator_loc, message_loc, read_name, write_name, binary_operator, binary_operator_loc, value, location)
148
148
  end
149
149
 
150
150
  # Create a new CallOrWriteNode node
@@ -183,8 +183,8 @@ module Prism
183
183
  end
184
184
 
185
185
  # Create a new ClassVariableOperatorWriteNode node
186
- def ClassVariableOperatorWriteNode(name, name_loc, operator_loc, value, operator, source = nil, location = Location())
187
- ClassVariableOperatorWriteNode.new(source, name, name_loc, operator_loc, value, operator, location)
186
+ def ClassVariableOperatorWriteNode(name, name_loc, binary_operator_loc, value, binary_operator, source = nil, location = Location())
187
+ ClassVariableOperatorWriteNode.new(source, name, name_loc, binary_operator_loc, value, binary_operator, location)
188
188
  end
189
189
 
190
190
  # Create a new ClassVariableOrWriteNode node
@@ -213,8 +213,8 @@ module Prism
213
213
  end
214
214
 
215
215
  # Create a new ConstantOperatorWriteNode node
216
- def ConstantOperatorWriteNode(name, name_loc, operator_loc, value, operator, source = nil, location = Location())
217
- ConstantOperatorWriteNode.new(source, name, name_loc, operator_loc, value, operator, location)
216
+ def ConstantOperatorWriteNode(name, name_loc, binary_operator_loc, value, binary_operator, source = nil, location = Location())
217
+ ConstantOperatorWriteNode.new(source, name, name_loc, binary_operator_loc, value, binary_operator, location)
218
218
  end
219
219
 
220
220
  # Create a new ConstantOrWriteNode node
@@ -228,13 +228,13 @@ module Prism
228
228
  end
229
229
 
230
230
  # Create a new ConstantPathNode node
231
- def ConstantPathNode(parent, child, delimiter_loc, source = nil, location = Location())
232
- ConstantPathNode.new(source, parent, child, delimiter_loc, location)
231
+ def ConstantPathNode(parent, name, delimiter_loc, name_loc, source = nil, location = Location())
232
+ ConstantPathNode.new(source, parent, name, delimiter_loc, name_loc, location)
233
233
  end
234
234
 
235
235
  # Create a new ConstantPathOperatorWriteNode node
236
- def ConstantPathOperatorWriteNode(target, operator_loc, value, operator, source = nil, location = Location())
237
- ConstantPathOperatorWriteNode.new(source, target, operator_loc, value, operator, location)
236
+ def ConstantPathOperatorWriteNode(target, binary_operator_loc, value, binary_operator, source = nil, location = Location())
237
+ ConstantPathOperatorWriteNode.new(source, target, binary_operator_loc, value, binary_operator, location)
238
238
  end
239
239
 
240
240
  # Create a new ConstantPathOrWriteNode node
@@ -243,8 +243,8 @@ module Prism
243
243
  end
244
244
 
245
245
  # Create a new ConstantPathTargetNode node
246
- def ConstantPathTargetNode(parent, child, delimiter_loc, source = nil, location = Location())
247
- ConstantPathTargetNode.new(source, parent, child, delimiter_loc, location)
246
+ def ConstantPathTargetNode(parent, name, delimiter_loc, name_loc, source = nil, location = Location())
247
+ ConstantPathTargetNode.new(source, parent, name, delimiter_loc, name_loc, location)
248
248
  end
249
249
 
250
250
  # Create a new ConstantPathWriteNode node
@@ -343,8 +343,8 @@ module Prism
343
343
  end
344
344
 
345
345
  # Create a new GlobalVariableOperatorWriteNode node
346
- def GlobalVariableOperatorWriteNode(name, name_loc, operator_loc, value, operator, source = nil, location = Location())
347
- GlobalVariableOperatorWriteNode.new(source, name, name_loc, operator_loc, value, operator, location)
346
+ def GlobalVariableOperatorWriteNode(name, name_loc, binary_operator_loc, value, binary_operator, source = nil, location = Location())
347
+ GlobalVariableOperatorWriteNode.new(source, name, name_loc, binary_operator_loc, value, binary_operator, location)
348
348
  end
349
349
 
350
350
  # Create a new GlobalVariableOrWriteNode node
@@ -408,8 +408,8 @@ module Prism
408
408
  end
409
409
 
410
410
  # Create a new IndexOperatorWriteNode node
411
- def IndexOperatorWriteNode(flags, receiver, call_operator_loc, opening_loc, arguments, closing_loc, block, operator, operator_loc, value, source = nil, location = Location())
412
- IndexOperatorWriteNode.new(source, flags, receiver, call_operator_loc, opening_loc, arguments, closing_loc, block, operator, operator_loc, value, location)
411
+ def IndexOperatorWriteNode(flags, receiver, call_operator_loc, opening_loc, arguments, closing_loc, block, binary_operator, binary_operator_loc, value, source = nil, location = Location())
412
+ IndexOperatorWriteNode.new(source, flags, receiver, call_operator_loc, opening_loc, arguments, closing_loc, block, binary_operator, binary_operator_loc, value, location)
413
413
  end
414
414
 
415
415
  # Create a new IndexOrWriteNode node
@@ -428,8 +428,8 @@ module Prism
428
428
  end
429
429
 
430
430
  # Create a new InstanceVariableOperatorWriteNode node
431
- def InstanceVariableOperatorWriteNode(name, name_loc, operator_loc, value, operator, source = nil, location = Location())
432
- InstanceVariableOperatorWriteNode.new(source, name, name_loc, operator_loc, value, operator, location)
431
+ def InstanceVariableOperatorWriteNode(name, name_loc, binary_operator_loc, value, binary_operator, source = nil, location = Location())
432
+ InstanceVariableOperatorWriteNode.new(source, name, name_loc, binary_operator_loc, value, binary_operator, location)
433
433
  end
434
434
 
435
435
  # Create a new InstanceVariableOrWriteNode node
@@ -508,8 +508,8 @@ module Prism
508
508
  end
509
509
 
510
510
  # Create a new LocalVariableOperatorWriteNode node
511
- def LocalVariableOperatorWriteNode(name_loc, operator_loc, value, name, operator, depth, source = nil, location = Location())
512
- LocalVariableOperatorWriteNode.new(source, name_loc, operator_loc, value, name, operator, depth, location)
511
+ def LocalVariableOperatorWriteNode(name_loc, binary_operator_loc, value, name, binary_operator, depth, source = nil, location = Location())
512
+ LocalVariableOperatorWriteNode.new(source, name_loc, binary_operator_loc, value, name, binary_operator, depth, location)
513
513
  end
514
514
 
515
515
  # Create a new LocalVariableOrWriteNode node
@@ -698,8 +698,8 @@ module Prism
698
698
  end
699
699
 
700
700
  # Create a new ReturnNode node
701
- def ReturnNode(keyword_loc, arguments, source = nil, location = Location())
702
- ReturnNode.new(source, keyword_loc, arguments, location)
701
+ def ReturnNode(flags, keyword_loc, arguments, source = nil, location = Location())
702
+ ReturnNode.new(source, flags, keyword_loc, arguments, location)
703
703
  end
704
704
 
705
705
  # Create a new SelfNode node
data/lib/prism/ffi.rb CHANGED
@@ -317,7 +317,7 @@ module Prism
317
317
  buffer.read
318
318
  end
319
319
 
320
- Serialize.load_tokens(Source.new(code), serialized)
320
+ Serialize.load_tokens(Source.for(code), serialized)
321
321
  end
322
322
 
323
323
  def parse_common(string, code, options) # :nodoc:
@@ -329,7 +329,7 @@ module Prism
329
329
  LibRubyParser::PrismBuffer.with do |buffer|
330
330
  LibRubyParser.pm_serialize_parse_comments(buffer.pointer, string.pointer, string.length, dump_options(options))
331
331
 
332
- source = Source.new(code)
332
+ source = Source.for(code)
333
333
  loader = Serialize::Loader.new(source, buffer.read)
334
334
 
335
335
  loader.load_header
@@ -343,7 +343,7 @@ module Prism
343
343
  LibRubyParser::PrismBuffer.with do |buffer|
344
344
  LibRubyParser.pm_serialize_parse_lex(buffer.pointer, string.pointer, string.length, dump_options(options))
345
345
 
346
- source = Source.new(code)
346
+ source = Source.for(code)
347
347
  loader = Serialize::Loader.new(source, buffer.read)
348
348
 
349
349
  tokens = loader.load_tokens
@@ -408,7 +408,7 @@ module Prism
408
408
  values << dump_options_command_line(options)
409
409
 
410
410
  template << "C"
411
- values << { nil => 0, "3.3.0" => 1, "3.4.0" => 0, "latest" => 0 }.fetch(options[:version])
411
+ values << { nil => 0, "3.3.0" => 1, "3.3.1" => 1, "3.4.0" => 0, "latest" => 0 }.fetch(options[:version])
412
412
 
413
413
  template << "L"
414
414
  if (scopes = options[:scopes])