prism 0.28.0 → 0.30.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 (73) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +41 -1
  3. data/CONTRIBUTING.md +0 -4
  4. data/README.md +1 -0
  5. data/config.yml +95 -26
  6. data/docs/fuzzing.md +1 -1
  7. data/docs/ripper_translation.md +22 -0
  8. data/ext/prism/api_node.c +70 -52
  9. data/ext/prism/extconf.rb +27 -23
  10. data/ext/prism/extension.c +107 -372
  11. data/ext/prism/extension.h +1 -1
  12. data/include/prism/ast.h +170 -102
  13. data/include/prism/diagnostic.h +18 -3
  14. data/include/prism/node.h +0 -21
  15. data/include/prism/parser.h +23 -25
  16. data/include/prism/regexp.h +17 -8
  17. data/include/prism/static_literals.h +3 -2
  18. data/include/prism/util/pm_char.h +1 -2
  19. data/include/prism/util/pm_constant_pool.h +0 -8
  20. data/include/prism/util/pm_integer.h +16 -9
  21. data/include/prism/util/pm_string.h +0 -8
  22. data/include/prism/version.h +2 -2
  23. data/include/prism.h +0 -11
  24. data/lib/prism/compiler.rb +3 -0
  25. data/lib/prism/desugar_compiler.rb +4 -4
  26. data/lib/prism/dispatcher.rb +14 -0
  27. data/lib/prism/dot_visitor.rb +54 -35
  28. data/lib/prism/dsl.rb +23 -18
  29. data/lib/prism/ffi.rb +25 -4
  30. data/lib/prism/inspect_visitor.rb +26 -24
  31. data/lib/prism/mutation_compiler.rb +6 -1
  32. data/lib/prism/node.rb +314 -389
  33. data/lib/prism/node_ext.rb +175 -17
  34. data/lib/prism/parse_result/comments.rb +1 -8
  35. data/lib/prism/parse_result/newlines.rb +102 -12
  36. data/lib/prism/parse_result.rb +17 -0
  37. data/lib/prism/reflection.rb +11 -9
  38. data/lib/prism/serialize.rb +91 -68
  39. data/lib/prism/translation/parser/compiler.rb +288 -138
  40. data/lib/prism/translation/parser.rb +7 -2
  41. data/lib/prism/translation/ripper.rb +24 -22
  42. data/lib/prism/translation/ruby_parser.rb +32 -14
  43. data/lib/prism/visitor.rb +3 -0
  44. data/lib/prism.rb +0 -4
  45. data/prism.gemspec +2 -4
  46. data/rbi/prism/node.rbi +114 -57
  47. data/rbi/prism/node_ext.rbi +5 -0
  48. data/rbi/prism/parse_result.rbi +1 -1
  49. data/rbi/prism/visitor.rbi +3 -0
  50. data/rbi/prism.rbi +6 -0
  51. data/sig/prism/dsl.rbs +13 -10
  52. data/sig/prism/lex_compat.rbs +10 -0
  53. data/sig/prism/mutation_compiler.rbs +1 -0
  54. data/sig/prism/node.rbs +72 -48
  55. data/sig/prism/node_ext.rbs +4 -0
  56. data/sig/prism/visitor.rbs +1 -0
  57. data/sig/prism.rbs +21 -0
  58. data/src/diagnostic.c +56 -27
  59. data/src/node.c +432 -1690
  60. data/src/prettyprint.c +97 -54
  61. data/src/prism.c +1286 -1196
  62. data/src/regexp.c +133 -68
  63. data/src/serialize.c +22 -17
  64. data/src/static_literals.c +63 -84
  65. data/src/token_type.c +4 -4
  66. data/src/util/pm_constant_pool.c +0 -8
  67. data/src/util/pm_integer.c +39 -11
  68. data/src/util/pm_string.c +0 -12
  69. data/src/util/pm_strpbrk.c +32 -6
  70. metadata +3 -5
  71. data/include/prism/util/pm_string_list.h +0 -44
  72. data/lib/prism/debug.rb +0 -249
  73. data/src/util/pm_string_list.c +0 -28
