prism 0.18.0 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -1
  3. data/README.md +2 -1
  4. data/config.yml +188 -55
  5. data/docs/building.md +9 -2
  6. data/docs/configuration.md +10 -9
  7. data/docs/encoding.md +24 -56
  8. data/docs/local_variable_depth.md +229 -0
  9. data/docs/ruby_api.md +2 -0
  10. data/docs/serialization.md +18 -13
  11. data/ext/prism/api_node.c +337 -195
  12. data/ext/prism/extconf.rb +13 -7
  13. data/ext/prism/extension.c +96 -32
  14. data/ext/prism/extension.h +1 -1
  15. data/include/prism/ast.h +340 -137
  16. data/include/prism/defines.h +17 -0
  17. data/include/prism/diagnostic.h +11 -5
  18. data/include/prism/encoding.h +248 -0
  19. data/include/prism/options.h +2 -2
  20. data/include/prism/parser.h +62 -42
  21. data/include/prism/regexp.h +2 -2
  22. data/include/prism/util/pm_buffer.h +9 -1
  23. data/include/prism/util/pm_memchr.h +2 -2
  24. data/include/prism/util/pm_strpbrk.h +3 -3
  25. data/include/prism/version.h +2 -2
  26. data/include/prism.h +13 -15
  27. data/lib/prism/compiler.rb +12 -0
  28. data/lib/prism/debug.rb +9 -4
  29. data/lib/prism/desugar_compiler.rb +3 -3
  30. data/lib/prism/dispatcher.rb +56 -0
  31. data/lib/prism/dot_visitor.rb +476 -198
  32. data/lib/prism/dsl.rb +66 -46
  33. data/lib/prism/ffi.rb +16 -3
  34. data/lib/prism/lex_compat.rb +19 -9
  35. data/lib/prism/mutation_compiler.rb +20 -0
  36. data/lib/prism/node.rb +1173 -450
  37. data/lib/prism/node_ext.rb +41 -16
  38. data/lib/prism/parse_result.rb +12 -15
  39. data/lib/prism/ripper_compat.rb +49 -34
  40. data/lib/prism/serialize.rb +242 -212
  41. data/lib/prism/visitor.rb +12 -0
  42. data/lib/prism.rb +20 -4
  43. data/prism.gemspec +4 -10
  44. data/rbi/prism.rbi +605 -230
  45. data/rbi/prism_static.rbi +3 -0
  46. data/sig/prism.rbs +379 -124
  47. data/sig/prism_static.rbs +1 -0
  48. data/src/diagnostic.c +228 -222
  49. data/src/encoding.c +5137 -0
  50. data/src/node.c +66 -0
  51. data/src/options.c +21 -2
  52. data/src/prettyprint.c +806 -406
  53. data/src/prism.c +1092 -700
  54. data/src/regexp.c +3 -3
  55. data/src/serialize.c +227 -157
  56. data/src/util/pm_buffer.c +10 -1
  57. data/src/util/pm_memchr.c +1 -1
  58. data/src/util/pm_strpbrk.c +4 -4
  59. metadata +5 -11
  60. data/include/prism/enc/pm_encoding.h +0 -227
  61. data/src/enc/pm_big5.c +0 -116
  62. data/src/enc/pm_cp51932.c +0 -57
  63. data/src/enc/pm_euc_jp.c +0 -69
  64. data/src/enc/pm_gbk.c +0 -65
  65. data/src/enc/pm_shift_jis.c +0 -57
  66. data/src/enc/pm_tables.c +0 -2073
  67. data/src/enc/pm_unicode.c +0 -2369
  68. data/src/enc/pm_windows_31j.c +0 -57
data/src/serialize.c CHANGED
@@ -22,13 +22,13 @@ pm_sizet_to_u32(size_t value) {
22
22
  }
23
23
 
24
24
  static void
25
- pm_serialize_location(pm_parser_t *parser, pm_location_t *location, pm_buffer_t *buffer) {
25
+ pm_serialize_location(const pm_parser_t *parser, const pm_location_t *location, pm_buffer_t *buffer) {
26
26
  assert(location->start);
27
27
  assert(location->end);
28
28
  assert(location->start <= location->end);
29
29
 
30
- pm_buffer_append_varint(buffer, pm_ptrdifft_to_u32(location->start - parser->start));
31
- pm_buffer_append_varint(buffer, pm_ptrdifft_to_u32(location->end - location->start));
30
+ pm_buffer_append_varuint(buffer, pm_ptrdifft_to_u32(location->start - parser->start));
31
+ pm_buffer_append_varuint(buffer, pm_ptrdifft_to_u32(location->end - location->start));
32
32
  }
33
33
 
34
34
  static void
@@ -36,15 +36,15 @@ pm_serialize_string(pm_parser_t *parser, pm_string_t *string, pm_buffer_t *buffe
36
36
  switch (string->type) {
37
37
  case PM_STRING_SHARED: {
38
38
  pm_buffer_append_byte(buffer, 1);
39
- pm_buffer_append_varint(buffer, pm_ptrdifft_to_u32(pm_string_source(string) - parser->start));
40
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(pm_string_length(string)));
39
+ pm_buffer_append_varuint(buffer, pm_ptrdifft_to_u32(pm_string_source(string) - parser->start));
40
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(pm_string_length(string)));
41
41
  break;
42
42
  }
43
43
  case PM_STRING_OWNED:
44
44
  case PM_STRING_CONSTANT: {
45
45
  uint32_t length = pm_sizet_to_u32(pm_string_length(string));
46
46
  pm_buffer_append_byte(buffer, 2);
47
- pm_buffer_append_varint(buffer, length);
47
+ pm_buffer_append_varuint(buffer, length);
48
48
  pm_buffer_append_bytes(buffer, pm_string_source(string), length);
49
49
  break;
50
50
  }
@@ -92,17 +92,18 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
92
92
  break;
93
93
  }
94
94
  case PM_ARGUMENTS_NODE: {
95
+ pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
95
96
  uint32_t arguments_size = pm_sizet_to_u32(((pm_arguments_node_t *)node)->arguments.size);
96
- pm_buffer_append_varint(buffer, arguments_size);
97
+ pm_buffer_append_varuint(buffer, arguments_size);
97
98
  for (uint32_t index = 0; index < arguments_size; index++) {
98
99
  pm_serialize_node(parser, (pm_node_t *) ((pm_arguments_node_t *)node)->arguments.nodes[index], buffer);
99
100
  }
100
- pm_buffer_append_varint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
101
101
  break;
102
102
  }
103
103
  case PM_ARRAY_NODE: {
104
+ pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
104
105
  uint32_t elements_size = pm_sizet_to_u32(((pm_array_node_t *)node)->elements.size);
105
- pm_buffer_append_varint(buffer, elements_size);
106
+ pm_buffer_append_varuint(buffer, elements_size);
106
107
  for (uint32_t index = 0; index < elements_size; index++) {
107
108
  pm_serialize_node(parser, (pm_node_t *) ((pm_array_node_t *)node)->elements.nodes[index], buffer);
108
109
  }
@@ -127,7 +128,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
127
128
  pm_serialize_node(parser, (pm_node_t *)((pm_array_pattern_node_t *)node)->constant, buffer);
128
129
  }
129
130
  uint32_t requireds_size = pm_sizet_to_u32(((pm_array_pattern_node_t *)node)->requireds.size);
130
- pm_buffer_append_varint(buffer, requireds_size);
131
+ pm_buffer_append_varuint(buffer, requireds_size);
131
132
  for (uint32_t index = 0; index < requireds_size; index++) {
132
133
  pm_serialize_node(parser, (pm_node_t *) ((pm_array_pattern_node_t *)node)->requireds.nodes[index], buffer);
133
134
  }
@@ -137,7 +138,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
137
138
  pm_serialize_node(parser, (pm_node_t *)((pm_array_pattern_node_t *)node)->rest, buffer);
138
139
  }
139
140
  uint32_t posts_size = pm_sizet_to_u32(((pm_array_pattern_node_t *)node)->posts.size);
140
- pm_buffer_append_varint(buffer, posts_size);
141
+ pm_buffer_append_varuint(buffer, posts_size);
141
142
  for (uint32_t index = 0; index < posts_size; index++) {
142
143
  pm_serialize_node(parser, (pm_node_t *) ((pm_array_pattern_node_t *)node)->posts.nodes[index], buffer);
143
144
  }
@@ -180,7 +181,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
180
181
  break;
181
182
  }
182
183
  case PM_BACK_REFERENCE_READ_NODE: {
183
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_back_reference_read_node_t *)node)->name));
184
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_back_reference_read_node_t *)node)->name));
184
185
  break;
185
186
  }
186
187
  case PM_BEGIN_NODE: {
@@ -228,15 +229,16 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
228
229
  break;
229
230
  }
230
231
  case PM_BLOCK_LOCAL_VARIABLE_NODE: {
231
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_block_local_variable_node_t *)node)->name));
232
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_block_local_variable_node_t *)node)->name));
232
233
  break;
233
234
  }
234
235
  case PM_BLOCK_NODE: {
235
236
  uint32_t locals_size = pm_sizet_to_u32(((pm_block_node_t *)node)->locals.size);
236
- pm_buffer_append_varint(buffer, locals_size);
237
+ pm_buffer_append_varuint(buffer, locals_size);
237
238
  for (uint32_t index = 0; index < locals_size; index++) {
238
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_block_node_t *)node)->locals.ids[index]));
239
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_block_node_t *)node)->locals.ids[index]));
239
240
  }
241
+ pm_buffer_append_varuint(buffer, ((pm_block_node_t *)node)->locals_body_index);
240
242
  if (((pm_block_node_t *)node)->parameters == NULL) {
241
243
  pm_buffer_append_byte(buffer, 0);
242
244
  } else {
@@ -252,7 +254,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
252
254
  break;
253
255
  }
254
256
  case PM_BLOCK_PARAMETER_NODE: {
255
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_block_parameter_node_t *)node)->name));
257
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_block_parameter_node_t *)node)->name));
256
258
  if (((pm_block_parameter_node_t *)node)->name_loc.start == NULL) {
257
259
  pm_buffer_append_byte(buffer, 0);
258
260
  } else {
@@ -269,7 +271,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
269
271
  pm_serialize_node(parser, (pm_node_t *)((pm_block_parameters_node_t *)node)->parameters, buffer);
270
272
  }
