yarp 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/src/serialize.c CHANGED
@@ -58,6 +58,12 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
58
58
  serialize_location(parser, &((yp_and_node_t *)node)->operator_loc, buffer);
59
59
  break;
60
60
  }
61
+ case YP_NODE_AND_WRITE_NODE: {
62
+ yp_serialize_node(parser, (yp_node_t *)((yp_and_write_node_t *)node)->target, buffer);
63
+ yp_serialize_node(parser, (yp_node_t *)((yp_and_write_node_t *)node)->value, buffer);
64
+ serialize_location(parser, &((yp_and_write_node_t *)node)->operator_loc, buffer);
65
+ break;
66
+ }
61
67
  case YP_NODE_ARGUMENTS_NODE: {
62
68
  uint32_t arguments_size = yp_sizet_to_u32(((yp_arguments_node_t *)node)->arguments.size);
63
69
  yp_buffer_append_u32(buffer, arguments_size);
@@ -203,10 +209,10 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
203
209
  } else {
204
210
  yp_serialize_node(parser, (yp_node_t *)((yp_block_node_t *)node)->parameters, buffer);
205
211
  }
206
- if (((yp_block_node_t *)node)->statements == NULL) {
212
+ if (((yp_block_node_t *)node)->body == NULL) {
207
213
  yp_buffer_append_u8(buffer, 0);
208
214
  } else {
209
- yp_serialize_node(parser, (yp_node_t *)((yp_block_node_t *)node)->statements, buffer);
215
+ yp_serialize_node(parser, (yp_node_t *)((yp_block_node_t *)node)->body, buffer);
210
216
  }
211
217
  serialize_location(parser, &((yp_block_node_t *)node)->opening_loc, buffer);
212
218
  serialize_location(parser, &((yp_block_node_t *)node)->closing_loc, buffer);
@@ -366,33 +372,14 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
366
372
  } else {
367
373
  yp_serialize_node(parser, (yp_node_t *)((yp_class_node_t *)node)->superclass, buffer);
368
374
  }
369
- if (((yp_class_node_t *)node)->statements == NULL) {
375
+ if (((yp_class_node_t *)node)->body == NULL) {
370
376
  yp_buffer_append_u8(buffer, 0);
371
377
  } else {
372
- yp_serialize_node(parser, (yp_node_t *)((yp_class_node_t *)node)->statements, buffer);
378
+ yp_serialize_node(parser, (yp_node_t *)((yp_class_node_t *)node)->body, buffer);
373
379
  }
374
380
  serialize_location(parser, &((yp_class_node_t *)node)->end_keyword_loc, buffer);
375
381
  break;
376
382
  }
377
- case YP_NODE_CLASS_VARIABLE_OPERATOR_AND_WRITE_NODE: {
378
- serialize_location(parser, &((yp_class_variable_operator_and_write_node_t *)node)->name_loc, buffer);
379
- serialize_location(parser, &((yp_class_variable_operator_and_write_node_t *)node)->operator_loc, buffer);
380
- yp_serialize_node(parser, (yp_node_t *)((yp_class_variable_operator_and_write_node_t *)node)->value, buffer);
381
- break;
382
- }
383
- case YP_NODE_CLASS_VARIABLE_OPERATOR_OR_WRITE_NODE: {
384
- serialize_location(parser, &((yp_class_variable_operator_or_write_node_t *)node)->name_loc, buffer);
385
- serialize_location(parser, &((yp_class_variable_operator_or_write_node_t *)node)->operator_loc, buffer);
386
- yp_serialize_node(parser, (yp_node_t *)((yp_class_variable_operator_or_write_node_t *)node)->value, buffer);
387
- break;
388
- }
389
- case YP_NODE_CLASS_VARIABLE_OPERATOR_WRITE_NODE: {
390
- serialize_location(parser, &((yp_class_variable_operator_write_node_t *)node)->name_loc, buffer);
391
- serialize_location(parser, &((yp_class_variable_operator_write_node_t *)node)->operator_loc, buffer);
392
- yp_serialize_node(parser, (yp_node_t *)((yp_class_variable_operator_write_node_t *)node)->value, buffer);
393
- yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_class_variable_operator_write_node_t *)node)->operator));
394
- break;
395
- }
396
383
  case YP_NODE_CLASS_VARIABLE_READ_NODE: {
397
384
  break;
398
385
  }
