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/src/regexp.c CHANGED
@@ -565,21 +565,36 @@ pm_regexp_parse_group(pm_regexp_parser_t *parser) {
565
565
  */
566
566
  static bool
567
567
  pm_regexp_parse_item(pm_regexp_parser_t *parser) {
568
- switch (*parser->cursor++) {
568
+ switch (*parser->cursor) {
569
569
  case '^':
570
570
  case '$':
571
+ parser->cursor++;
571
572
  return true;
572
573
  case '\\':
574
+ parser->cursor++;
573
575
  if (!pm_regexp_char_is_eof(parser)) {
574
576
  parser->cursor++;
575
577
  }
576
578
  return pm_regexp_parse_quantifier(parser);
577
579
  case '(':
580
+ parser->cursor++;
578
581
  return pm_regexp_parse_group(parser) && pm_regexp_parse_quantifier(parser);
579
582
  case '[':
583
+ parser->cursor++;
580
584
  return pm_regexp_parse_lbracket(parser) && pm_regexp_parse_quantifier(parser);
581
- default:
585
+ default: {
586
+ size_t width;
587
+ if (!parser->encoding_changed) {
588
+ width = pm_encoding_utf_8_char_width(parser->cursor, (ptrdiff_t) (parser->end - parser->cursor));
589
+ } else {
590
+ width = parser->encoding->char_width(parser->cursor, (ptrdiff_t) (parser->end - parser->cursor));
591
+ }
592
+
593
+ if (width == 0) return false; // TODO: add appropriate error
594
+ parser->cursor += width;
595
+
582
596
  return pm_regexp_parse_quantifier(parser);
597
+ }
583
598
  }
584
599
  }
585
600
 
data/src/serialize.c CHANGED
@@ -5,8 +5,14 @@
5
5
  /* if you are looking to modify the */
6
6
  /* template */
7
7
  /******************************************************************************/
8
+
8
9
  #include "prism.h"
9
10
 
11
+ // We optionally support serializing to a binary string. For systems that don't
12
+ // want or need this functionality, it can be turned off with the
13
+ // PRISM_EXCLUDE_SERIALIZATION define.
14
+ #ifndef PRISM_EXCLUDE_SERIALIZATION
15
+
10
16
  #include <stdio.h>
11
17
 
12
18
  static inline uint32_t
@@ -32,7 +38,7 @@ pm_serialize_location(const pm_parser_t *parser, const pm_location_t *location,
32
38
  }
33
39
 
34
40
  static void
35
- pm_serialize_string(pm_parser_t *parser, pm_string_t *string, pm_buffer_t *buffer) {
41
+ pm_serialize_string(const pm_parser_t *parser, const pm_string_t *string, pm_buffer_t *buffer) {
36
42
  switch (string->type) {
37
43
  case PM_STRING_SHARED: {
38
44
  pm_buffer_append_byte(buffer, 1);
@@ -48,9 +54,25 @@ pm_serialize_string(pm_parser_t *parser, pm_string_t *string, pm_buffer_t *buffe
48
54
  pm_buffer_append_bytes(buffer, pm_string_source(string), length);
49
55
  break;
50
56
  }
57
+ #ifdef PRISM_HAS_MMAP
51
58
  case PM_STRING_MAPPED:
52
59
  assert(false && "Cannot serialize mapped strings.");
53
60
  break;
61
+ #endif
62
+ }
63
+ }
64
+
65
+ static void
66
+ pm_serialize_integer(const pm_integer_t *integer, pm_buffer_t *buffer) {
67
+ pm_buffer_append_byte(buffer, integer->negative ? 1 : 0);
68
+ if (integer->values == NULL) {
69
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(1));
70
+ pm_buffer_append_varuint(buffer, integer->value);
71
+ } else {
72
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(integer->length));
73
+ for (size_t i = 0; i < integer->length; i++) {
74
+ pm_buffer_append_varuint(buffer, integer->values[i]);
75
+ }
54
76
  }
55
77
  }
56
78
 
@@ -385,8 +407,8 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
385
407
  }
386
408
  pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_call_operator_write_node_t *)node)->read_name));