271
273
  uint32_t locals_size = pm_sizet_to_u32(((pm_block_parameters_node_t *)node)->locals.size);
272
- pm_buffer_append_varint(buffer, locals_size);
274
+ pm_buffer_append_varuint(buffer, locals_size);
273
275
  for (uint32_t index = 0; index < locals_size; index++) {
274
276
  pm_serialize_node(parser, (pm_node_t *) ((pm_block_parameters_node_t *)node)->locals.nodes[index], buffer);
275
277
  }
@@ -297,6 +299,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
297
299
  break;
298
300
  }
299
301
  case PM_CALL_AND_WRITE_NODE: {
302
+ pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
300
303
  if (((pm_call_and_write_node_t *)node)->receiver == NULL) {
301
304
  pm_buffer_append_byte(buffer, 0);
302
305
  } else {
@@ -314,14 +317,14 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
314
317
  pm_buffer_append_byte(buffer, 1);
315
318
  pm_serialize_location(parser, &((pm_call_and_write_node_t *)node)->message_loc, buffer);
316
319
  }
317
- pm_buffer_append_varint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
318
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_call_and_write_node_t *)node)->read_name));
319
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_call_and_write_node_t *)node)->write_name));
320
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_call_and_write_node_t *)node)->read_name));
321
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_call_and_write_node_t *)node)->write_name));
320
322
  pm_serialize_location(parser, &((pm_call_and_write_node_t *)node)->operator_loc, buffer);
321
323
  pm_serialize_node(parser, (pm_node_t *)((pm_call_and_write_node_t *)node)->value, buffer);
322
324
  break;
323
325
  }
324
326
  case PM_CALL_NODE: {
327
+ pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
325
328
  if (((pm_call_node_t *)node)->receiver == NULL) {
326
329
  pm_buffer_append_byte(buffer, 0);
327
330
  } else {
@@ -333,6 +336,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
333
336
  pm_buffer_append_byte(buffer, 1);
334
337
  pm_serialize_location(parser, &((pm_call_node_t *)node)->call_operator_loc, buffer);
335
338
  }
339
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_call_node_t *)node)->name));
336
340
  if (((pm_call_node_t *)node)->message_loc.start == NULL) {
337
341
  pm_buffer_append_byte(buffer, 0);
338
342
  } else {
@@ -361,11 +365,10 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
361
365
  } else {
362
366
  pm_serialize_node(parser, (pm_node_t *)((pm_call_node_t *)node)->block, buffer);
363
367
  }
364
- pm_buffer_append_varint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
365
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_call_node_t *)node)->name));
366
368
  break;
367
369
  }
368
370
  case PM_CALL_OPERATOR_WRITE_NODE: {
371
+ pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
369
372
  if (((pm_call_operator_write_node_t *)node)->receiver == NULL) {
370
373
  pm_buffer_append_byte(buffer, 0);
371
374
  } else {
@@ -383,15 +386,15 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
383
386
  pm_buffer_append_byte(buffer, 1);
384
387
  pm_serialize_location(parser, &((pm_call_operator_write_node_t *)node)->message_loc, buffer);
385
388
  }
386
- pm_buffer_append_varint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
387
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_call_operator_write_node_t *)node)->read_name));
388
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_call_operator_write_node_t *)node)->write_name));
389
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_call_operator_write_node_t *)node)->operator));
389
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_call_operator_write_node_t *)node)->read_name));
390
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_call_operator_write_node_t *)node)->write_name));
391
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_call_operator_write_node_t *)node)->operator));
390
392
  pm_serialize_location(parser, &((pm_call_operator_write_node_t *)node)->operator_loc, buffer);
391
393
  pm_serialize_node(parser, (pm_node_t *)((pm_call_operator_write_node_t *)node)->value, buffer);
392
394
  break;
393
395
  }
394
396
  case PM_CALL_OR_WRITE_NODE: {
397
+ pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
395
398
  if (((pm_call_or_write_node_t *)node)->receiver == NULL) {
396
399
  pm_buffer_append_byte(buffer, 0);
397
400
  } else {
@@ -409,13 +412,20 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
409
412
  pm_buffer_append_byte(buffer, 1);
410
413
  pm_serialize_location(parser, &((pm_call_or_write_node_t *)node)->message_loc, buffer);
411
414
  }
412
- pm_buffer_append_varint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
413
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_call_or_write_node_t *)node)->read_name));
414
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_call_or_write_node_t *)node)->write_name));
415
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_call_or_write_node_t *)node)->read_name));
416
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_call_or_write_node_t *)node)->write_name));
415
417
  pm_serialize_location(parser, &((pm_call_or_write_node_t *)node)->operator_loc, buffer);
416
418
  pm_serialize_node(parser, (pm_node_t *)((pm_call_or_write_node_t *)node)->value, buffer);
417
419
  break;
418
420
  }
421
+ case PM_CALL_TARGET_NODE: {
422
+ pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
423
+ pm_serialize_node(parser, (pm_node_t *)((pm_call_target_node_t *)node)->receiver, buffer);
424
+ pm_serialize_location(parser, &((pm_call_target_node_t *)node)->call_operator_loc, buffer);
425
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_call_target_node_t *)node)->name));
426
+ pm_serialize_location(parser, &((pm_call_target_node_t *)node)->message_loc, buffer);
427
+ break;
428
+ }
419
429
  case PM_CAPTURE_PATTERN_NODE: {
420
430
  pm_serialize_node(parser, (pm_node_t *)((pm_capture_pattern_node_t *)node)->value, buffer);
421
431
  pm_serialize_node(parser, (pm_node_t *)((pm_capture_pattern_node_t *)node)->target, buffer);
@@ -429,7 +439,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
429
439
  pm_serialize_node(parser, (pm_node_t *)((pm_case_match_node_t *)node)->predicate, buffer);
430
440
  }
431
441
  uint32_t conditions_size = pm_sizet_to_u32(((pm_case_match_node_t *)node)->conditions.size);
432
- pm_buffer_append_varint(buffer, conditions_size);
442
+ pm_buffer_append_varuint(buffer, conditions_size);
433
443
  for (uint32_t index = 0; index < conditions_size; index++) {
434
444
  pm_serialize_node(parser, (pm_node_t *) ((pm_case_match_node_t *)node)->conditions.nodes[index], buffer);
435
445
  }
@@ -449,7 +459,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
449
459
  pm_serialize_node(parser, (pm_node_t *)((pm_case_node_t *)node)->predicate, buffer);
450
460
  }
451
461
  uint32_t conditions_size = pm_sizet_to_u32(((pm_case_node_t *)node)->conditions.size);
452
- pm_buffer_append_varint(buffer, conditions_size);
462
+ pm_buffer_append_varuint(buffer, conditions_size);
453
463
  for (uint32_t index = 0; index < conditions_size; index++) {
454
464
  pm_serialize_node(parser, (pm_node_t *) ((pm_case_node_t *)node)->conditions.nodes[index], buffer);
455
465
  }
@@ -464,9 +474,9 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
464
474
  }
465
475
  case PM_CLASS_NODE: {
466
476
  uint32_t locals_size = pm_sizet_to_u32(((pm_class_node_t *)node)->locals.size);
467
- pm_buffer_append_varint(buffer, locals_size);
477
+ pm_buffer_append_varuint(buffer, locals_size);
468
478
  for (uint32_t index = 0; index < locals_size; index++) {
469
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_class_node_t *)node)->locals.ids[index]));
479
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_node_t *)node)->locals.ids[index]));
470
480
  }
471
481
  pm_serialize_location(parser, &((pm_class_node_t *)node)->class_keyword_loc, buffer);
472
482
  pm_serialize_node(parser, (pm_node_t *)((pm_class_node_t *)node)->constant_path, buffer);
@@ -487,41 +497,41 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
487
497
  pm_serialize_node(parser, (pm_node_t *)((pm_class_node_t *)node)->body, buffer);
488
498
  }
489
499
  pm_serialize_location(parser, &((pm_class_node_t *)node)->end_keyword_loc, buffer);
490
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_class_node_t *)node)->name));
500
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_node_t *)node)->name));
491
501
  break;
492
502
  }
493
503
  case PM_CLASS_VARIABLE_AND_WRITE_NODE: {
494
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_class_variable_and_write_node_t *)node)->name));
504
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_variable_and_write_node_t *)node)->name));
495
505
  pm_serialize_location(parser, &((pm_class_variable_and_write_node_t *)node)->name_loc, buffer);
496
506
  pm_serialize_location(parser, &((pm_class_variable_and_write_node_t *)node)->operator_loc, buffer);
497
507
  pm_serialize_node(parser, (pm_node_t *)((pm_class_variable_and_write_node_t *)node)->value, buffer);
498
508
  break;
499
509
  }
500
510
  case PM_CLASS_VARIABLE_OPERATOR_WRITE_NODE: {
501
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_class_variable_operator_write_node_t *)node)->name));
511
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_variable_operator_write_node_t *)node)->name));
502
512
  pm_serialize_location(parser, &((pm_class_variable_operator_write_node_t *)node)->name_loc, buffer);
503
513
  pm_serialize_location(parser, &((pm_class_variable_operator_write_node_t *)node)->operator_loc, buffer);
504
514
  pm_serialize_node(parser, (pm_node_t *)((pm_class_variable_operator_write_node_t *)node)->value, buffer);
505
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_class_variable_operator_write_node_t *)node)->operator));
515
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_variable_operator_write_node_t *)node)->operator));
506
516
  break;
507
517
  }
508
518
  case PM_CLASS_VARIABLE_OR_WRITE_NODE: {
509
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_class_variable_or_write_node_t *)node)->name));
519
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_variable_or_write_node_t *)node)->name));
510
520
  pm_serialize_location(parser, &((pm_class_variable_or_write_node_t *)node)->name_loc, buffer);
511
521
  pm_serialize_location(parser, &((pm_class_variable_or_write_node_t *)node)->operator_loc, buffer);