@@ -411,25 +398,6 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
411
398
  }
412
399
  break;
413
400
  }
414
- case YP_NODE_CONSTANT_OPERATOR_AND_WRITE_NODE: {
415
- serialize_location(parser, &((yp_constant_operator_and_write_node_t *)node)->name_loc, buffer);
416
- serialize_location(parser, &((yp_constant_operator_and_write_node_t *)node)->operator_loc, buffer);
417
- yp_serialize_node(parser, (yp_node_t *)((yp_constant_operator_and_write_node_t *)node)->value, buffer);
418
- break;
419
- }
420
- case YP_NODE_CONSTANT_OPERATOR_OR_WRITE_NODE: {
421
- serialize_location(parser, &((yp_constant_operator_or_write_node_t *)node)->name_loc, buffer);
422
- serialize_location(parser, &((yp_constant_operator_or_write_node_t *)node)->operator_loc, buffer);
423
- yp_serialize_node(parser, (yp_node_t *)((yp_constant_operator_or_write_node_t *)node)->value, buffer);
424
- break;
425
- }
426
- case YP_NODE_CONSTANT_OPERATOR_WRITE_NODE: {
427
- serialize_location(parser, &((yp_constant_operator_write_node_t *)node)->name_loc, buffer);
428
- serialize_location(parser, &((yp_constant_operator_write_node_t *)node)->operator_loc, buffer);
429
- yp_serialize_node(parser, (yp_node_t *)((yp_constant_operator_write_node_t *)node)->value, buffer);
430
- yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_constant_operator_write_node_t *)node)->operator));
431
- break;
432
- }
433
401
  case YP_NODE_CONSTANT_PATH_NODE: {
434
402
  if (((yp_constant_path_node_t *)node)->parent == NULL) {
435
403
  yp_buffer_append_u8(buffer, 0);
@@ -440,25 +408,6 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
440
408
  serialize_location(parser, &((yp_constant_path_node_t *)node)->delimiter_loc, buffer);
441
409
  break;
442
410
  }
443
- case YP_NODE_CONSTANT_PATH_OPERATOR_AND_WRITE_NODE: {
444
- yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_operator_and_write_node_t *)node)->target, buffer);
445
- serialize_location(parser, &((yp_constant_path_operator_and_write_node_t *)node)->operator_loc, buffer);
446
- yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_operator_and_write_node_t *)node)->value, buffer);
447
- break;
448
- }
449
- case YP_NODE_CONSTANT_PATH_OPERATOR_OR_WRITE_NODE: {
450
- yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_operator_or_write_node_t *)node)->target, buffer);
451
- serialize_location(parser, &((yp_constant_path_operator_or_write_node_t *)node)->operator_loc, buffer);
452
- yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_operator_or_write_node_t *)node)->value, buffer);
453
- break;
454
- }
455
- case YP_NODE_CONSTANT_PATH_OPERATOR_WRITE_NODE: {
456
- yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_operator_write_node_t *)node)->target, buffer);
457
- serialize_location(parser, &((yp_constant_path_operator_write_node_t *)node)->operator_loc, buffer);
458
- yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_operator_write_node_t *)node)->value, buffer);
459
- yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_constant_path_operator_write_node_t *)node)->operator));
460
- break;
461
- }
462
411
  case YP_NODE_CONSTANT_PATH_WRITE_NODE: {
463
412
  yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_write_node_t *)node)->target, buffer);