387
409
  pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_call_operator_write_node_t *)node)->write_name));
388
- pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_call_operator_write_node_t *)node)->operator));
389
- pm_serialize_location(parser, &((pm_call_operator_write_node_t *)node)->operator_loc, buffer);
410
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_call_operator_write_node_t *)node)->binary_operator));
411
+ pm_serialize_location(parser, &((pm_call_operator_write_node_t *)node)->binary_operator_loc, buffer);
390
412
  pm_serialize_node(parser, (pm_node_t *)((pm_call_operator_write_node_t *)node)->value, buffer);
391
413
  break;
392
414
  }
@@ -507,9 +529,9 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
507
529
  case PM_CLASS_VARIABLE_OPERATOR_WRITE_NODE: {
508
530
  pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_variable_operator_write_node_t *)node)->name));
509
531
  pm_serialize_location(parser, &((pm_class_variable_operator_write_node_t *)node)->name_loc, buffer);
510
- pm_serialize_location(parser, &((pm_class_variable_operator_write_node_t *)node)->operator_loc, buffer);
532
+ pm_serialize_location(parser, &((pm_class_variable_operator_write_node_t *)node)->binary_operator_loc, buffer);
511
533
  pm_serialize_node(parser, (pm_node_t *)((pm_class_variable_operator_write_node_t *)node)->value, buffer);
512
- pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_variable_operator_write_node_t *)node)->operator));
534
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_variable_operator_write_node_t *)node)->binary_operator));
513
535
  break;
514
536
  }
515
537
  case PM_CLASS_VARIABLE_OR_WRITE_NODE: {
@@ -531,12 +553,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
531
553
  pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_variable_write_node_t *)node)->name));
532
554
  pm_serialize_location(parser, &((pm_class_variable_write_node_t *)node)->name_loc, buffer);
533
555
  pm_serialize_node(parser, (pm_node_t *)((pm_class_variable_write_node_t *)node)->value, buffer);
534
- if (((pm_class_variable_write_node_t *)node)->operator_loc.start == NULL) {
535
- pm_buffer_append_byte(buffer, 0);
536
- } else {
537
- pm_buffer_append_byte(buffer, 1);
538
- pm_serialize_location(parser, &((pm_class_variable_write_node_t *)node)->operator_loc, buffer);
539
- }
556
+ pm_serialize_location(parser, &((pm_class_variable_write_node_t *)node)->operator_loc, buffer);
540
557
  break;
541
558
  }
542
559
  case PM_CONSTANT_AND_WRITE_NODE: {
@@ -549,9 +566,9 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
549
566
  case PM_CONSTANT_OPERATOR_WRITE_NODE: {
550
567
  pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_operator_write_node_t *)node)->name));
551
568
  pm_serialize_location(parser, &((pm_constant_operator_write_node_t *)node)->name_loc, buffer);
552
- pm_serialize_location(parser, &((pm_constant_operator_write_node_t *)node)->operator_loc, buffer);
569
+ pm_serialize_location(parser, &((pm_constant_operator_write_node_t *)node)->binary_operator_loc, buffer);
553
570
  pm_serialize_node(parser, (pm_node_t *)((pm_constant_operator_write_node_t *)node)->value, buffer);
554
- pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_operator_write_node_t *)node)->operator));
571
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_operator_write_node_t *)node)->binary_operator));
555
572
  break;
556
573
  }
557
574
  case PM_CONSTANT_OR_WRITE_NODE: {
@@ -573,15 +590,16 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
573
590
  } else {
574
591
  pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_node_t *)node)->parent, buffer);
575
592
  }