512
522
  pm_serialize_node(parser, (pm_node_t *)((pm_class_variable_or_write_node_t *)node)->value, buffer);
513
523
  break;
514
524
  }
515
525
  case PM_CLASS_VARIABLE_READ_NODE: {
516
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_class_variable_read_node_t *)node)->name));
526
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_variable_read_node_t *)node)->name));
517
527
  break;
518
528
  }
519
529
  case PM_CLASS_VARIABLE_TARGET_NODE: {
520
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_class_variable_target_node_t *)node)->name));
530
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_variable_target_node_t *)node)->name));
521
531
  break;
522
532
  }
523
533
  case PM_CLASS_VARIABLE_WRITE_NODE: {
524
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_class_variable_write_node_t *)node)->name));
534
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_variable_write_node_t *)node)->name));
525
535
  pm_serialize_location(parser, &((pm_class_variable_write_node_t *)node)->name_loc, buffer);
526
536
  pm_serialize_node(parser, (pm_node_t *)((pm_class_variable_write_node_t *)node)->value, buffer);
527
537
  if (((pm_class_variable_write_node_t *)node)->operator_loc.start == NULL) {
@@ -533,22 +543,22 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
533
543
  break;
534
544
  }
535
545
  case PM_CONSTANT_AND_WRITE_NODE: {
536
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_constant_and_write_node_t *)node)->name));
546
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_and_write_node_t *)node)->name));
537
547
  pm_serialize_location(parser, &((pm_constant_and_write_node_t *)node)->name_loc, buffer);
538
548
  pm_serialize_location(parser, &((pm_constant_and_write_node_t *)node)->operator_loc, buffer);
539
549
  pm_serialize_node(parser, (pm_node_t *)((pm_constant_and_write_node_t *)node)->value, buffer);
540
550
  break;
541
551
  }
542
552
  case PM_CONSTANT_OPERATOR_WRITE_NODE: {
543
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_constant_operator_write_node_t *)node)->name));
553
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_operator_write_node_t *)node)->name));
544
554
  pm_serialize_location(parser, &((pm_constant_operator_write_node_t *)node)->name_loc, buffer);
545
555
  pm_serialize_location(parser, &((pm_constant_operator_write_node_t *)node)->operator_loc, buffer);
546
556
  pm_serialize_node(parser, (pm_node_t *)((pm_constant_operator_write_node_t *)node)->value, buffer);
547
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_constant_operator_write_node_t *)node)->operator));
557
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_operator_write_node_t *)node)->operator));
548
558
  break;
549
559
  }
550
560
  case PM_CONSTANT_OR_WRITE_NODE: {
551
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_constant_or_write_node_t *)node)->name));
561
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_or_write_node_t *)node)->name));
552
562
  pm_serialize_location(parser, &((pm_constant_or_write_node_t *)node)->name_loc, buffer);
553
563
  pm_serialize_location(parser, &((pm_constant_or_write_node_t *)node)->operator_loc, buffer);
554
564
  pm_serialize_node(parser, (pm_node_t *)((pm_constant_or_write_node_t *)node)->value, buffer);
@@ -574,7 +584,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
574
584
  pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_operator_write_node_t *)node)->target, buffer);
575
585
  pm_serialize_location(parser, &((pm_constant_path_operator_write_node_t *)node)->operator_loc, buffer);
576
586
  pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_operator_write_node_t *)node)->value, buffer);
577
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_constant_path_operator_write_node_t *)node)->operator));
587
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_path_operator_write_node_t *)node)->operator));
578
588
  break;
579
589
  }
580
590
  case PM_CONSTANT_PATH_OR_WRITE_NODE: {
@@ -600,15 +610,15 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
600
610
  break;
601
611
  }
602
612
  case PM_CONSTANT_READ_NODE: {
603
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_constant_read_node_t *)node)->name));
613
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_read_node_t *)node)->name));
604
614
  break;
605
615
  }
606
616
  case PM_CONSTANT_TARGET_NODE: {
607
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_constant_target_node_t *)node)->name));
617
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_target_node_t *)node)->name));
608
618
  break;
609
619
  }
610
620
  case PM_CONSTANT_WRITE_NODE: {
611
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_constant_write_node_t *)node)->name));
621
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_write_node_t *)node)->name));
612
622
  pm_serialize_location(parser, &((pm_constant_write_node_t *)node)->name_loc, buffer);
613
623
  pm_serialize_node(parser, (pm_node_t *)((pm_constant_write_node_t *)node)->value, buffer);
614
624
  pm_serialize_location(parser, &((pm_constant_write_node_t *)node)->operator_loc, buffer);
@@ -619,7 +629,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
619
629
  // encoding of location u32s make us need to save this offset.
620
630
  size_t length_offset = buffer->length;
621
631
  pm_buffer_append_string(buffer, "\0\0\0\0", 4); /* consume 4 bytes, updated below */
622
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_def_node_t *)node)->name));
632
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_def_node_t *)node)->name));
623
633
  pm_serialize_location(parser, &((pm_def_node_t *)node)->name_loc, buffer);
624
634
  if (((pm_def_node_t *)node)->receiver == NULL) {
625
635
  pm_buffer_append_byte(buffer, 0);
@@ -637,10 +647,11 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
637
647
  pm_serialize_node(parser, (pm_node_t *)((pm_def_node_t *)node)->body, buffer);
638
648
  }
639
649
  uint32_t locals_size = pm_sizet_to_u32(((pm_def_node_t *)node)->locals.size);
640
- pm_buffer_append_varint(buffer, locals_size);
650
+ pm_buffer_append_varuint(buffer, locals_size);
641
651
  for (uint32_t index = 0; index < locals_size; index++) {
642
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_def_node_t *)node)->locals.ids[index]));
652
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_def_node_t *)node)->locals.ids[index]));
643
653
  }
654
+ pm_buffer_append_varuint(buffer, ((pm_def_node_t *)node)->locals_body_index);
644
655
  pm_serialize_location(parser, &((pm_def_node_t *)node)->def_keyword_loc, buffer);
645
656
  if (((pm_def_node_t *)node)->operator_loc.start == NULL) {
646
657
  pm_buffer_append_byte(buffer, 0);
@@ -745,7 +756,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
745
756
  }
746
757
  pm_serialize_node(parser, (pm_node_t *)((pm_find_pattern_node_t *)node)->left, buffer);
747
758
  uint32_t requireds_size = pm_sizet_to_u32(((pm_find_pattern_node_t *)node)->requireds.size);
748
- pm_buffer_append_varint(buffer, requireds_size);
759
+ pm_buffer_append_varuint(buffer, requireds_size);
749
760
  for (uint32_t index = 0; index < requireds_size; index++) {
750
761
  pm_serialize_node(parser, (pm_node_t *) ((pm_find_pattern_node_t *)node)->requireds.nodes[index], buffer);
751
762
  }
@@ -765,6 +776,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
765
776
  break;
766
777
  }
767
778
  case PM_FLIP_FLOP_NODE: {
779
+ pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
768
780
  if (((pm_flip_flop_node_t *)node)->left == NULL) {
769
781
  pm_buffer_append_byte(buffer, 0);
770
782
  } else {
@@ -776,7 +788,6 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
776
788
  pm_serialize_node(parser, (pm_node_t *)((pm_flip_flop_node_t *)node)->right, buffer);
777
789
  }
778
790
  pm_serialize_location(parser, &((pm_flip_flop_node_t *)node)->operator_loc, buffer);
779
- pm_buffer_append_varint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
780
791
  break;
781
792
  }
782
793
  case PM_FLOAT_NODE: {
@@ -816,37 +827,37 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
816
827
  break;
817
828
  }
818
829
  case PM_GLOBAL_VARIABLE_AND_WRITE_NODE: {
819
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_global_variable_and_write_node_t *)node)->name));
830
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_global_variable_and_write_node_t *)node)->name));
820
831
  pm_serialize_location(parser, &((pm_global_variable_and_write_node_t *)node)->name_loc, buffer);
821
832
  pm_serialize_location(parser, &((pm_global_variable_and_write_node_t *)node)->operator_loc, buffer);
822
833
  pm_serialize_node(parser, (pm_node_t *)((pm_global_variable_and_write_node_t *)node)->value, buffer);
823
834
  break;
824
835
  }
825
836
  case PM_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE: {
826
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_global_variable_operator_write_node_t *)node)->name));
837
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_global_variable_operator_write_node_t *)node)->name));
827
838
  pm_serialize_location(parser, &((pm_global_variable_operator_write_node_t *)node)->name_loc, buffer);
828
839
  pm_serialize_location(parser, &((pm_global_variable_operator_write_node_t *)node)->operator_loc, buffer);
829
840
  pm_serialize_node(parser, (pm_node_t *)((pm_global_variable_operator_write_node_t *)node)->value, buffer);
830
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_global_variable_operator_write_node_t *)node)->operator));
841
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_global_variable_operator_write_node_t *)node)->operator));
831
842
  break;
832
843
  }
833
844
  case PM_GLOBAL_VARIABLE_OR_WRITE_NODE: {
834
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_global_variable_or_write_node_t *)node)->name));
845
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_global_variable_or_write_node_t *)node)->name));
835
846
  pm_serialize_location(parser, &((pm_global_variable_or_write_node_t *)node)->name_loc, buffer);
836
847
  pm_serialize_location(parser, &((pm_global_variable_or_write_node_t *)node)->operator_loc, buffer);
837
848
  pm_serialize_node(parser, (pm_node_t *)((pm_global_variable_or_write_node_t *)node)->value, buffer);
838
849
  break;
839
850
  }
840
851
  case PM_GLOBAL_VARIABLE_READ_NODE: {
841
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_global_variable_read_node_t *)node)->name));
852
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_global_variable_read_node_t *)node)->name));
842
853
  break;
843
854
  }
844
855
  case PM_GLOBAL_VARIABLE_TARGET_NODE: {
845
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_global_variable_target_node_t *)node)->name));
856
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_global_variable_target_node_t *)node)->name));
846
857
  break;
847
858
  }
848
859
  case PM_GLOBAL_VARIABLE_WRITE_NODE: {
849
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_global_variable_write_node_t *)node)->name));
860
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_global_variable_write_node_t *)node)->name));
850
861
  pm_serialize_location(parser, &((pm_global_variable_write_node_t *)node)->name_loc, buffer);
