prism 1.4.0 → 1.7.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 (90) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +73 -1
  3. data/Makefile +7 -5
  4. data/README.md +3 -1
  5. data/config.yml +294 -41
  6. data/docs/build_system.md +2 -2
  7. data/docs/cruby_compilation.md +1 -1
  8. data/docs/design.md +2 -2
  9. data/docs/parser_translation.md +8 -23
  10. data/docs/releasing.md +6 -25
  11. data/docs/ripper_translation.md +1 -1
  12. data/ext/prism/api_node.c +9 -3
  13. data/ext/prism/extconf.rb +1 -1
  14. data/ext/prism/extension.c +24 -3
  15. data/ext/prism/extension.h +1 -1
  16. data/include/prism/ast.h +360 -70
  17. data/include/prism/diagnostic.h +7 -0
  18. data/include/prism/options.h +49 -3
  19. data/include/prism/parser.h +3 -0
  20. data/include/prism/regexp.h +2 -2
  21. data/include/prism/util/pm_buffer.h +8 -0
  22. data/include/prism/util/pm_integer.h +4 -0
  23. data/include/prism/util/pm_list.h +6 -0
  24. data/include/prism/util/pm_string.h +12 -2
  25. data/include/prism/version.h +2 -2
  26. data/include/prism.h +40 -15
  27. data/lib/prism/compiler.rb +456 -151
  28. data/lib/prism/desugar_compiler.rb +1 -0
  29. data/lib/prism/dispatcher.rb +16 -0
  30. data/lib/prism/dot_visitor.rb +10 -1
  31. data/lib/prism/dsl.rb +5 -2
  32. data/lib/prism/ffi.rb +28 -10
  33. data/lib/prism/inspect_visitor.rb +4 -0
  34. data/lib/prism/lex_compat.rb +1 -0
  35. data/lib/prism/mutation_compiler.rb +3 -0
  36. data/lib/prism/node.rb +559 -349
  37. data/lib/prism/node_ext.rb +4 -1
  38. data/lib/prism/pack.rb +2 -0
  39. data/lib/prism/parse_result/comments.rb +1 -0
  40. data/lib/prism/parse_result/errors.rb +1 -0
  41. data/lib/prism/parse_result/newlines.rb +1 -0
  42. data/lib/prism/parse_result.rb +3 -15
  43. data/lib/prism/pattern.rb +1 -0
  44. data/lib/prism/polyfill/scan_byte.rb +14 -0
  45. data/lib/prism/polyfill/warn.rb +36 -0
  46. data/lib/prism/reflection.rb +4 -1
  47. data/lib/prism/relocation.rb +1 -0
  48. data/lib/prism/serialize.rb +30 -22
  49. data/lib/prism/string_query.rb +1 -0
  50. data/lib/prism/translation/parser/builder.rb +1 -0
  51. data/lib/prism/translation/parser/compiler.rb +63 -41
  52. data/lib/prism/translation/parser/lexer.rb +29 -21
  53. data/lib/prism/translation/parser.rb +25 -4
  54. data/lib/prism/translation/parser33.rb +1 -0
  55. data/lib/prism/translation/parser34.rb +1 -0
  56. data/lib/prism/translation/parser35.rb +2 -6
  57. data/lib/prism/translation/parser40.rb +13 -0
  58. data/lib/prism/translation/parser41.rb +13 -0
  59. data/lib/prism/translation/parser_current.rb +26 -0
  60. data/lib/prism/translation/ripper/sexp.rb +1 -0
  61. data/lib/prism/translation/ripper.rb +19 -3
  62. data/lib/prism/translation/ruby_parser.rb +340 -22
  63. data/lib/prism/translation.rb +4 -0
  64. data/lib/prism/visitor.rb +457 -152
  65. data/lib/prism.rb +22 -0
  66. data/prism.gemspec +9 -1
  67. data/rbi/prism/dsl.rbi +6 -6
  68. data/rbi/prism/node.rbi +42 -17
  69. data/rbi/prism/translation/parser35.rbi +0 -2
  70. data/rbi/prism/translation/parser40.rbi +6 -0
  71. data/rbi/prism/translation/parser41.rbi +6 -0
  72. data/sig/prism/dispatcher.rbs +3 -0
  73. data/sig/prism/dsl.rbs +5 -5
  74. data/sig/prism/node.rbs +462 -38
  75. data/sig/prism/node_ext.rbs +84 -17
  76. data/sig/prism/parse_result/comments.rbs +38 -0
  77. data/sig/prism/parse_result.rbs +4 -0
  78. data/sig/prism/reflection.rbs +1 -1
  79. data/sig/prism.rbs +4 -0
  80. data/src/diagnostic.c +13 -1
  81. data/src/encoding.c +172 -67
  82. data/src/node.c +11 -0
  83. data/src/options.c +17 -7
  84. data/src/prettyprint.c +18 -0
  85. data/src/prism.c +1495 -2021
  86. data/src/serialize.c +9 -1
  87. data/src/token_type.c +38 -36
  88. data/src/util/pm_constant_pool.c +1 -1
  89. data/src/util/pm_string.c +6 -8
  90. metadata +11 -3