576
- pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_node_t *)node)->child, buffer);
593
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_path_node_t *)node)->name));
577
594
  pm_serialize_location(parser, &((pm_constant_path_node_t *)node)->delimiter_loc, buffer);
595
+ pm_serialize_location(parser, &((pm_constant_path_node_t *)node)->name_loc, buffer);
578
596
  break;
579
597
  }
580
598
  case PM_CONSTANT_PATH_OPERATOR_WRITE_NODE: {
581
599
  pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_operator_write_node_t *)node)->target, buffer);
582
- pm_serialize_location(parser, &((pm_constant_path_operator_write_node_t *)node)->operator_loc, buffer);
600
+ pm_serialize_location(parser, &((pm_constant_path_operator_write_node_t *)node)->binary_operator_loc, buffer);
583
601
  pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_operator_write_node_t *)node)->value, buffer);
584
- pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_path_operator_write_node_t *)node)->operator));
602
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_path_operator_write_node_t *)node)->binary_operator));
585
603
  break;
586
604
  }
587
605
  case PM_CONSTANT_PATH_OR_WRITE_NODE: {
@@ -596,8 +614,9 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
596
614
  } else {
597
615
  pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_target_node_t *)node)->parent, buffer);
598
616
  }
599
- pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_target_node_t *)node)->child, buffer);
617
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_path_target_node_t *)node)->name));
600
618
  pm_serialize_location(parser, &((pm_constant_path_target_node_t *)node)->delimiter_loc, buffer);
619
+ pm_serialize_location(parser, &((pm_constant_path_target_node_t *)node)->name_loc, buffer);
601
620
  break;
602
621
  }
603
622
  case PM_CONSTANT_PATH_WRITE_NODE: {
@@ -787,6 +806,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
787
806
  break;
788
807
  }
789
808
  case PM_FLOAT_NODE: {
809
+ pm_buffer_append_double(buffer, ((pm_float_node_t *)node)->value);
790
810
  break;
791
811
  }
792
812
  case PM_FOR_NODE: {
@@ -832,9 +852,9 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
832
852
  case PM_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE: {
833
853
  pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_global_variable_operator_write_node_t *)node)->name));
834
854
  pm_serialize_location(parser, &((pm_global_variable_operator_write_node_t *)node)->name_loc, buffer);
835
- pm_serialize_location(parser, &((pm_global_variable_operator_write_node_t *)node)->operator_loc, buffer);
855
+ pm_serialize_location(parser, &((pm_global_variable_operator_write_node_t *)node)->binary_operator_loc, buffer);
836
856
  pm_serialize_node(parser, (pm_node_t *)((pm_global_variable_operator_write_node_t *)node)->value, buffer);
837
- pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_global_variable_operator_write_node_t *)node)->operator));
857
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_global_variable_operator_write_node_t *)node)->binary_operator));
838
858
  break;
839
859
  }
840
860
  case PM_GLOBAL_VARIABLE_OR_WRITE_NODE: {
@@ -1012,8 +1032,8 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1012
1032
  } else {
1013
1033
  pm_serialize_node(parser, (pm_node_t *)((pm_index_operator_write_node_t *)node)->block, buffer);
1014
1034
  }
1015
- pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_index_operator_write_node_t *)node)->operator));
1016
- pm_serialize_location(parser, &((pm_index_operator_write_node_t *)node)->operator_loc, buffer);
1035
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_index_operator_write_node_t *)node)->binary_operator));
1036
+ pm_serialize_location(parser, &((pm_index_operator_write_node_t *)node)->binary_operator_loc, buffer);
1017
1037
  pm_serialize_node(parser, (pm_node_t *)((pm_index_operator_write_node_t *)node)->value, buffer);
1018
1038
  break;
1019
1039
  }
@@ -1073,9 +1093,9 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1073
1093
  case PM_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE: {
1074
1094
  pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_instance_variable_operator_write_node_t *)node)->name));