851
862
  pm_serialize_node(parser, (pm_node_t *)((pm_global_variable_write_node_t *)node)->value, buffer);
852
863
  pm_serialize_location(parser, &((pm_global_variable_write_node_t *)node)->operator_loc, buffer);
@@ -855,7 +866,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
855
866
  case PM_HASH_NODE: {
856
867
  pm_serialize_location(parser, &((pm_hash_node_t *)node)->opening_loc, buffer);
857
868
  uint32_t elements_size = pm_sizet_to_u32(((pm_hash_node_t *)node)->elements.size);
858
- pm_buffer_append_varint(buffer, elements_size);
869
+ pm_buffer_append_varuint(buffer, elements_size);
859
870
  for (uint32_t index = 0; index < elements_size; index++) {
860
871
  pm_serialize_node(parser, (pm_node_t *) ((pm_hash_node_t *)node)->elements.nodes[index], buffer);
861
872
  }
@@ -869,7 +880,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
869
880
  pm_serialize_node(parser, (pm_node_t *)((pm_hash_pattern_node_t *)node)->constant, buffer);
870
881
  }
871
882
  uint32_t elements_size = pm_sizet_to_u32(((pm_hash_pattern_node_t *)node)->elements.size);
872
- pm_buffer_append_varint(buffer, elements_size);
883
+ pm_buffer_append_varuint(buffer, elements_size);
873
884
  for (uint32_t index = 0; index < elements_size; index++) {
874
885
  pm_serialize_node(parser, (pm_node_t *) ((pm_hash_pattern_node_t *)node)->elements.nodes[index], buffer);
875
886
  }
@@ -932,6 +943,9 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
932
943
  pm_serialize_node(parser, (pm_node_t *)((pm_implicit_node_t *)node)->value, buffer);
933
944
  break;
934
945
  }
946
+ case PM_IMPLICIT_REST_NODE: {
947
+ break;
948
+ }
935
949
  case PM_IN_NODE: {
936
950
  pm_serialize_node(parser, (pm_node_t *)((pm_in_node_t *)node)->pattern, buffer);
937
951
  if (((pm_in_node_t *)node)->statements == NULL) {
@@ -949,6 +963,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
949
963
  break;
950
964
  }
951
965
  case PM_INDEX_AND_WRITE_NODE: {
966
+ pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
952
967
  if (((pm_index_and_write_node_t *)node)->receiver == NULL) {
953
968
  pm_buffer_append_byte(buffer, 0);
954
969
  } else {
@@ -972,12 +987,12 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
972
987
  } else {
973
988
  pm_serialize_node(parser, (pm_node_t *)((pm_index_and_write_node_t *)node)->block, buffer);
974
989
  }
975
- pm_buffer_append_varint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
976
990
  pm_serialize_location(parser, &((pm_index_and_write_node_t *)node)->operator_loc, buffer);
977
991
  pm_serialize_node(parser, (pm_node_t *)((pm_index_and_write_node_t *)node)->value, buffer);
978
992
  break;
979
993
  }
980
994
  case PM_INDEX_OPERATOR_WRITE_NODE: {
995
+ pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
981
996
  if (((pm_index_operator_write_node_t *)node)->receiver == NULL) {
982
997
  pm_buffer_append_byte(buffer, 0);
983
998
  } else {
@@ -1001,13 +1016,13 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1001
1016
  } else {
1002
1017
  pm_serialize_node(parser, (pm_node_t *)((pm_index_operator_write_node_t *)node)->block, buffer);
1003
1018
  }
1004
- pm_buffer_append_varint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1005
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_index_operator_write_node_t *)node)->operator));
1019
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_index_operator_write_node_t *)node)->operator));
1006
1020
  pm_serialize_location(parser, &((pm_index_operator_write_node_t *)node)->operator_loc, buffer);
1007
1021
  pm_serialize_node(parser, (pm_node_t *)((pm_index_operator_write_node_t *)node)->value, buffer);
1008
1022
  break;
1009
1023
  }
1010
1024
  case PM_INDEX_OR_WRITE_NODE: {
1025
+ pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1011
1026
  if (((pm_index_or_write_node_t *)node)->receiver == NULL) {
1012
1027
  pm_buffer_append_byte(buffer, 0);
1013
1028
  } else {
@@ -1031,72 +1046,88 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1031
1046
  } else {
1032
1047
  pm_serialize_node(parser, (pm_node_t *)((pm_index_or_write_node_t *)node)->block, buffer);
1033
1048
  }
1034
- pm_buffer_append_varint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1035
1049
  pm_serialize_location(parser, &((pm_index_or_write_node_t *)node)->operator_loc, buffer);
1036
1050
  pm_serialize_node(parser, (pm_node_t *)((pm_index_or_write_node_t *)node)->value, buffer);
1037
1051
  break;
1038
1052
  }
1053
+ case PM_INDEX_TARGET_NODE: {
1054
+ pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1055
+ pm_serialize_node(parser, (pm_node_t *)((pm_index_target_node_t *)node)->receiver, buffer);
1056
+ pm_serialize_location(parser, &((pm_index_target_node_t *)node)->opening_loc, buffer);
1057
+ if (((pm_index_target_node_t *)node)->arguments == NULL) {
1058
+ pm_buffer_append_byte(buffer, 0);
1059
+ } else {
1060
+ pm_serialize_node(parser, (pm_node_t *)((pm_index_target_node_t *)node)->arguments, buffer);
1061
+ }
1062
+ pm_serialize_location(parser, &((pm_index_target_node_t *)node)->closing_loc, buffer);
1063
+ if (((pm_index_target_node_t *)node)->block == NULL) {
1064
+ pm_buffer_append_byte(buffer, 0);
1065
+ } else {
1066
+ pm_serialize_node(parser, (pm_node_t *)((pm_index_target_node_t *)node)->block, buffer);
1067
+ }
1068
+ break;
1069
+ }
1039
1070
  case PM_INSTANCE_VARIABLE_AND_WRITE_NODE: {
1040
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_instance_variable_and_write_node_t *)node)->name));
1071
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_instance_variable_and_write_node_t *)node)->name));
1041
1072
  pm_serialize_location(parser, &((pm_instance_variable_and_write_node_t *)node)->name_loc, buffer);
1042
1073
  pm_serialize_location(parser, &((pm_instance_variable_and_write_node_t *)node)->operator_loc, buffer);
1043
1074
  pm_serialize_node(parser, (pm_node_t *)((pm_instance_variable_and_write_node_t *)node)->value, buffer);
1044
1075
  break;
1045
1076
  }
1046
1077
  case PM_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE: {
1047
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_instance_variable_operator_write_node_t *)node)->name));
1078
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_instance_variable_operator_write_node_t *)node)->name));
1048
1079
  pm_serialize_location(parser, &((pm_instance_variable_operator_write_node_t *)node)->name_loc, buffer);
1049
1080
  pm_serialize_location(parser, &((pm_instance_variable_operator_write_node_t *)node)->operator_loc, buffer);
1050
1081
  pm_serialize_node(parser, (pm_node_t *)((pm_instance_variable_operator_write_node_t *)node)->value, buffer);
1051
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_instance_variable_operator_write_node_t *)node)->operator));
1082
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_instance_variable_operator_write_node_t *)node)->operator));
1052
1083
  break;
1053
1084
  }
1054
1085
  case PM_INSTANCE_VARIABLE_OR_WRITE_NODE: {
1055
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_instance_variable_or_write_node_t *)node)->name));
1086
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_instance_variable_or_write_node_t *)node)->name));
1056
1087
  pm_serialize_location(parser, &((pm_instance_variable_or_write_node_t *)node)->name_loc, buffer);
1057
1088
  pm_serialize_location(parser, &((pm_instance_variable_or_write_node_t *)node)->operator_loc, buffer);
1058
1089
  pm_serialize_node(parser, (pm_node_t *)((pm_instance_variable_or_write_node_t *)node)->value, buffer);
1059
1090
  break;
1060
1091
  }
1061
1092
  case PM_INSTANCE_VARIABLE_READ_NODE: {
1062
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_instance_variable_read_node_t *)node)->name));
1093
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_instance_variable_read_node_t *)node)->name));
1063
1094
  break;
1064
1095
  }
1065
1096
  case PM_INSTANCE_VARIABLE_TARGET_NODE: {
1066
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_instance_variable_target_node_t *)node)->name));
1097
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_instance_variable_target_node_t *)node)->name));
1067
1098
  break;
1068
1099
  }
1069
1100
  case PM_INSTANCE_VARIABLE_WRITE_NODE: {
1070
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_instance_variable_write_node_t *)node)->name));
1101
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_instance_variable_write_node_t *)node)->name));
1071
1102
  pm_serialize_location(parser, &((pm_instance_variable_write_node_t *)node)->name_loc, buffer);
1072
1103
  pm_serialize_node(parser, (pm_node_t *)((pm_instance_variable_write_node_t *)node)->value, buffer);
1073
1104
  pm_serialize_location(parser, &((pm_instance_variable_write_node_t *)node)->operator_loc, buffer);
1074
1105
  break;
1075
1106
  }
1076
1107
  case PM_INTEGER_NODE: {
1077
- pm_buffer_append_varint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1108
+ pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1078
1109
  break;
1079
1110
  }
1080
1111
  case PM_INTERPOLATED_MATCH_LAST_LINE_NODE: {
1112
+ pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1081
1113
  pm_serialize_location(parser, &((pm_interpolated_match_last_line_node_t *)node)->opening_loc, buffer);
1082
1114
  uint32_t parts_size = pm_sizet_to_u32(((pm_interpolated_match_last_line_node_t *)node)->parts.size);
1083
- pm_buffer_append_varint(buffer, parts_size);
1115
+ pm_buffer_append_varuint(buffer, parts_size);
1084
1116
  for (uint32_t index = 0; index < parts_size; index++) {
1085
1117
  pm_serialize_node(parser, (pm_node_t *) ((pm_interpolated_match_last_line_node_t *)node)->parts.nodes[index], buffer);
1086
1118
  }
1087
1119
  pm_serialize_location(parser, &((pm_interpolated_match_last_line_node_t *)node)->closing_loc, buffer);
1088
- pm_buffer_append_varint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1089
1120
  break;
1090
1121
  }