464
413
  if (((yp_constant_path_write_node_t *)node)->operator_loc.start == NULL) {
@@ -508,10 +457,10 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
508
457
  } else {
509
458
  yp_serialize_node(parser, (yp_node_t *)((yp_def_node_t *)node)->parameters, buffer);
510
459
  }
511
- if (((yp_def_node_t *)node)->statements == NULL) {
460
+ if (((yp_def_node_t *)node)->body == NULL) {
512
461
  yp_buffer_append_u8(buffer, 0);
513
462
  } else {
514
- yp_serialize_node(parser, (yp_node_t *)((yp_def_node_t *)node)->statements, buffer);
463
+ yp_serialize_node(parser, (yp_node_t *)((yp_def_node_t *)node)->body, buffer);
515
464
  }
516
465
  uint32_t locals_size = yp_sizet_to_u32(((yp_def_node_t *)node)->locals.size);
517
466
  yp_buffer_append_u32(buffer, locals_size);
@@ -692,25 +641,6 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
692
641
  }
693
642
  break;
694
643
  }
695
- case YP_NODE_GLOBAL_VARIABLE_OPERATOR_AND_WRITE_NODE: {
696
- serialize_location(parser, &((yp_global_variable_operator_and_write_node_t *)node)->name_loc, buffer);
697
- serialize_location(parser, &((yp_global_variable_operator_and_write_node_t *)node)->operator_loc, buffer);
698
- yp_serialize_node(parser, (yp_node_t *)((yp_global_variable_operator_and_write_node_t *)node)->value, buffer);
699
- break;
700
- }
701
- case YP_NODE_GLOBAL_VARIABLE_OPERATOR_OR_WRITE_NODE: {
702
- serialize_location(parser, &((yp_global_variable_operator_or_write_node_t *)node)->name_loc, buffer);
703
- serialize_location(parser, &((yp_global_variable_operator_or_write_node_t *)node)->operator_loc, buffer);
704
- yp_serialize_node(parser, (yp_node_t *)((yp_global_variable_operator_or_write_node_t *)node)->value, buffer);
705
- break;
706
- }
707
- case YP_NODE_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE: {
708
- serialize_location(parser, &((yp_global_variable_operator_write_node_t *)node)->name_loc, buffer);
709
- serialize_location(parser, &((yp_global_variable_operator_write_node_t *)node)->operator_loc, buffer);
710
- yp_serialize_node(parser, (yp_node_t *)((yp_global_variable_operator_write_node_t *)node)->value, buffer);
711
- yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_global_variable_operator_write_node_t *)node)->operator));
712
- break;
713
- }
714
644
  case YP_NODE_GLOBAL_VARIABLE_READ_NODE: {
715
645
  break;
716
646
  }
@@ -815,25 +745,6 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
815
745
  }
816
746
  break;
817
747
  }
818
- case YP_NODE_INSTANCE_VARIABLE_OPERATOR_AND_WRITE_NODE: {
819
- serialize_location(parser, &((yp_instance_variable_operator_and_write_node_t *)node)->name_loc, buffer);
820
- serialize_location(parser, &((yp_instance_variable_operator_and_write_node_t *)node)->operator_loc, buffer);
821
- yp_serialize_node(parser, (yp_node_t *)((yp_instance_variable_operator_and_write_node_t *)node)->value, buffer);
822
- break;
823
- }
824
- case YP_NODE_INSTANCE_VARIABLE_OPERATOR_OR_WRITE_NODE: {
825
- serialize_location(parser, &((yp_instance_variable_operator_or_write_node_t *)node)->name_loc, buffer);
826
- serialize_location(parser, &((yp_instance_variable_operator_or_write_node_t *)node)->operator_loc, buffer);
827
- yp_serialize_node(parser, (yp_node_t *)((yp_instance_variable_operator_or_write_node_t *)node)->value, buffer);
828
- break;
829
- }
830
- case YP_NODE_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE: {
831
- serialize_location(parser, &((yp_instance_variable_operator_write_node_t *)node)->name_loc, buffer);
832
- serialize_location(parser, &((yp_instance_variable_operator_write_node_t *)node)->operator_loc, buffer);
833
- yp_serialize_node(parser, (yp_node_t *)((yp_instance_variable_operator_write_node_t *)node)->value, buffer);
834
- yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_instance_variable_operator_write_node_t *)node)->operator));
835
- break;
836
- }
837
748
  case YP_NODE_INSTANCE_VARIABLE_READ_NODE: {
838
749
  break;
839
750
  }