1075
1095
  pm_serialize_location(parser, &((pm_instance_variable_operator_write_node_t *)node)->name_loc, buffer);
1076
- pm_serialize_location(parser, &((pm_instance_variable_operator_write_node_t *)node)->operator_loc, buffer);
1096
+ pm_serialize_location(parser, &((pm_instance_variable_operator_write_node_t *)node)->binary_operator_loc, buffer);
1077
1097
  pm_serialize_node(parser, (pm_node_t *)((pm_instance_variable_operator_write_node_t *)node)->value, buffer);
1078
- pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_instance_variable_operator_write_node_t *)node)->operator));
1098
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_instance_variable_operator_write_node_t *)node)->binary_operator));
1079
1099
  break;
1080
1100
  }
1081
1101
  case PM_INSTANCE_VARIABLE_OR_WRITE_NODE: {
@@ -1102,6 +1122,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1102
1122
  }
1103
1123
  case PM_INTEGER_NODE: {
1104
1124
  pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1125
+ pm_serialize_integer(&((pm_integer_node_t *)node)->value, buffer);
1105
1126
  break;
1106
1127
  }
1107
1128
  case PM_INTERPOLATED_MATCH_LAST_LINE_NODE: {
@@ -1127,6 +1148,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1127
1148
  break;
1128
1149
  }
1129
1150
  case PM_INTERPOLATED_STRING_NODE: {
1151
+ pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1130
1152
  if (((pm_interpolated_string_node_t *)node)->opening_loc.start == NULL) {
1131
1153
  pm_buffer_append_byte(buffer, 0);
1132
1154
  } else {
@@ -1176,6 +1198,9 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1176
1198
  pm_serialize_location(parser, &((pm_interpolated_x_string_node_t *)node)->closing_loc, buffer);
1177
1199
  break;
1178
1200
  }
1201
+ case PM_IT_PARAMETERS_NODE: {
1202
+ break;
1203
+ }
1179
1204
  case PM_KEYWORD_HASH_NODE: {
1180
1205
  pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1181
1206
  uint32_t elements_size = pm_sizet_to_u32(((pm_keyword_hash_node_t *)node)->elements.size);
@@ -1228,10 +1253,10 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1228
1253
  }
1229
1254
  case PM_LOCAL_VARIABLE_OPERATOR_WRITE_NODE: {
1230
1255
  pm_serialize_location(parser, &((pm_local_variable_operator_write_node_t *)node)->name_loc, buffer);
1231
- pm_serialize_location(parser, &((pm_local_variable_operator_write_node_t *)node)->operator_loc, buffer);
1256
+ pm_serialize_location(parser, &((pm_local_variable_operator_write_node_t *)node)->binary_operator_loc, buffer);
1232
1257
  pm_serialize_node(parser, (pm_node_t *)((pm_local_variable_operator_write_node_t *)node)->value, buffer);
1233
1258
  pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_local_variable_operator_write_node_t *)node)->name));
1234
- pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_local_variable_operator_write_node_t *)node)->operator));
1259
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_local_variable_operator_write_node_t *)node)->binary_operator));
1235
1260
  pm_buffer_append_varuint(buffer, ((pm_local_variable_operator_write_node_t *)node)->depth);
1236
1261
  break;
1237
1262
  }
@@ -1602,6 +1627,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1602
1627
  break;
1603
1628
  }