1091
1122
  case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE: {
1123
+ pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1092
1124
  pm_serialize_location(parser, &((pm_interpolated_regular_expression_node_t *)node)->opening_loc, buffer);
1093
1125
  uint32_t parts_size = pm_sizet_to_u32(((pm_interpolated_regular_expression_node_t *)node)->parts.size);
1094
- pm_buffer_append_varint(buffer, parts_size);
1126
+ pm_buffer_append_varuint(buffer, parts_size);
1095
1127
  for (uint32_t index = 0; index < parts_size; index++) {
1096
1128
  pm_serialize_node(parser, (pm_node_t *) ((pm_interpolated_regular_expression_node_t *)node)->parts.nodes[index], buffer);
1097
1129
  }
1098
1130
  pm_serialize_location(parser, &((pm_interpolated_regular_expression_node_t *)node)->closing_loc, buffer);
1099
- pm_buffer_append_varint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1100
1131
  break;
1101
1132
  }
1102
1133
  case PM_INTERPOLATED_STRING_NODE: {
@@ -1107,7 +1138,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1107
1138
  pm_serialize_location(parser, &((pm_interpolated_string_node_t *)node)->opening_loc, buffer);
1108
1139
  }
1109
1140
  uint32_t parts_size = pm_sizet_to_u32(((pm_interpolated_string_node_t *)node)->parts.size);
1110
- pm_buffer_append_varint(buffer, parts_size);
1141
+ pm_buffer_append_varuint(buffer, parts_size);
1111
1142
  for (uint32_t index = 0; index < parts_size; index++) {
1112
1143
  pm_serialize_node(parser, (pm_node_t *) ((pm_interpolated_string_node_t *)node)->parts.nodes[index], buffer);
1113
1144
  }
@@ -1127,7 +1158,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1127
1158
  pm_serialize_location(parser, &((pm_interpolated_symbol_node_t *)node)->opening_loc, buffer);
1128
1159
  }
1129
1160
  uint32_t parts_size = pm_sizet_to_u32(((pm_interpolated_symbol_node_t *)node)->parts.size);
1130
- pm_buffer_append_varint(buffer, parts_size);
1161
+ pm_buffer_append_varuint(buffer, parts_size);
1131
1162
  for (uint32_t index = 0; index < parts_size; index++) {
1132
1163
  pm_serialize_node(parser, (pm_node_t *) ((pm_interpolated_symbol_node_t *)node)->parts.nodes[index], buffer);
1133
1164
  }
@@ -1142,7 +1173,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1142
1173
  case PM_INTERPOLATED_X_STRING_NODE: {
1143
1174
  pm_serialize_location(parser, &((pm_interpolated_x_string_node_t *)node)->opening_loc, buffer);
1144
1175
  uint32_t parts_size = pm_sizet_to_u32(((pm_interpolated_x_string_node_t *)node)->parts.size);
1145
- pm_buffer_append_varint(buffer, parts_size);
1176
+ pm_buffer_append_varuint(buffer, parts_size);
1146
1177
  for (uint32_t index = 0; index < parts_size; index++) {
1147
1178
  pm_serialize_node(parser, (pm_node_t *) ((pm_interpolated_x_string_node_t *)node)->parts.nodes[index], buffer);
1148
1179
  }
@@ -1150,15 +1181,16 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1150
1181
  break;
1151
1182
  }
1152
1183
  case PM_KEYWORD_HASH_NODE: {
1184
+ pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1153
1185
  uint32_t elements_size = pm_sizet_to_u32(((pm_keyword_hash_node_t *)node)->elements.size);
1154
- pm_buffer_append_varint(buffer, elements_size);
1186
+ pm_buffer_append_varuint(buffer, elements_size);
1155
1187
  for (uint32_t index = 0; index < elements_size; index++) {
1156
1188
  pm_serialize_node(parser, (pm_node_t *) ((pm_keyword_hash_node_t *)node)->elements.nodes[index], buffer);
1157
1189
  }
1158
1190
  break;
1159
1191
  }
1160
1192
  case PM_KEYWORD_REST_PARAMETER_NODE: {
1161
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_keyword_rest_parameter_node_t *)node)->name));
1193
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_keyword_rest_parameter_node_t *)node)->name));
1162
1194
  if (((pm_keyword_rest_parameter_node_t *)node)->name_loc.start == NULL) {
1163
1195
  pm_buffer_append_byte(buffer, 0);
1164
1196
  } else {
@@ -1170,10 +1202,11 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1170
1202
  }
1171
1203
  case PM_LAMBDA_NODE: {
1172
1204
  uint32_t locals_size = pm_sizet_to_u32(((pm_lambda_node_t *)node)->locals.size);
1173
- pm_buffer_append_varint(buffer, locals_size);
1205
+ pm_buffer_append_varuint(buffer, locals_size);
1174
1206
  for (uint32_t index = 0; index < locals_size; index++) {
1175
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_lambda_node_t *)node)->locals.ids[index]));
1207
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_lambda_node_t *)node)->locals.ids[index]));
1176
1208
  }
1209
+ pm_buffer_append_varuint(buffer, ((pm_lambda_node_t *)node)->locals_body_index);
1177
1210
  pm_serialize_location(parser, &((pm_lambda_node_t *)node)->operator_loc, buffer);
1178
1211
  pm_serialize_location(parser, &((pm_lambda_node_t *)node)->opening_loc, buffer);
1179
1212
  pm_serialize_location(parser, &((pm_lambda_node_t *)node)->closing_loc, buffer);
@@ -1193,51 +1226,51 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1193
1226
  pm_serialize_location(parser, &((pm_local_variable_and_write_node_t *)node)->name_loc, buffer);
1194
1227
  pm_serialize_location(parser, &((pm_local_variable_and_write_node_t *)node)->operator_loc, buffer);
1195
1228
  pm_serialize_node(parser, (pm_node_t *)((pm_local_variable_and_write_node_t *)node)->value, buffer);
1196
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_local_variable_and_write_node_t *)node)->name));
1197
- pm_buffer_append_varint(buffer, ((pm_local_variable_and_write_node_t *)node)->depth);
1229
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_local_variable_and_write_node_t *)node)->name));
1230
+ pm_buffer_append_varuint(buffer, ((pm_local_variable_and_write_node_t *)node)->depth);
1198
1231
  break;
1199
1232
  }
1200
1233
  case PM_LOCAL_VARIABLE_OPERATOR_WRITE_NODE: {
1201
1234
  pm_serialize_location(parser, &((pm_local_variable_operator_write_node_t *)node)->name_loc, buffer);
1202
1235
  pm_serialize_location(parser, &((pm_local_variable_operator_write_node_t *)node)->operator_loc, buffer);
1203
1236
  pm_serialize_node(parser, (pm_node_t *)((pm_local_variable_operator_write_node_t *)node)->value, buffer);
1204
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_local_variable_operator_write_node_t *)node)->name));
1205
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_local_variable_operator_write_node_t *)node)->operator));
1206
- pm_buffer_append_varint(buffer, ((pm_local_variable_operator_write_node_t *)node)->depth);
1237
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_local_variable_operator_write_node_t *)node)->name));
1238
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_local_variable_operator_write_node_t *)node)->operator));
1239
+ pm_buffer_append_varuint(buffer, ((pm_local_variable_operator_write_node_t *)node)->depth);
1207
1240
  break;
1208
1241
  }
1209
1242
  case PM_LOCAL_VARIABLE_OR_WRITE_NODE: {
1210
1243
  pm_serialize_location(parser, &((pm_local_variable_or_write_node_t *)node)->name_loc, buffer);
1211
1244
  pm_serialize_location(parser, &((pm_local_variable_or_write_node_t *)node)->operator_loc, buffer);
1212
1245
  pm_serialize_node(parser, (pm_node_t *)((pm_local_variable_or_write_node_t *)node)->value, buffer);
1213
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_local_variable_or_write_node_t *)node)->name));
1214
- pm_buffer_append_varint(buffer, ((pm_local_variable_or_write_node_t *)node)->depth);
1246
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_local_variable_or_write_node_t *)node)->name));
1247
+ pm_buffer_append_varuint(buffer, ((pm_local_variable_or_write_node_t *)node)->depth);
1215
1248
  break;
1216
1249
  }
1217
1250
  case PM_LOCAL_VARIABLE_READ_NODE: {
1218
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_local_variable_read_node_t *)node)->name));
1219
- pm_buffer_append_varint(buffer, ((pm_local_variable_read_node_t *)node)->depth);
1251
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_local_variable_read_node_t *)node)->name));
1252
+ pm_buffer_append_varuint(buffer, ((pm_local_variable_read_node_t *)node)->depth);
1220
1253
  break;
1221
1254
  }
1222
1255
  case PM_LOCAL_VARIABLE_TARGET_NODE: {
1223
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_local_variable_target_node_t *)node)->name));
1224
- pm_buffer_append_varint(buffer, ((pm_local_variable_target_node_t *)node)->depth);
1256
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_local_variable_target_node_t *)node)->name));
1257
+ pm_buffer_append_varuint(buffer, ((pm_local_variable_target_node_t *)node)->depth);
1225
1258
  break;
1226
1259
  }
1227
1260
  case PM_LOCAL_VARIABLE_WRITE_NODE: {
1228
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_local_variable_write_node_t *)node)->name));
1229
- pm_buffer_append_varint(buffer, ((pm_local_variable_write_node_t *)node)->depth);
1261
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_local_variable_write_node_t *)node)->name));
1262
+ pm_buffer_append_varuint(buffer, ((pm_local_variable_write_node_t *)node)->depth);
1230
1263
  pm_serialize_location(parser, &((pm_local_variable_write_node_t *)node)->name_loc, buffer);
1231
1264
  pm_serialize_node(parser, (pm_node_t *)((pm_local_variable_write_node_t *)node)->value, buffer);
1232
1265
  pm_serialize_location(parser, &((pm_local_variable_write_node_t *)node)->operator_loc, buffer);
1233
1266
  break;