@@ -955,35 +866,13 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
955
866
  } else {
956
867
  yp_serialize_node(parser, (yp_node_t *)((yp_lambda_node_t *)node)->parameters, buffer);
957
868
  }
958
- if (((yp_lambda_node_t *)node)->statements == NULL) {
869
+ if (((yp_lambda_node_t *)node)->body == NULL) {
959
870
  yp_buffer_append_u8(buffer, 0);
960
871
  } else {
961
- yp_serialize_node(parser, (yp_node_t *)((yp_lambda_node_t *)node)->statements, buffer);
872
+ yp_serialize_node(parser, (yp_node_t *)((yp_lambda_node_t *)node)->body, buffer);
962
873
  }
963
874
  break;
964
875
  }
965
- case YP_NODE_LOCAL_VARIABLE_OPERATOR_AND_WRITE_NODE: {
966
- serialize_location(parser, &((yp_local_variable_operator_and_write_node_t *)node)->name_loc, buffer);
967
- serialize_location(parser, &((yp_local_variable_operator_and_write_node_t *)node)->operator_loc, buffer);
968
- yp_serialize_node(parser, (yp_node_t *)((yp_local_variable_operator_and_write_node_t *)node)->value, buffer);
969
- yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_operator_and_write_node_t *)node)->constant_id));
970
- break;
971
- }
972
- case YP_NODE_LOCAL_VARIABLE_OPERATOR_OR_WRITE_NODE: {
973
- serialize_location(parser, &((yp_local_variable_operator_or_write_node_t *)node)->name_loc, buffer);
974
- serialize_location(parser, &((yp_local_variable_operator_or_write_node_t *)node)->operator_loc, buffer);
975
- yp_serialize_node(parser, (yp_node_t *)((yp_local_variable_operator_or_write_node_t *)node)->value, buffer);
976
- yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_operator_or_write_node_t *)node)->constant_id));
977
- break;
978
- }
979
- case YP_NODE_LOCAL_VARIABLE_OPERATOR_WRITE_NODE: {
980
- serialize_location(parser, &((yp_local_variable_operator_write_node_t *)node)->name_loc, buffer);
981
- serialize_location(parser, &((yp_local_variable_operator_write_node_t *)node)->operator_loc, buffer);
982
- yp_serialize_node(parser, (yp_node_t *)((yp_local_variable_operator_write_node_t *)node)->value, buffer);
983
- yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_operator_write_node_t *)node)->constant_id));
984
- yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_operator_write_node_t *)node)->operator_id));
985
- break;
986
- }
987
876
  case YP_NODE_LOCAL_VARIABLE_READ_NODE: {
988
877
  yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_read_node_t *)node)->constant_id));
989
878
  yp_buffer_append_u32(buffer, ((yp_local_variable_read_node_t *)node)->depth);
@@ -1029,10 +918,10 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1029
918
  }
1030
919
  serialize_location(parser, &((yp_module_node_t *)node)->module_keyword_loc, buffer);
1031
920
  yp_serialize_node(parser, (yp_node_t *)((yp_module_node_t *)node)->constant_path, buffer);