data/src/node.c CHANGED
@@ -1,3 +1,5 @@
1
+ /* :markup: markdown */
2
+
1
3
  /*----------------------------------------------------------------------------*/
2
4
  /* This file is generated by the templates/template.rb script and should not */
3
5
  /* be modified manually. See */
@@ -3803,6 +3805,15 @@ pm_dump_json(pm_buffer_t *buffer, const pm_parser_t *parser, const pm_node_t *no
3803
3805
  pm_buffer_append_string(buffer, "null", 4);
3804
3806
  }
3805
3807
 
3808
+ // Dump the equal_loc field
3809
+ pm_buffer_append_byte(buffer, ',');
3810
+ pm_buffer_append_string(buffer, "\"equal_loc\":", 12);
3811
+ if (cast->equal_loc.start != NULL) {
3812
+ pm_dump_json_location(buffer, parser, &cast->equal_loc);
3813
+ } else {
3814
+ pm_buffer_append_string(buffer, "null", 4);
3815
+ }
3816
+
3806
3817
  // Dump the block field
3807
3818
  pm_buffer_append_byte(buffer, ',');
3808
3819
  pm_buffer_append_string(buffer, "\"block\":", 8);
data/src/options.c CHANGED
@@ -88,27 +88,37 @@ pm_options_version_set(pm_options_t *options, const char *version, size_t length
88
88
  return true;
89
89
  }
90
90
 
91
- if (strncmp(version, "3.5", 3) == 0) {
92
- options->version = PM_OPTIONS_VERSION_LATEST;
91
+ if (strncmp(version, "3.5", 3) == 0 || strncmp(version, "4.0", 3) == 0) {
92
+ options->version = PM_OPTIONS_VERSION_CRUBY_4_0;
93
+ return true;
94
+ }
95
+
96
+ if (strncmp(version, "4.1", 3) == 0) {
97
+ options->version = PM_OPTIONS_VERSION_CRUBY_4_1;
93
98
  return true;
94
99
  }
95
100
 
96
101
  return false;
97
102
  }
98
103
 
99
- if (length >= 4) {
100
- if (strncmp(version, "3.3.", 4) == 0 && is_number(version + 4, length - 4)) {
104
+ if (length >= 4 && is_number(version + 4, length - 4)) {
105
+ if (strncmp(version, "3.3.", 4) == 0) {
101
106
  options->version = PM_OPTIONS_VERSION_CRUBY_3_3;
102
107
  return true;
103
108
  }
104
109
 
105
- if (strncmp(version, "3.4.", 4) == 0 && is_number(version + 4, length - 4)) {
110
+ if (strncmp(version, "3.4.", 4) == 0) {
106
111
  options->version = PM_OPTIONS_VERSION_CRUBY_3_4;
107
112
  return true;
108
113
  }
109
114
 
110
- if (strncmp(version, "3.5.", 4) == 0 && is_number(version + 4, length - 4)) {
111
- options->version = PM_OPTIONS_VERSION_LATEST;
115
+ if (strncmp(version, "3.5.", 4) == 0 || strncmp(version, "4.0.", 4) == 0) {
116
+ options->version = PM_OPTIONS_VERSION_CRUBY_4_0;
117
+ return true;
118
+ }
119
+
120
+ if (strncmp(version, "4.1.", 4) == 0) {
121
+ options->version = PM_OPTIONS_VERSION_CRUBY_4_1;
112
122
  return true;
113
123
  }
114
124
  }
data/src/prettyprint.c CHANGED
@@ -1,3 +1,5 @@
1
+ /* :markup: markdown */
2
+
1
3
  /*----------------------------------------------------------------------------*/
2
4
  /* This file is generated by the templates/template.rb script and should not */
3
5
  /* be modified manually. See */
@@ -1266,6 +1268,22 @@ prettyprint_node(pm_buffer_t *output_buffer, const pm_parser_t *parser, const pm
1266
1268
  }
1267
1269
  }
1268
1270
 
1271
+ // equal_loc
1272
+ {
1273
+ pm_buffer_concat(output_buffer, prefix_buffer);
1274
+ pm_buffer_append_string(output_buffer, "+-- equal_loc:", 14);
1275
+ pm_location_t *location = &cast->equal_loc;
1276
+ if (location->start == NULL) {
1277
+ pm_buffer_append_string(output_buffer, " nil\n", 5);
1278
+ } else {
1279
+ pm_buffer_append_byte(output_buffer, ' ');
1280
+ prettyprint_location(output_buffer, parser, location);
1281
+ pm_buffer_append_string(output_buffer, " = \"", 4);
1282
+ pm_buffer_append_source(output_buffer, location->start, (size_t) (location->end - location->start), PM_BUFFER_ESCAPING_RUBY);
1283
+ pm_buffer_append_string(output_buffer, "\"\n", 2);
1284
+ }
1285
+ }
1286
+
1269
1287
  // block
1270
1288
  {
1271
1289
  pm_buffer_concat(output_buffer, prefix_buffer);