1234
1267
  }
1235
1268
  case PM_MATCH_LAST_LINE_NODE: {
1269
+ pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1236
1270
  pm_serialize_location(parser, &((pm_match_last_line_node_t *)node)->opening_loc, buffer);
1237
1271
  pm_serialize_location(parser, &((pm_match_last_line_node_t *)node)->content_loc, buffer);
1238
1272
  pm_serialize_location(parser, &((pm_match_last_line_node_t *)node)->closing_loc, buffer);
1239
1273
  pm_serialize_string(parser, &((pm_match_last_line_node_t *)node)->unescaped, buffer);
1240
- pm_buffer_append_varint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1241
1274
  break;
1242
1275
  }
1243
1276
  case PM_MATCH_PREDICATE_NODE: {
@@ -1255,7 +1288,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1255
1288
  case PM_MATCH_WRITE_NODE: {
1256
1289
  pm_serialize_node(parser, (pm_node_t *)((pm_match_write_node_t *)node)->call, buffer);
1257
1290
  uint32_t targets_size = pm_sizet_to_u32(((pm_match_write_node_t *)node)->targets.size);
1258
- pm_buffer_append_varint(buffer, targets_size);
1291
+ pm_buffer_append_varuint(buffer, targets_size);
1259
1292
  for (uint32_t index = 0; index < targets_size; index++) {
1260
1293
  pm_serialize_node(parser, (pm_node_t *) ((pm_match_write_node_t *)node)->targets.nodes[index], buffer);
1261
1294
  }
@@ -1266,9 +1299,9 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1266
1299
  }
1267
1300
  case PM_MODULE_NODE: {
1268
1301
  uint32_t locals_size = pm_sizet_to_u32(((pm_module_node_t *)node)->locals.size);
1269
- pm_buffer_append_varint(buffer, locals_size);
1302
+ pm_buffer_append_varuint(buffer, locals_size);
1270
1303
  for (uint32_t index = 0; index < locals_size; index++) {
1271
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_module_node_t *)node)->locals.ids[index]));
1304
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_module_node_t *)node)->locals.ids[index]));
1272
1305
  }
1273
1306
  pm_serialize_location(parser, &((pm_module_node_t *)node)->module_keyword_loc, buffer);
1274
1307
  pm_serialize_node(parser, (pm_node_t *)((pm_module_node_t *)node)->constant_path, buffer);
@@ -1278,12 +1311,12 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1278
1311
  pm_serialize_node(parser, (pm_node_t *)((pm_module_node_t *)node)->body, buffer);
1279
1312
  }
1280
1313
  pm_serialize_location(parser, &((pm_module_node_t *)node)->end_keyword_loc, buffer);
1281
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_module_node_t *)node)->name));
1314
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_module_node_t *)node)->name));
1282
1315
  break;
1283
1316
  }
1284
1317
  case PM_MULTI_TARGET_NODE: {
1285
1318
  uint32_t lefts_size = pm_sizet_to_u32(((pm_multi_target_node_t *)node)->lefts.size);
1286
- pm_buffer_append_varint(buffer, lefts_size);
1319
+ pm_buffer_append_varuint(buffer, lefts_size);
1287
1320
  for (uint32_t index = 0; index < lefts_size; index++) {
1288
1321
  pm_serialize_node(parser, (pm_node_t *) ((pm_multi_target_node_t *)node)->lefts.nodes[index], buffer);
1289
1322
  }
@@ -1293,7 +1326,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1293
1326
  pm_serialize_node(parser, (pm_node_t *)((pm_multi_target_node_t *)node)->rest, buffer);
1294
1327
  }
1295
1328
  uint32_t rights_size = pm_sizet_to_u32(((pm_multi_target_node_t *)node)->rights.size);
1296
- pm_buffer_append_varint(buffer, rights_size);
1329
+ pm_buffer_append_varuint(buffer, rights_size);
1297
1330
  for (uint32_t index = 0; index < rights_size; index++) {
1298
1331
  pm_serialize_node(parser, (pm_node_t *) ((pm_multi_target_node_t *)node)->rights.nodes[index], buffer);
1299
1332
  }
@@ -1313,7 +1346,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1313
1346
  }
1314
1347
  case PM_MULTI_WRITE_NODE: {
1315
1348
  uint32_t lefts_size = pm_sizet_to_u32(((pm_multi_write_node_t *)node)->lefts.size);
1316
- pm_buffer_append_varint(buffer, lefts_size);
1349
+ pm_buffer_append_varuint(buffer, lefts_size);
1317
1350
  for (uint32_t index = 0; index < lefts_size; index++) {
1318
1351
  pm_serialize_node(parser, (pm_node_t *) ((pm_multi_write_node_t *)node)->lefts.nodes[index], buffer);
1319
1352
  }
@@ -1323,7 +1356,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1323
1356
  pm_serialize_node(parser, (pm_node_t *)((pm_multi_write_node_t *)node)->rest, buffer);
1324
1357
  }
1325
1358
  uint32_t rights_size = pm_sizet_to_u32(((pm_multi_write_node_t *)node)->rights.size);
1326
- pm_buffer_append_varint(buffer, rights_size);
1359
+ pm_buffer_append_varuint(buffer, rights_size);
1327
1360
  for (uint32_t index = 0; index < rights_size; index++) {
1328
1361
  pm_serialize_node(parser, (pm_node_t *) ((pm_multi_write_node_t *)node)->rights.nodes[index], buffer);
1329
1362
  }
@@ -1360,18 +1393,22 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1360
1393
  pm_serialize_location(parser, &((pm_no_keywords_parameter_node_t *)node)->keyword_loc, buffer);
1361
1394
  break;
1362
1395
  }
1396
+ case PM_NUMBERED_PARAMETERS_NODE: {
1397
+ pm_buffer_append_byte(buffer, ((pm_numbered_parameters_node_t *)node)->maximum);
1398
+ break;
1399
+ }
1363
1400
  case PM_NUMBERED_REFERENCE_READ_NODE: {
1364
- pm_buffer_append_varint(buffer, ((pm_numbered_reference_read_node_t *)node)->number);
1401
+ pm_buffer_append_varuint(buffer, ((pm_numbered_reference_read_node_t *)node)->number);
1365
1402
  break;
1366
1403
  }
1367
1404
  case PM_OPTIONAL_KEYWORD_PARAMETER_NODE: {
1368
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_optional_keyword_parameter_node_t *)node)->name));
1405
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_optional_keyword_parameter_node_t *)node)->name));
1369
1406
  pm_serialize_location(parser, &((pm_optional_keyword_parameter_node_t *)node)->name_loc, buffer);
1370
1407
  pm_serialize_node(parser, (pm_node_t *)((pm_optional_keyword_parameter_node_t *)node)->value, buffer);
1371
1408
  break;
1372
1409
  }
1373
1410
  case PM_OPTIONAL_PARAMETER_NODE: {
1374
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_optional_parameter_node_t *)node)->name));
1411
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_optional_parameter_node_t *)node)->name));
1375
1412
  pm_serialize_location(parser, &((pm_optional_parameter_node_t *)node)->name_loc, buffer);
1376
1413
  pm_serialize_location(parser, &((pm_optional_parameter_node_t *)node)->operator_loc, buffer);
1377
1414
  pm_serialize_node(parser, (pm_node_t *)((pm_optional_parameter_node_t *)node)->value, buffer);
@@ -1385,12 +1422,12 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1385
1422
  }
1386
1423
  case PM_PARAMETERS_NODE: {
1387
1424
  uint32_t requireds_size = pm_sizet_to_u32(((pm_parameters_node_t *)node)->requireds.size);
1388
- pm_buffer_append_varint(buffer, requireds_size);
1425
+ pm_buffer_append_varuint(buffer, requireds_size);
1389
1426
  for (uint32_t index = 0; index < requireds_size; index++) {
1390
1427
  pm_serialize_node(parser, (pm_node_t *) ((pm_parameters_node_t *)node)->requireds.nodes[index], buffer);
1391
1428
  }
1392
1429
  uint32_t optionals_size = pm_sizet_to_u32(((pm_parameters_node_t *)node)->optionals.size);
1393
- pm_buffer_append_varint(buffer, optionals_size);
1430
+ pm_buffer_append_varuint(buffer, optionals_size);
1394
1431
  for (uint32_t index = 0; index < optionals_size; index++) {
1395
1432
  pm_serialize_node(parser, (pm_node_t *) ((pm_parameters_node_t *)node)->optionals.nodes[index], buffer);
1396
1433
  }
@@ -1400,12 +1437,12 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1400
1437
  pm_serialize_node(parser, (pm_node_t *)((pm_parameters_node_t *)node)->rest, buffer);
1401
1438
  }
1402
1439
  uint32_t posts_size = pm_sizet_to_u32(((pm_parameters_node_t *)node)->posts.size);
1403
- pm_buffer_append_varint(buffer, posts_size);
1440
+ pm_buffer_append_varuint(buffer, posts_size);
1404
1441
  for (uint32_t index = 0; index < posts_size; index++) {
1405
1442
  pm_serialize_node(parser, (pm_node_t *) ((pm_parameters_node_t *)node)->posts.nodes[index], buffer);
1406
1443
  }
1407
1444
  uint32_t keywords_size = pm_sizet_to_u32(((pm_parameters_node_t *)node)->keywords.size);
1408
- pm_buffer_append_varint(buffer, keywords_size);
1445
+ pm_buffer_append_varuint(buffer, keywords_size);
1409
1446
  for (uint32_t index = 0; index < keywords_size; index++) {
1410
1447
  pm_serialize_node(parser, (pm_node_t *) ((pm_parameters_node_t *)node)->keywords.nodes[index], buffer);
1411
1448
  }
@@ -1467,14 +1504,15 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1467
1504
  }
1468
1505
  case PM_PROGRAM_NODE: {
1469
1506
  uint32_t locals_size = pm_sizet_to_u32(((pm_program_node_t *)node)->locals.size);
1470
- pm_buffer_append_varint(buffer, locals_size);
1507
+ pm_buffer_append_varuint(buffer, locals_size);
1471
1508
  for (uint32_t index = 0; index < locals_size; index++) {
1472
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_program_node_t *)node)->locals.ids[index]));
1509
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_program_node_t *)node)->locals.ids[index]));
1473
1510
  }