data/src/prettyprint.c CHANGED
@@ -1372,20 +1372,20 @@ prettyprint_node(pm_buffer_t *output_buffer, const pm_parser_t *parser, const pm
1372
1372
  pm_buffer_append_byte(output_buffer, '\n');
1373
1373
  }
1374
1374
 
1375
- // operator
1375
+ // binary_operator
1376
1376
  {
1377
1377
  pm_buffer_concat(output_buffer, prefix_buffer);
1378
- pm_buffer_append_string(output_buffer, "+-- operator:", 13);
1378
+ pm_buffer_append_string(output_buffer, "+-- binary_operator:", 20);
1379
1379
  pm_buffer_append_byte(output_buffer, ' ');
1380
- prettyprint_constant(output_buffer, parser, cast->operator);
1380
+ prettyprint_constant(output_buffer, parser, cast->binary_operator);
1381
1381
  pm_buffer_append_byte(output_buffer, '\n');
1382
1382
  }
1383
1383
 
1384
- // operator_loc
1384
+ // binary_operator_loc
1385
1385
  {
1386
1386
  pm_buffer_concat(output_buffer, prefix_buffer);
1387
- pm_buffer_append_string(output_buffer, "+-- operator_loc:", 17);
1388
- pm_location_t *location = &cast->operator_loc;
1387
+ pm_buffer_append_string(output_buffer, "+-- binary_operator_loc:", 24);
1388
+ pm_location_t *location = &cast->binary_operator_loc;
1389
1389
  pm_buffer_append_byte(output_buffer, ' ');
1390
1390
  prettyprint_location(output_buffer, parser, location);
1391
1391
  pm_buffer_append_string(output_buffer, " = \"", 4);
@@ -2031,11 +2031,11 @@ prettyprint_node(pm_buffer_t *output_buffer, const pm_parser_t *parser, const pm
2031
2031
  pm_buffer_append_string(output_buffer, "\"\n", 2);
2032
2032
  }
2033
2033
 
2034
- // operator_loc
2034
+ // binary_operator_loc
2035
2035
  {
2036
2036
  pm_buffer_concat(output_buffer, prefix_buffer);
2037
- pm_buffer_append_string(output_buffer, "+-- operator_loc:", 17);
2038
- pm_location_t *location = &cast->operator_loc;
2037
+ pm_buffer_append_string(output_buffer, "+-- binary_operator_loc:", 24);
2038
+ pm_location_t *location = &cast->binary_operator_loc;
2039
2039
  pm_buffer_append_byte(output_buffer, ' ');
2040
2040
  prettyprint_location(output_buffer, parser, location);
2041
2041
  pm_buffer_append_string(output_buffer, " = \"", 4);
@@ -2056,12 +2056,12 @@ prettyprint_node(pm_buffer_t *output_buffer, const pm_parser_t *parser, const pm
2056
2056
  prefix_buffer->length = prefix_length;
2057
2057
  }
2058
2058
 
2059
- // operator
2059
+ // binary_operator
2060
2060
  {
2061
2061
  pm_buffer_concat(output_buffer, prefix_buffer);
2062
- pm_buffer_append_string(output_buffer, "+-- operator:", 13);
2062
+ pm_buffer_append_string(output_buffer, "+-- binary_operator:", 20);
2063
2063
  pm_buffer_append_byte(output_buffer, ' ');
2064
- prettyprint_constant(output_buffer, parser, cast->operator);
2064
+ prettyprint_constant(output_buffer, parser, cast->binary_operator);
2065
2065
  pm_buffer_append_byte(output_buffer, '\n');
2066
2066
  }
2067
2067
 
@@ -2290,11 +2290,11 @@ prettyprint_node(pm_buffer_t *output_buffer, const pm_parser_t *parser, const pm
2290
2290
  pm_buffer_append_string(output_buffer, "\"\n", 2);
2291
2291
  }
2292
2292
 
2293
- // operator_loc
2293
+ // binary_operator_loc
2294
2294
  {
2295
2295
  pm_buffer_concat(output_buffer, prefix_buffer);
2296
- pm_buffer_append_string(output_buffer, "+-- operator_loc:", 17);
2297
- pm_location_t *location = &cast->operator_loc;
2296
+ pm_buffer_append_string(output_buffer, "+-- binary_operator_loc:", 24);
2297
+ pm_location_t *location = &cast->binary_operator_loc;
2298
2298
  pm_buffer_append_byte(output_buffer, ' ');
2299
2299
  prettyprint_location(output_buffer, parser, location);
2300
2300
  pm_buffer_append_string(output_buffer, " = \"", 4);
@@ -2315,12 +2315,12 @@ prettyprint_node(pm_buffer_t *output_buffer, const pm_parser_t *parser, const pm
2315
2315
  prefix_buffer->length = prefix_length;
2316
2316
  }
2317
2317
 
2318
- // operator
2318
+ // binary_operator
2319
2319
  {
2320
2320
  pm_buffer_concat(output_buffer, prefix_buffer);
2321
- pm_buffer_append_string(output_buffer, "+-- operator:", 13);
2321
+ pm_buffer_append_string(output_buffer, "+-- binary_operator:", 20);
2322
2322
  pm_buffer_append_byte(output_buffer, ' ');
2323
- prettyprint_constant(output_buffer, parser, cast->operator);
2323
+ prettyprint_constant(output_buffer, parser, cast->binary_operator);
2324
2324
  pm_buffer_append_byte(output_buffer, '\n');
2325
2325
  }
2326
2326
 
@@ -2507,11 +2507,11 @@ prettyprint_node(pm_buffer_t *output_buffer, const pm_parser_t *parser, const pm
2507
2507
  prefix_buffer->length = prefix_length;
2508
2508
  }
2509
2509
 
2510
- // operator_loc
2510
+ // binary_operator_loc
2511
2511
  {
2512
2512
  pm_buffer_concat(output_buffer, prefix_buffer);
2513
- pm_buffer_append_string(output_buffer, "+-- operator_loc:", 17);
2514
- pm_location_t *location = &cast->operator_loc;
2513
+ pm_buffer_append_string(output_buffer, "+-- binary_operator_loc:", 24);
2514
+ pm_location_t *location = &cast->binary_operator_loc;
2515
2515
  pm_buffer_append_byte(output_buffer, ' ');
2516
2516
  prettyprint_location(output_buffer, parser, location);
2517
2517
  pm_buffer_append_string(output_buffer, " = \"", 4);
@@ -2532,12 +2532,12 @@ prettyprint_node(pm_buffer_t *output_buffer, const pm_parser_t *parser, const pm
2532
2532
  prefix_buffer->length = prefix_length;
2533
2533
  }
2534
2534
 
2535
- // operator
2535
+ // binary_operator
2536
2536
  {
2537
2537
  pm_buffer_concat(output_buffer, prefix_buffer);
2538
- pm_buffer_append_string(output_buffer, "+-- operator:", 13);
2538
+ pm_buffer_append_string(output_buffer, "+-- binary_operator:", 20);
2539
2539
  pm_buffer_append_byte(output_buffer, ' ');
2540
- prettyprint_constant(output_buffer, parser, cast->operator);
2540
+ prettyprint_constant(output_buffer, parser, cast->binary_operator);
2541
2541
  pm_buffer_append_byte(output_buffer, '\n');
2542
2542
  }
2543
2543
 
@@ -3632,11 +3632,11 @@ prettyprint_node(pm_buffer_t *output_buffer, const pm_parser_t *parser, const pm
3632
3632
  pm_buffer_append_string(output_buffer, "\"\n", 2);
3633
3633
  }
3634
3634
 
3635
- // operator_loc
3635
+ // binary_operator_loc
3636
3636
  {
3637
3637
  pm_buffer_concat(output_buffer, prefix_buffer);
3638
- pm_buffer_append_string(output_buffer, "+-- operator_loc:", 17);
3639
- pm_location_t *location = &cast->operator_loc;
3638
+ pm_buffer_append_string(output_buffer, "+-- binary_operator_loc:", 24);
3639
+ pm_location_t *location = &cast->binary_operator_loc;
3640
3640
  pm_buffer_append_byte(output_buffer, ' ');
3641
3641
  prettyprint_location(output_buffer, parser, location);
3642
3642
  pm_buffer_append_string(output_buffer, " = \"", 4);
@@ -3657,12 +3657,12 @@ prettyprint_node(pm_buffer_t *output_buffer, const pm_parser_t *parser, const pm
3657
3657
  prefix_buffer->length = prefix_length;
3658
3658
  }
3659
3659
 
3660
- // operator
3660
+ // binary_operator
3661
3661
  {
3662
3662
  pm_buffer_concat(output_buffer, prefix_buffer);
3663
- pm_buffer_append_string(output_buffer, "+-- operator:", 13);
3663
+ pm_buffer_append_string(output_buffer, "+-- binary_operator:", 20);
3664
3664
  pm_buffer_append_byte(output_buffer, ' ');
3665
- prettyprint_constant(output_buffer, parser, cast->operator);
3665
+ prettyprint_constant(output_buffer, parser, cast->binary_operator);
3666
3666
  pm_buffer_append_byte(output_buffer, '\n');
3667
3667
  }
3668
3668
 
@@ -4449,20 +4449,20 @@ prettyprint_node(pm_buffer_t *output_buffer, const pm_parser_t *parser, const pm
4449
4449
  }
4450
4450
  }
4451
4451
 
4452
- // operator
4452
+ // binary_operator
4453
4453
  {
4454
4454
  pm_buffer_concat(output_buffer, prefix_buffer);
4455
- pm_buffer_append_string(output_buffer, "+-- operator:", 13);
4455
+ pm_buffer_append_string(output_buffer, "+-- binary_operator:", 20);
4456
4456
  pm_buffer_append_byte(output_buffer, ' ');
4457
- prettyprint_constant(output_buffer, parser, cast->operator);
4457
+ prettyprint_constant(output_buffer, parser, cast->binary_operator);
4458
4458
  pm_buffer_append_byte(output_buffer, '\n');
4459
4459
  }
4460
4460
 
4461
- // operator_loc
4461
+ // binary_operator_loc
4462
4462
  {
4463
4463
  pm_buffer_concat(output_buffer, prefix_buffer);
4464
- pm_buffer_append_string(output_buffer, "+-- operator_loc:", 17);
4465
- pm_location_t *location = &cast->operator_loc;
4464
+ pm_buffer_append_string(output_buffer, "+-- binary_operator_loc:", 24);
4465
+ pm_location_t *location = &cast->binary_operator_loc;
4466
4466
  pm_buffer_append_byte(output_buffer, ' ');
4467
4467
  prettyprint_location(output_buffer, parser, location);
4468
4468
  pm_buffer_append_string(output_buffer, " = \"", 4);
@@ -4827,11 +4827,11 @@ prettyprint_node(pm_buffer_t *output_buffer, const pm_parser_t *parser, const pm
4827
4827
  pm_buffer_append_string(output_buffer, "\"\n", 2);
4828
4828
  }
4829
4829
 
4830
- // operator_loc
4830
+ // binary_operator_loc
4831
4831
  {
4832
4832
  pm_buffer_concat(output_buffer, prefix_buffer);
4833
- pm_buffer_append_string(output_buffer, "+-- operator_loc:", 17);
4834
- pm_location_t *location = &cast->operator_loc;
4833
+ pm_buffer_append_string(output_buffer, "+-- binary_operator_loc:", 24);
4834
+ pm_location_t *location = &cast->binary_operator_loc;
4835
4835
  pm_buffer_append_byte(output_buffer, ' ');
4836
4836
  prettyprint_location(output_buffer, parser, location);
4837
4837
  pm_buffer_append_string(output_buffer, " = \"", 4);
@@ -4852,12 +4852,12 @@ prettyprint_node(pm_buffer_t *output_buffer, const pm_parser_t *parser, const pm
4852
4852
  prefix_buffer->length = prefix_length;
4853
4853
  }
4854
4854
 
4855
- // operator
4855
+ // binary_operator
4856
4856
  {
4857
4857
  pm_buffer_concat(output_buffer, prefix_buffer);
4858
- pm_buffer_append_string(output_buffer, "+-- operator:", 13);
4858
+ pm_buffer_append_string(output_buffer, "+-- binary_operator:", 20);
4859
4859
  pm_buffer_append_byte(output_buffer, ' ');
4860
- prettyprint_constant(output_buffer, parser, cast->operator);
4860
+ prettyprint_constant(output_buffer, parser, cast->binary_operator);
4861
4861
  pm_buffer_append_byte(output_buffer, '\n');
4862
4862
  }
4863
4863
 
@@ -5465,6 +5465,13 @@ prettyprint_node(pm_buffer_t *output_buffer, const pm_parser_t *parser, const pm
5465
5465
 
5466
5466
  break;
5467
5467
  }
5468
+ case PM_IT_LOCAL_VARIABLE_READ_NODE: {
5469
+ pm_buffer_append_string(output_buffer, "@ ItLocalVariableReadNode (location: ", 37);
5470
+ prettyprint_location(output_buffer, parser, &node->location);
5471
+ pm_buffer_append_string(output_buffer, ")\n", 2);
5472
+
5473
+ break;
5474
+ }
5468
5475
  case PM_IT_PARAMETERS_NODE: {
5469
5476
  pm_buffer_append_string(output_buffer, "@ ItParametersNode (location: ", 30);
5470
5477
  prettyprint_location(output_buffer, parser, &node->location);
@@ -5744,11 +5751,11 @@ prettyprint_node(pm_buffer_t *output_buffer, const pm_parser_t *parser, const pm
5744
5751
  pm_buffer_append_string(output_buffer, "\"\n", 2);
5745
5752
  }
5746
5753
 
5747
- // operator_loc
5754
+ // binary_operator_loc
5748
5755
  {
5749
5756
  pm_buffer_concat(output_buffer, prefix_buffer);
5750
- pm_buffer_append_string(output_buffer, "+-- operator_loc:", 17);
5751
- pm_location_t *location = &cast->operator_loc;
5757
+ pm_buffer_append_string(output_buffer, "+-- binary_operator_loc:", 24);
5758
+ pm_location_t *location = &cast->binary_operator_loc;
5752
5759
  pm_buffer_append_byte(output_buffer, ' ');
5753
5760
  prettyprint_location(output_buffer, parser, location);
5754
5761
  pm_buffer_append_string(output_buffer, " = \"", 4);
@@ -5778,12 +5785,12 @@ prettyprint_node(pm_buffer_t *output_buffer, const pm_parser_t *parser, const pm
5778
5785
  pm_buffer_append_byte(output_buffer, '\n');
5779
5786
  }
5780
5787
 
5781
- // operator
5788
+ // binary_operator
5782
5789
  {
5783
5790
  pm_buffer_concat(output_buffer, prefix_buffer);
5784
- pm_buffer_append_string(output_buffer, "+-- operator:", 13);
5791
+ pm_buffer_append_string(output_buffer, "+-- binary_operator:", 20);
5785
5792
  pm_buffer_append_byte(output_buffer, ' ');
5786
- prettyprint_constant(output_buffer, parser, cast->operator);
5793
+ prettyprint_constant(output_buffer, parser, cast->binary_operator);
5787
5794
  pm_buffer_append_byte(output_buffer, '\n');
5788
5795
  }
5789
5796
 
@@ -7290,17 +7297,53 @@ prettyprint_node(pm_buffer_t *output_buffer, const pm_parser_t *parser, const pm
7290
7297
  prettyprint_location(output_buffer, parser, &node->location);
7291
7298
  pm_buffer_append_string(output_buffer, ")\n", 2);
7292
7299
 
7293
- // numeric
7300
+ // flags
7294
7301
  {
7295
7302
  pm_buffer_concat(output_buffer, prefix_buffer);
7296
- pm_buffer_append_string(output_buffer, "+-- numeric:", 12);
7303
+ pm_buffer_append_string(output_buffer, "+-- flags:", 10);
7304
+ bool found = false;
7305
+ if (cast->base.flags & PM_INTEGER_BASE_FLAGS_BINARY) {
7306
+ if (found) pm_buffer_append_byte(output_buffer, ',');
7307
+ pm_buffer_append_string(output_buffer, " binary", 7);
7308
+ found = true;
7309
+ }
7310
+ if (cast->base.flags & PM_INTEGER_BASE_FLAGS_DECIMAL) {
7311
+ if (found) pm_buffer_append_byte(output_buffer, ',');
7312
+ pm_buffer_append_string(output_buffer, " decimal", 8);
7313
+ found = true;
7314
+ }
7315
+ if (cast->base.flags & PM_INTEGER_BASE_FLAGS_OCTAL) {
7316
+ if (found) pm_buffer_append_byte(output_buffer, ',');
7317
+ pm_buffer_append_string(output_buffer, " octal", 6);
7318
+ found = true;
7319
+ }
7320
+ if (cast->base.flags & PM_INTEGER_BASE_FLAGS_HEXADECIMAL) {
7321
+ if (found) pm_buffer_append_byte(output_buffer, ',');
7322
+ pm_buffer_append_string(output_buffer, " hexadecimal", 12);
7323
+ found = true;
7324
+ }
7325
+ if (!found) pm_buffer_append_string(output_buffer, " nil", 4);
7297
7326
  pm_buffer_append_byte(output_buffer, '\n');
7327
+ }
7298
7328
 
7299
- size_t prefix_length = prefix_buffer->length;
7300
- pm_buffer_append_string(prefix_buffer, " ", 4);
7329
+ // numerator
7330
+ {
7301
7331
  pm_buffer_concat(output_buffer, prefix_buffer);
7302
- prettyprint_node(output_buffer, parser, (pm_node_t *) cast->numeric, prefix_buffer);
7303
- prefix_buffer->length = prefix_length;
7332
+ pm_buffer_append_string(output_buffer, "+-- numerator:", 14);
7333
+ const pm_integer_t *integer = &cast->numerator;
7334
+ pm_buffer_append_byte(output_buffer, ' ');
7335
+ pm_integer_string(output_buffer, integer);
7336
+ pm_buffer_append_byte(output_buffer, '\n');
7337
+ }
7338
+
7339
+ // denominator
7340
+ {
7341
+ pm_buffer_concat(output_buffer, prefix_buffer);
7342
+ pm_buffer_append_string(output_buffer, "+-- denominator:", 16);
7343
+ const pm_integer_t *integer = &cast->denominator;
7344
+ pm_buffer_append_byte(output_buffer, ' ');
7345
+ pm_integer_string(output_buffer, integer);
7346
+ pm_buffer_append_byte(output_buffer, '\n');
7304
7347
  }
7305
7348
 
7306
7349
  break;