1032
- if (((yp_module_node_t *)node)->statements == NULL) {
921
+ if (((yp_module_node_t *)node)->body == NULL) {
1033
922
  yp_buffer_append_u8(buffer, 0);
1034
923
  } else {
1035
- yp_serialize_node(parser, (yp_node_t *)((yp_module_node_t *)node)->statements, buffer);
924
+ yp_serialize_node(parser, (yp_node_t *)((yp_module_node_t *)node)->body, buffer);
1036
925
  }
1037
926
  serialize_location(parser, &((yp_module_node_t *)node)->end_keyword_loc, buffer);
1038
927
  break;
@@ -1088,6 +977,13 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1088
977
  case YP_NODE_NUMBERED_REFERENCE_READ_NODE: {
1089
978
  break;
1090
979
  }
980
+ case YP_NODE_OPERATOR_WRITE_NODE: {
981
+ yp_serialize_node(parser, (yp_node_t *)((yp_operator_write_node_t *)node)->target, buffer);
982
+ serialize_location(parser, &((yp_operator_write_node_t *)node)->operator_loc, buffer);
983
+ yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_operator_write_node_t *)node)->operator));
984
+ yp_serialize_node(parser, (yp_node_t *)((yp_operator_write_node_t *)node)->value, buffer);
985
+ break;
986
+ }
1091
987
  case YP_NODE_OPTIONAL_PARAMETER_NODE: {
1092
988
  yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_optional_parameter_node_t *)node)->constant_id));
1093
989
  serialize_location(parser, &((yp_optional_parameter_node_t *)node)->name_loc, buffer);
@@ -1101,6 +997,12 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1101
997
  serialize_location(parser, &((yp_or_node_t *)node)->operator_loc, buffer);
1102
998
  break;
1103
999
  }
1000
+ case YP_NODE_OR_WRITE_NODE: {
1001
+ yp_serialize_node(parser, (yp_node_t *)((yp_or_write_node_t *)node)->target, buffer);
1002
+ yp_serialize_node(parser, (yp_node_t *)((yp_or_write_node_t *)node)->value, buffer);
1003
+ serialize_location(parser, &((yp_or_write_node_t *)node)->operator_loc, buffer);
1004
+ break;
1005
+ }
1104
1006
  case YP_NODE_PARAMETERS_NODE: {
1105
1007
  uint32_t requireds_size = yp_sizet_to_u32(((yp_parameters_node_t *)node)->requireds.size);
1106
1008
  yp_buffer_append_u32(buffer, requireds_size);
@@ -1140,10 +1042,10 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1140
1042
  break;
1141
1043
  }