1474
1511
  pm_serialize_node(parser, (pm_node_t *)((pm_program_node_t *)node)->statements, buffer);
1475
1512
  break;
1476
1513
  }
1477
1514
  case PM_RANGE_NODE: {
1515
+ pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1478
1516
  if (((pm_range_node_t *)node)->left == NULL) {
1479
1517
  pm_buffer_append_byte(buffer, 0);
1480
1518
  } else {
@@ -1486,7 +1524,6 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1486
1524
  pm_serialize_node(parser, (pm_node_t *)((pm_range_node_t *)node)->right, buffer);
1487
1525
  }
1488
1526
  pm_serialize_location(parser, &((pm_range_node_t *)node)->operator_loc, buffer);
1489
- pm_buffer_append_varint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1490
1527
  break;
1491
1528
  }
1492
1529
  case PM_RATIONAL_NODE: {
@@ -1497,20 +1534,20 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1497
1534
  break;
1498
1535
  }
1499
1536
  case PM_REGULAR_EXPRESSION_NODE: {
1537
+ pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1500
1538
  pm_serialize_location(parser, &((pm_regular_expression_node_t *)node)->opening_loc, buffer);
1501
1539
  pm_serialize_location(parser, &((pm_regular_expression_node_t *)node)->content_loc, buffer);
1502
1540
  pm_serialize_location(parser, &((pm_regular_expression_node_t *)node)->closing_loc, buffer);
1503
1541
  pm_serialize_string(parser, &((pm_regular_expression_node_t *)node)->unescaped, buffer);
1504
- pm_buffer_append_varint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1505
1542
  break;
1506
1543
  }
1507
1544
  case PM_REQUIRED_KEYWORD_PARAMETER_NODE: {
1508
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_required_keyword_parameter_node_t *)node)->name));
1545
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_required_keyword_parameter_node_t *)node)->name));
1509
1546
  pm_serialize_location(parser, &((pm_required_keyword_parameter_node_t *)node)->name_loc, buffer);
1510
1547
  break;
1511
1548
  }
1512
1549
  case PM_REQUIRED_PARAMETER_NODE: {
1513
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_required_parameter_node_t *)node)->name));
1550
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_required_parameter_node_t *)node)->name));
1514
1551
  break;
1515
1552
  }
1516
1553
  case PM_RESCUE_MODIFIER_NODE: {
@@ -1522,7 +1559,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1522
1559
  case PM_RESCUE_NODE: {
1523
1560
  pm_serialize_location(parser, &((pm_rescue_node_t *)node)->keyword_loc, buffer);
1524
1561
  uint32_t exceptions_size = pm_sizet_to_u32(((pm_rescue_node_t *)node)->exceptions.size);
1525
- pm_buffer_append_varint(buffer, exceptions_size);
1562
+ pm_buffer_append_varuint(buffer, exceptions_size);
1526
1563
  for (uint32_t index = 0; index < exceptions_size; index++) {
1527
1564
  pm_serialize_node(parser, (pm_node_t *) ((pm_rescue_node_t *)node)->exceptions.nodes[index], buffer);
1528
1565
  }
@@ -1550,7 +1587,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1550
1587
  break;
1551
1588
  }
1552
1589
  case PM_REST_PARAMETER_NODE: {
1553
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_rest_parameter_node_t *)node)->name));
1590
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_rest_parameter_node_t *)node)->name));
1554
1591
  if (((pm_rest_parameter_node_t *)node)->name_loc.start == NULL) {
1555
1592
  pm_buffer_append_byte(buffer, 0);
1556
1593
  } else {
@@ -1577,9 +1614,9 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1577
1614
  }
1578
1615
  case PM_SINGLETON_CLASS_NODE: {
1579
1616
  uint32_t locals_size = pm_sizet_to_u32(((pm_singleton_class_node_t *)node)->locals.size);
1580
- pm_buffer_append_varint(buffer, locals_size);
1617
+ pm_buffer_append_varuint(buffer, locals_size);
1581
1618
  for (uint32_t index = 0; index < locals_size; index++) {
1582
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_singleton_class_node_t *)node)->locals.ids[index]));
1619
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_singleton_class_node_t *)node)->locals.ids[index]));
1583
1620
  }
1584
1621
  pm_serialize_location(parser, &((pm_singleton_class_node_t *)node)->class_keyword_loc, buffer);
1585
1622
  pm_serialize_location(parser, &((pm_singleton_class_node_t *)node)->operator_loc, buffer);
@@ -1613,14 +1650,14 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1613
1650
  }
1614
1651
  case PM_STATEMENTS_NODE: {
1615
1652
  uint32_t body_size = pm_sizet_to_u32(((pm_statements_node_t *)node)->body.size);
1616
- pm_buffer_append_varint(buffer, body_size);
1653
+ pm_buffer_append_varuint(buffer, body_size);
1617
1654
  for (uint32_t index = 0; index < body_size; index++) {
1618
1655
  pm_serialize_node(parser, (pm_node_t *) ((pm_statements_node_t *)node)->body.nodes[index], buffer);
1619
1656
  }
1620
1657
  break;
1621
1658
  }
1622
1659
  case PM_STRING_NODE: {
1623
- pm_buffer_append_varint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1660
+ pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1624
1661
  if (((pm_string_node_t *)node)->opening_loc.start == NULL) {
1625
1662
  pm_buffer_append_byte(buffer, 0);
1626
1663
  } else {
@@ -1664,6 +1701,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1664
1701
  break;
1665
1702
  }
1666
1703
  case PM_SYMBOL_NODE: {
1704
+ pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1667
1705
  if (((pm_symbol_node_t *)node)->opening_loc.start == NULL) {
1668
1706
  pm_buffer_append_byte(buffer, 0);
1669
1707
  } else {
@@ -1690,7 +1728,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1690
1728
  }
1691
1729
  case PM_UNDEF_NODE: {
1692
1730
  uint32_t names_size = pm_sizet_to_u32(((pm_undef_node_t *)node)->names.size);
1693
- pm_buffer_append_varint(buffer, names_size);
1731
+ pm_buffer_append_varuint(buffer, names_size);
1694
1732
  for (uint32_t index = 0; index < names_size; index++) {
1695
1733
  pm_serialize_node(parser, (pm_node_t *) ((pm_undef_node_t *)node)->names.nodes[index], buffer);
1696
1734
  }
@@ -1725,6 +1763,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1725
1763
  break;
1726
1764
  }
1727
1765
  case PM_UNTIL_NODE: {
1766
+ pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1728
1767
  pm_serialize_location(parser, &((pm_until_node_t *)node)->keyword_loc, buffer);
1729
1768
  if (((pm_until_node_t *)node)->closing_loc.start == NULL) {
1730
1769
  pm_buffer_append_byte(buffer, 0);
@@ -1738,13 +1777,12 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1738
1777
  } else {
1739
1778
  pm_serialize_node(parser, (pm_node_t *)((pm_until_node_t *)node)->statements, buffer);
1740
1779
  }
1741
- pm_buffer_append_varint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1742
1780
  break;
1743
1781
  }
1744
1782
  case PM_WHEN_NODE: {
1745
1783
  pm_serialize_location(parser, &((pm_when_node_t *)node)->keyword_loc, buffer);
1746
1784
  uint32_t conditions_size = pm_sizet_to_u32(((pm_when_node_t *)node)->conditions.size);
1747
- pm_buffer_append_varint(buffer, conditions_size);
1785
+ pm_buffer_append_varuint(buffer, conditions_size);
1748
1786
  for (uint32_t index = 0; index < conditions_size; index++) {
1749
1787
  pm_serialize_node(parser, (pm_node_t *) ((pm_when_node_t *)node)->conditions.nodes[index], buffer);
1750
1788
  }
@@ -1756,6 +1794,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1756
1794
  break;
1757
1795
  }
1758
1796
  case PM_WHILE_NODE: {
1797
+ pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1759
1798
  pm_serialize_location(parser, &((pm_while_node_t *)node)->keyword_loc, buffer);
1760
1799
  if (((pm_while_node_t *)node)->closing_loc.start == NULL) {
1761
1800
  pm_buffer_append_byte(buffer, 0);
@@ -1769,10 +1808,10 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1769
1808
  } else {
1770
1809
  pm_serialize_node(parser, (pm_node_t *)((pm_while_node_t *)node)->statements, buffer);
1771
1810
  }
1772
- pm_buffer_append_varint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1773
1811
  break;
1774
1812
  }
1775
1813
  case PM_X_STRING_NODE: {
1814
+ pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1776
1815
  pm_serialize_location(parser, &((pm_x_string_node_t *)node)->opening_loc, buffer);
1777
1816
  pm_serialize_location(parser, &((pm_x_string_node_t *)node)->content_loc, buffer);
1778
1817
  pm_serialize_location(parser, &((pm_x_string_node_t *)node)->closing_loc, buffer);
@@ -1809,8 +1848,7 @@ pm_serialize_comment(pm_parser_t *parser, pm_comment_t *comment, pm_buffer_t *bu
1809
1848
  pm_buffer_append_byte(buffer, (uint8_t) comment->type);
1810
1849
 
1811
1850
  // serialize location
1812
- pm_buffer_append_varint(buffer, pm_ptrdifft_to_u32(comment->start - parser->start));
1813
- pm_buffer_append_varint(buffer, pm_ptrdifft_to_u32(comment->end - comment->start));
1851
+ pm_serialize_location(parser, &comment->location, buffer);
1814
1852
  }
1815
1853
 
1816
1854
  /**
@@ -1818,7 +1856,7 @@ pm_serialize_comment(pm_parser_t *parser, pm_comment_t *comment, pm_buffer_t *bu
1818
1856
  */
1819
1857
  void
1820
1858
  pm_serialize_comment_list(pm_parser_t *parser, pm_list_t *list, pm_buffer_t *buffer) {
1821
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(pm_list_size(list)));
1859
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(pm_list_size(list)));
1822
1860
 
1823
1861
  pm_comment_t *comment;
1824
1862
  for (comment = (pm_comment_t *) list->head; comment != NULL; comment = (pm_comment_t *) comment->node.next) {
@@ -1829,17 +1867,17 @@ pm_serialize_comment_list(pm_parser_t *parser, pm_list_t *list, pm_buffer_t *buf
1829
1867
  static void
1830
1868
  pm_serialize_magic_comment(pm_parser_t *parser, pm_magic_comment_t *magic_comment, pm_buffer_t *buffer) {
1831
1869
  // serialize key location
1832
- pm_buffer_append_varint(buffer, pm_ptrdifft_to_u32(magic_comment->key_start - parser->start));
1833
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(magic_comment->key_length));
1870
+ pm_buffer_append_varuint(buffer, pm_ptrdifft_to_u32(magic_comment->key_start - parser->start));
1871
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(magic_comment->key_length));
1834
1872
 
1835
1873
  // serialize value location
1836
- pm_buffer_append_varint(buffer, pm_ptrdifft_to_u32(magic_comment->value_start - parser->start));
1837
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(magic_comment->value_length));
1874
+ pm_buffer_append_varuint(buffer, pm_ptrdifft_to_u32(magic_comment->value_start - parser->start));
1875
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(magic_comment->value_length));
1838
1876
  }