1604
1629
  case PM_RETURN_NODE: {
1630
+ pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1605
1631
  pm_serialize_location(parser, &((pm_return_node_t *)node)->keyword_loc, buffer);
1606
1632
  if (((pm_return_node_t *)node)->arguments == NULL) {
1607
1633
  pm_buffer_append_byte(buffer, 0);
@@ -1613,6 +1639,11 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1613
1639
  case PM_SELF_NODE: {
1614
1640
  break;
1615
1641
  }
1642
+ case PM_SHAREABLE_CONSTANT_NODE: {
1643
+ pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1644
+ pm_serialize_node(parser, (pm_node_t *)((pm_shareable_constant_node_t *)node)->write, buffer);
1645
+ break;
1646
+ }
1616
1647
  case PM_SINGLETON_CLASS_NODE: {
1617
1648
  uint32_t locals_size = pm_sizet_to_u32(((pm_singleton_class_node_t *)node)->locals.size);
1618
1649
  pm_buffer_append_varuint(buffer, locals_size);
@@ -1634,6 +1665,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1634
1665
  break;
1635
1666
  }
1636
1667
  case PM_SOURCE_FILE_NODE: {
1668
+ pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1637
1669
  pm_serialize_string(parser, &((pm_source_file_node_t *)node)->filepath, buffer);
1638
1670
  break;
1639
1671
  }
@@ -1787,6 +1819,12 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1787
1819
  for (uint32_t index = 0; index < conditions_size; index++) {
1788
1820
  pm_serialize_node(parser, (pm_node_t *) ((pm_when_node_t *)node)->conditions.nodes[index], buffer);
1789
1821
  }
1822
+ if (((pm_when_node_t *)node)->then_keyword_loc.start == NULL) {
1823
+ pm_buffer_append_byte(buffer, 0);
1824
+ } else {
1825
+ pm_buffer_append_byte(buffer, 1);
1826
+ pm_serialize_location(parser, &((pm_when_node_t *)node)->then_keyword_loc, buffer);
1827
+ }
1790
1828
  if (((pm_when_node_t *)node)->statements == NULL) {
1791
1829
  pm_buffer_append_byte(buffer, 0);
1792
1830
  } else {
@@ -1909,6 +1947,9 @@ pm_serialize_data_loc(const pm_parser_t *parser, pm_buffer_t *buffer) {
1909
1947
 
1910
1948
  static void
1911
1949
  pm_serialize_diagnostic(pm_parser_t *parser, pm_diagnostic_t *diagnostic, pm_buffer_t *buffer) {
1950
+ // serialize the type
1951
+ pm_buffer_append_varuint(buffer, (uint32_t) diagnostic->diag_id);
1952
+
1912
1953
  // serialize message
1913
1954
  size_t message_length = strlen(diagnostic->message);
1914
1955
  pm_buffer_append_varuint(buffer, pm_sizet_to_u32(message_length));
@@ -1952,7 +1993,7 @@ pm_serialize_metadata(pm_parser_t *parser, pm_buffer_t *buffer) {
1952
1993
  pm_serialize_diagnostic_list(parser, &parser->warning_list, buffer);
1953
1994
  }
1954
1995
 
1955
- #line 243 "serialize.c.erb"
1996
+ #line 271 "serialize.c.erb"
1956
1997
  /**
1957
1998
  * Serialize the metadata, nodes, and constant pool.
1958
1999
  */
@@ -2084,23 +2125,4 @@ pm_serialize_parse_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size,
2084
2125
  pm_options_free(&options);
2085
2126
  }
2086
2127
 
2087
- /**
2088
- * Parse the source and return true if it parses without errors or warnings.
2089
- */
2090
- PRISM_EXPORTED_FUNCTION bool
2091
- pm_parse_success_p(const uint8_t *source, size_t size, const char *data) {
2092
- pm_options_t options = { 0 };
2093
- pm_options_read(&options, data);
2094
-
2095
- pm_parser_t parser;
2096
- pm_parser_init(&parser, source, size, &options);
2097
-
2098
- pm_node_t *node = pm_parse(&parser);
2099
- pm_node_destroy(&parser, node);
2100
-
2101
- bool result = parser.error_list.size == 0 && parser.warning_list.size == 0;
2102
- pm_parser_free(&parser);
2103
- pm_options_free(&options);
2104
-
2105
- return result;
2106
- }
2128
+ #endif