1142
1044
  case YP_NODE_PARENTHESES_NODE: {
1143
- if (((yp_parentheses_node_t *)node)->statements == NULL) {
1045
+ if (((yp_parentheses_node_t *)node)->body == NULL) {
1144
1046
  yp_buffer_append_u8(buffer, 0);
1145
1047
  } else {
1146
- yp_serialize_node(parser, (yp_node_t *)((yp_parentheses_node_t *)node)->statements, buffer);
1048
+ yp_serialize_node(parser, (yp_node_t *)((yp_parentheses_node_t *)node)->body, buffer);
1147
1049
  }
1148
1050
  serialize_location(parser, &((yp_parentheses_node_t *)node)->opening_loc, buffer);
1149
1051
  serialize_location(parser, &((yp_parentheses_node_t *)node)->closing_loc, buffer);
@@ -1308,10 +1210,10 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1308
1210
  serialize_location(parser, &((yp_singleton_class_node_t *)node)->class_keyword_loc, buffer);
1309
1211
  serialize_location(parser, &((yp_singleton_class_node_t *)node)->operator_loc, buffer);
1310
1212
  yp_serialize_node(parser, (yp_node_t *)((yp_singleton_class_node_t *)node)->expression, buffer);
1311
- if (((yp_singleton_class_node_t *)node)->statements == NULL) {
1213
+ if (((yp_singleton_class_node_t *)node)->body == NULL) {
1312
1214
  yp_buffer_append_u8(buffer, 0);
1313
1215
  } else {
1314
- yp_serialize_node(parser, (yp_node_t *)((yp_singleton_class_node_t *)node)->statements, buffer);
1216
+ yp_serialize_node(parser, (yp_node_t *)((yp_singleton_class_node_t *)node)->body, buffer);
1315
1217
  }
1316
1218
  serialize_location(parser, &((yp_singleton_class_node_t *)node)->end_keyword_loc, buffer);
1317
1219
  break;
@@ -1526,7 +1428,7 @@ void yp_serialize_comment(yp_parser_t *parser, yp_comment_t *comment, yp_buffer_
1526
1428
  }
1527
1429
 
1528
1430
  void yp_serialize_comment_list(yp_parser_t *parser, yp_list_t list, yp_buffer_t *buffer) {
1529
- yp_buffer_append_u32(buffer, yp_list_size(&list));
1431
+ yp_buffer_append_u32(buffer, yp_sizet_to_u32(yp_list_size(&list)));
1530
1432
 
1531
1433
  yp_comment_t *comment;
1532
1434
  for (comment = (yp_comment_t *) list.head; comment != NULL; comment = (yp_comment_t *) comment->node.next) {
@@ -1546,7 +1448,7 @@ void yp_serialize_diagnostic(yp_parser_t *parser, yp_diagnostic_t *diagnostic, y
1546
1448
  }
1547
1449
 
1548
1450
  void yp_serialize_diagnostic_list(yp_parser_t *parser, yp_list_t list, yp_buffer_t *buffer) {
1549
- yp_buffer_append_u32(buffer, yp_list_size(&list));
1451
+ yp_buffer_append_u32(buffer, yp_sizet_to_u32(yp_list_size(&list)));
1550
1452
 
1551
1453
  yp_diagnostic_t *diagnostic;
1552
1454
  for (diagnostic = (yp_diagnostic_t *) list.head; diagnostic != NULL; diagnostic = (yp_diagnostic_t *) diagnostic->node.next) {
data/src/unescape.c CHANGED
@@ -180,22 +180,6 @@ unescape_char(const unsigned char value, const unsigned char flags) {
180
180
  static const char *
181
181
  unescape(char *dest, size_t *dest_length, const char *backslash, const char *end, yp_list_t *error_list, const unsigned char flags, bool write_to_str) {
182
182
  switch (backslash[1]) {
183
- // \a \b \e \f \n \r \s \t \v
184
- case '\r': {
185
- // if this is an \r\n we need to escape both
186
- if (write_to_str) {
187
- dest[(*dest_length)++] = (char) unescape_char(unescape_chars[(unsigned char) backslash[1]], flags);
188
- }
189
-
190
- if (backslash + 2 < end && backslash[2] == '\n') {
191
- if (write_to_str) {
192
- dest[(*dest_length)++] = (char) unescape_char(unescape_chars[(unsigned char) backslash[2]], flags);
193
- }
194
- return backslash + 3;
195
- }
196
-
197
- return backslash + 2;
198
- }
199
183
  case 'a':
200
184
  case 'b':
201
185
  case 'e':
@@ -398,14 +382,23 @@ unescape(char *dest, size_t *dest_length, const char *backslash, const char *end
398
382
  yp_diagnostic_list_append(error_list, backslash, backslash + 2, "Invalid meta escape sequence");
399
383
  return backslash + 3;
400
384
  }
385
+ // \n
386
+ case '\n':
387
+ return backslash + 2;
388
+ // \r
389
+ case '\r':
390
+ if (backslash + 2 < end && backslash[2] == '\n') {
391
+ return backslash + 3;
392
+ }
393
+
394
+ /* fallthrough */
401
395
  // In this case we're escaping something that doesn't need escaping.
402
- default:
403
- {
404
- if (write_to_str) {
405
- dest[(*dest_length)++] = backslash[1];
406
- }
407
- return backslash + 2;
396
+ default: {
397
+ if (write_to_str) {
398
+ dest[(*dest_length)++] = backslash[1];
408
399
  }
400
+ return backslash + 2;
401
+ }
409
402
  }
410
403
  }
411
404
 
@@ -438,26 +431,24 @@ unescape(char *dest, size_t *dest_length, const char *backslash, const char *end
438
431
  // \c? or \C-? delete, ASCII 7Fh (DEL)
439
432
  //
440
433
  YP_EXPORTED_FUNCTION void
441
- yp_unescape_manipulate_string(yp_parser_t *parser, const char *value, size_t length, yp_string_t *string, yp_unescape_type_t unescape_type, yp_list_t *error_list) {
434
+ yp_unescape_manipulate_string(yp_parser_t *parser, yp_string_t *string, yp_unescape_type_t unescape_type, yp_list_t *error_list) {
442
435
  if (unescape_type == YP_UNESCAPE_NONE) {
443
436
  // If we're not unescaping then we can reference the source directly.
444
- yp_string_shared_init(string, value, value + length);
445
437
  return;
446
438
  }
447
439
 
448
- const char *backslash = yp_memchr(value, '\\', length, parser->encoding_changed, &parser->encoding);
440
+ const char *backslash = yp_memchr(string->source, '\\', string->length, parser->encoding_changed, &parser->encoding);
449
441
 
450
442
  if (backslash == NULL) {
451
443
  // Here there are no escapes, so we can reference the source directly.
452
- yp_string_shared_init(string, value, value + length);
453
444
  return;
454
445
  }
455
446
 
456
447
  // Here we have found an escape character, so we need to handle all escapes
457
448
  // within the string.
458
- char *allocated = malloc(length);
449
+ char *allocated = malloc(string->length);
459
450
  if (allocated == NULL) {
460
- yp_diagnostic_list_append(error_list, value, value + length, "Failed to allocate memory for unescaping.");
451
+ yp_diagnostic_list_append(error_list, string->source, string->source + string->length, "Failed to allocate memory for unescaping.");
461
452
  return;
462
453
  }
463
454
 
@@ -468,13 +459,13 @@ yp_unescape_manipulate_string(yp_parser_t *parser, const char *value, size_t len
468
459
  // This is the current position in the source string that we're looking at.
469
460
  // It's going to move along behind the backslash so that we can copy each
470
461
  // segment of the string that doesn't contain an escape.
471
- const char *cursor = value;
472
- const char *end = value + length;
462
+ const char *cursor = string->source;
463
+ const char *end = string->source + string->length;
473
464
 
474
465
  // For each escape found in the source string, we will handle it and update
475
466
  // the moving cursor->backslash window.
476
467
  while (backslash != NULL && backslash + 1 < end) {
477
- assert(dest_length < length);
468
+ assert(dest_length < string->length);
478
469
 
479
470
  // This is the size of the segment of the string from the previous escape
480
471
  // or the start of the string to the current escape.
@@ -520,6 +511,10 @@ yp_unescape_manipulate_string(yp_parser_t *parser, const char *value, size_t len
520
511
  cursor = end;
521
512
  }
522
513
 
514
+ // If the string was already allocated, then we need to free that memory
515
+ // here. That's because we're about to override it with the escaped string.
516
+ yp_string_free(string);
517
+
523
518
  // We also need to update the length at the end. This is because every escape
524
519
  // reduces the length of the final string, and we don't want garbage at the
525
520
  // end.
@@ -530,13 +525,12 @@ YP_EXPORTED_FUNCTION bool
530
525
  yp_unescape_string(const char *start, size_t length, yp_unescape_type_t unescape_type, yp_string_t *result) {
531
526
  bool success;
532
527
 
533
- yp_list_t error_list;
534
- yp_list_init(&error_list);
535
-
536
528
  yp_parser_t parser;
537
529
  yp_parser_init(&parser, start, length, "");
538
530
 
539
- yp_unescape_manipulate_string(&parser, start, length, result, unescape_type, &error_list);
531
+ yp_list_t error_list = YP_LIST_EMPTY;
532
+ yp_string_shared_init(result, start, start + length);
533
+ yp_unescape_manipulate_string(&parser, result, unescape_type, &error_list);
540
534
  success = yp_list_empty_p(&error_list);
541
535
 
542
536
  yp_list_free(&error_list);
data/src/util/yp_buffer.c CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  #define YP_BUFFER_INITIAL_SIZE 1024
4
4
 
5
+ // Return the size of the yp_buffer_t struct.
6
+ size_t
7
+ yp_buffer_sizeof(void) {
8
+ return sizeof(yp_buffer_t);
9
+ }
10
+
5
11
  // Initialize a yp_buffer_t with its default values.
6
12
  bool
7
13
  yp_buffer_init(yp_buffer_t *buffer) {
@@ -12,6 +18,18 @@ yp_buffer_init(yp_buffer_t *buffer) {
12
18
  return buffer->value != NULL;
13
19
  }
14
20
 
21
+ // Return the value of the buffer.
22
+ char *
23
+ yp_buffer_value(yp_buffer_t *buffer) {
24
+ return buffer->value;
25
+ }
26
+
27
+ // Return the length of the buffer.
28
+ size_t
29
+ yp_buffer_length(yp_buffer_t *buffer) {
30
+ return buffer->length;
31
+ }
32
+
15
33
  // Append the given amount of space to the buffer.
16
34
  static inline void
17
35
  yp_buffer_append_length(yp_buffer_t *buffer, size_t length) {
data/src/util/yp_list.c CHANGED
@@ -1,28 +1,15 @@
1
1
  #include "yarp/util/yp_list.h"
2
2
 
3
- // Initializes a new list.
4
- YP_EXPORTED_FUNCTION void
5
- yp_list_init(yp_list_t *list) {
6
- *list = (yp_list_t) { .head = NULL, .tail = NULL };
7
- }
8
-
9
3
  // Returns true if the given list is empty.
10
4
  YP_EXPORTED_FUNCTION bool
11
5
  yp_list_empty_p(yp_list_t *list) {
12
6
  return list->head == NULL;
13
7
  }
14
8
 
15
- YP_EXPORTED_FUNCTION uint32_t
9
+ // Returns the size of the list.
10
+ YP_EXPORTED_FUNCTION size_t
16
11
  yp_list_size(yp_list_t *list) {
17
- yp_list_node_t *node = list->head;
18
- uint32_t length = 0;
19
-
20
- while (node != NULL) {
21
- length++;
22
- node = node->next;
23
- }
24
-
25
- return length;
12
+ return list->size;
26
13
  }
27
14
 
28
15
  // Append a node to the given list.
@@ -33,7 +20,9 @@ yp_list_append(yp_list_t *list, yp_list_node_t *node) {
33
20
  } else {
34
21
  list->tail->next = node;
35
22
  }
23
+
36
24
  list->tail = node;
25
+ list->size++;
37
26
  }
38
27
 
39
28
  // Deallocate the internal state of the given list.
@@ -47,4 +36,6 @@ yp_list_free(yp_list_t *list) {
47
36
  free(node);
48
37
  node = next;
49
38
  }
39
+
40
+ list->size = 0;
50
41
  }
@@ -1,11 +1,5 @@
1
1
  #include "yarp/util/yp_state_stack.h"
2
2
 
3
- // Initializes the state stack to an empty stack.
4
- void
5
- yp_state_stack_init(yp_state_stack_t *stack) {
6
- *stack = 0;
7
- }
8
-
9
3
  // Pushes a value onto the stack.
10
4
  void
11
5
  yp_state_stack_push(yp_state_stack_t *stack, bool value) {