1839
1877
 
1840
1878
  static void
1841
1879
  pm_serialize_magic_comment_list(pm_parser_t *parser, pm_list_t *list, pm_buffer_t *buffer) {
1842
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(pm_list_size(list)));
1880
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(pm_list_size(list)));
1843
1881
 
1844
1882
  pm_magic_comment_t *magic_comment;
1845
1883
  for (magic_comment = (pm_magic_comment_t *) list->head; magic_comment != NULL; magic_comment = (pm_magic_comment_t *) magic_comment->node.next) {
@@ -1847,21 +1885,30 @@ pm_serialize_magic_comment_list(pm_parser_t *parser, pm_list_t *list, pm_buffer_
1847
1885
  }
1848
1886
  }
1849
1887
 
1888
+ static void
1889
+ pm_serialize_data_loc(const pm_parser_t *parser, pm_buffer_t *buffer) {
1890
+ if (parser->data_loc.end == NULL) {
1891
+ pm_buffer_append_byte(buffer, 0);
1892
+ } else {
1893
+ pm_buffer_append_byte(buffer, 1);
1894
+ pm_serialize_location(parser, &parser->data_loc, buffer);
1895
+ }
1896
+ }
1897
+
1850
1898
  static void
1851
1899
  pm_serialize_diagnostic(pm_parser_t *parser, pm_diagnostic_t *diagnostic, pm_buffer_t *buffer) {
1852
1900
  // serialize message
1853
1901
  size_t message_length = strlen(diagnostic->message);
1854
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(message_length));
1902
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(message_length));
1855
1903
  pm_buffer_append_string(buffer, diagnostic->message, message_length);
1856
1904
 
1857
1905
  // serialize location
1858
- pm_buffer_append_varint(buffer, pm_ptrdifft_to_u32(diagnostic->start - parser->start));
1859
- pm_buffer_append_varint(buffer, pm_ptrdifft_to_u32(diagnostic->end - diagnostic->start));
1906
+ pm_serialize_location(parser, &diagnostic->location, buffer);
1860
1907
  }
1861
1908
 
1862
1909
  static void
1863
1910
  pm_serialize_diagnostic_list(pm_parser_t *parser, pm_list_t *list, pm_buffer_t *buffer) {
1864
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(pm_list_size(list)));
1911
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(pm_list_size(list)));
1865
1912
 
1866
1913
  pm_diagnostic_t *diagnostic;
1867
1914
  for (diagnostic = (pm_diagnostic_t *) list->head; diagnostic != NULL; diagnostic = (pm_diagnostic_t *) diagnostic->node.next) {
@@ -1873,22 +1920,23 @@ pm_serialize_diagnostic_list(pm_parser_t *parser, pm_list_t *list, pm_buffer_t *
1873
1920
  * Serialize the name of the encoding to the buffer.
1874
1921
  */
1875
1922
  void
1876
- pm_serialize_encoding(pm_encoding_t *encoding, pm_buffer_t *buffer) {
1923
+ pm_serialize_encoding(const pm_encoding_t *encoding, pm_buffer_t *buffer) {
1877
1924
  size_t encoding_length = strlen(encoding->name);
1878
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(encoding_length));
1925
+ pm_buffer_append_varuint(buffer, pm_sizet_to_u32(encoding_length));
1879
1926
  pm_buffer_append_string(buffer, encoding->name, encoding_length);
1880
1927
  }
1881
1928
 
1882
- #line 206 "serialize.c.erb"
1929
+ #line 216 "serialize.c.erb"
1883
1930
  /**
1884
1931
  * Serialize the encoding, metadata, nodes, and constant pool.
1885
1932
  */
1886
1933
  void
1887
1934
  pm_serialize_content(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1888
- pm_serialize_encoding(&parser->encoding, buffer);
1889
- pm_buffer_append_varint(buffer, parser->start_line);
1935
+ pm_serialize_encoding(parser->encoding, buffer);
1936
+ pm_buffer_append_varsint(buffer, parser->start_line);
1890
1937
  pm_serialize_comment_list(parser, &parser->comment_list, buffer);
1891
1938
  pm_serialize_magic_comment_list(parser, &parser->magic_comment_list, buffer);
1939
+ pm_serialize_data_loc(parser, buffer);
1892
1940
  pm_serialize_diagnostic_list(parser, &parser->error_list, buffer);
1893
1941
  pm_serialize_diagnostic_list(parser, &parser->warning_list, buffer);
1894
1942
 
@@ -1898,7 +1946,7 @@ pm_serialize_content(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer)
1898
1946
  pm_buffer_append_zeroes(buffer, 4);
1899
1947
 
1900
1948
  // Next, encode the length of the constant pool.
1901
- pm_buffer_append_varint(buffer, parser->constant_pool.size);
1949
+ pm_buffer_append_varuint(buffer, parser->constant_pool.size);
1902
1950
 
1903
1951
  // Now we're going to serialize the content of the node.
1904
1952
  pm_serialize_node(parser, node, buffer);
@@ -1953,10 +2001,10 @@ static void
1953
2001
  serialize_token(void *data, pm_parser_t *parser, pm_token_t *token) {
1954
2002
  pm_buffer_t *buffer = (pm_buffer_t *) data;
1955
2003
 
1956
- pm_buffer_append_varint(buffer, token->type);
1957
- pm_buffer_append_varint(buffer, pm_ptrdifft_to_u32(token->start - parser->start));
1958
- pm_buffer_append_varint(buffer, pm_ptrdifft_to_u32(token->end - token->start));
1959
- pm_buffer_append_varint(buffer, parser->lex_state);
2004
+ pm_buffer_append_varuint(buffer, token->type);
2005
+ pm_buffer_append_varuint(buffer, pm_ptrdifft_to_u32(token->start - parser->start));
2006
+ pm_buffer_append_varuint(buffer, pm_ptrdifft_to_u32(token->end - token->start));
2007
+ pm_buffer_append_varuint(buffer, parser->lex_state);
1960
2008
  }
1961
2009
 
1962
2010
  /**
@@ -1965,7 +2013,7 @@ serialize_token(void *data, pm_parser_t *parser, pm_token_t *token) {
1965
2013
  PRISM_EXPORTED_FUNCTION void
1966
2014
  pm_serialize_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data) {
1967
2015
  pm_options_t options = { 0 };
1968
- if (data != NULL) pm_options_read(&options, data);
2016
+ pm_options_read(&options, data);
1969
2017
 
1970
2018
  pm_parser_t parser;
1971
2019
  pm_parser_init(&parser, source, size, &options);
@@ -1981,10 +2029,11 @@ pm_serialize_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const
1981
2029
  // Append 0 to mark end of tokens.
1982
2030
  pm_buffer_append_byte(buffer, 0);
1983
2031
 
1984
- pm_serialize_encoding(&parser.encoding, buffer);
1985
- pm_buffer_append_varint(buffer, parser.start_line);
2032
+ pm_serialize_encoding(parser.encoding, buffer);
2033
+ pm_buffer_append_varsint(buffer, parser.start_line);
1986
2034
  pm_serialize_comment_list(&parser, &parser.comment_list, buffer);
1987
2035
  pm_serialize_magic_comment_list(&parser, &parser.magic_comment_list, buffer);
2036
+ pm_serialize_data_loc(&parser, buffer);
1988
2037
  pm_serialize_diagnostic_list(&parser, &parser.error_list, buffer);
1989
2038
  pm_serialize_diagnostic_list(&parser, &parser.warning_list, buffer);
1990
2039
 
@@ -2000,7 +2049,7 @@ pm_serialize_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const
2000
2049
  PRISM_EXPORTED_FUNCTION void
2001
2050
  pm_serialize_parse_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data) {
2002
2051
  pm_options_t options = { 0 };
2003
- if (data != NULL) pm_options_read(&options, data);
2052
+ pm_options_read(&options, data);
2004
2053
 
2005
2054
  pm_parser_t parser;
2006
2055
  pm_parser_init(&parser, source, size, &options);
@@ -2020,3 +2069,24 @@ pm_serialize_parse_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size,
2020
2069
  pm_parser_free(&parser);
2021
2070
  pm_options_free(&options);
2022
2071
  }
2072
+
2073
+ /**
2074
+ * Parse the source and return true if it parses without errors or warnings.
2075
+ */
2076
+ PRISM_EXPORTED_FUNCTION bool
2077
+ pm_parse_success_p(const uint8_t *source, size_t size, const char *data) {
2078
+ pm_options_t options = { 0 };
2079
+ pm_options_read(&options, data);
2080
+
2081
+ pm_parser_t parser;
2082
+ pm_parser_init(&parser, source, size, &options);
2083
+
2084
+ pm_node_t *node = pm_parse(&parser);
2085
+ pm_node_destroy(&parser, node);
2086
+
2087
+ bool result = parser.error_list.size == 0 && parser.warning_list.size == 0;
2088
+ pm_parser_free(&parser);
2089
+ pm_options_free(&options);
2090
+
2091
+ return result;
2092
+ }