yarp 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -1
  3. data/Makefile +5 -1
  4. data/config.yml +156 -125
  5. data/docs/encoding.md +5 -5
  6. data/docs/serialization.md +2 -2
  7. data/ext/yarp/api_node.c +142 -98
  8. data/ext/yarp/extension.c +21 -7
  9. data/ext/yarp/extension.h +1 -1
  10. data/include/yarp/ast.h +327 -18
  11. data/include/yarp/defines.h +2 -1
  12. data/include/yarp/diagnostic.h +3 -3
  13. data/include/yarp/enc/yp_encoding.h +10 -10
  14. data/include/yarp/parser.h +19 -19
  15. data/include/yarp/regexp.h +1 -1
  16. data/include/yarp/unescape.h +4 -4
  17. data/include/yarp/util/yp_buffer.h +3 -0
  18. data/include/yarp/util/yp_char.h +16 -16
  19. data/include/yarp/util/yp_constant_pool.h +2 -2
  20. data/include/yarp/util/yp_newline_list.h +5 -5
  21. data/include/yarp/util/yp_string.h +4 -4
  22. data/include/yarp/util/yp_string_list.h +0 -3
  23. data/include/yarp/util/yp_strpbrk.h +1 -1
  24. data/include/yarp/version.h +2 -2
  25. data/include/yarp.h +5 -4
  26. data/lib/yarp/desugar_visitor.rb +59 -122
  27. data/lib/yarp/node.rb +230 -240
  28. data/lib/yarp/serialize.rb +16 -16
  29. data/lib/yarp.rb +5 -5
  30. data/src/diagnostic.c +1 -1
  31. data/src/enc/yp_big5.c +15 -42
  32. data/src/enc/yp_euc_jp.c +16 -43
  33. data/src/enc/yp_gbk.c +19 -46
  34. data/src/enc/yp_shift_jis.c +16 -43
  35. data/src/enc/yp_tables.c +36 -38
  36. data/src/enc/yp_unicode.c +20 -25
  37. data/src/enc/yp_windows_31j.c +16 -43
  38. data/src/node.c +1271 -899
  39. data/src/prettyprint.c +87 -48
  40. data/src/regexp.c +21 -21
  41. data/src/serialize.c +28 -15
  42. data/src/unescape.c +151 -121
  43. data/src/util/yp_buffer.c +7 -2
  44. data/src/util/yp_char.c +34 -34
  45. data/src/util/yp_constant_pool.c +4 -4
  46. data/src/util/yp_memchr.c +1 -1
  47. data/src/util/yp_newline_list.c +5 -4
  48. data/src/util/yp_string.c +22 -20
  49. data/src/util/yp_string_list.c +0 -6
  50. data/src/util/yp_strncasecmp.c +3 -6
  51. data/src/util/yp_strpbrk.c +8 -8
  52. data/src/yarp.c +355 -216
  53. data/yarp.gemspec +1 -1
  54. metadata +2 -2
data/src/prettyprint.c CHANGED
@@ -312,7 +312,7 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
312
312
  snprintf(flags_buffer, sizeof(flags_buffer), "+%d", node->flags >> 1);
313
313
  yp_buffer_append_str(buffer, flags_buffer, strlen(flags_buffer));
314
314
  yp_buffer_append_str(buffer, ", ", 2); yp_buffer_append_str(buffer, "\"", 1);
315
- yp_buffer_append_str(buffer, yp_string_source(&((yp_call_node_t *)node)->name), yp_string_length(&((yp_call_node_t *)node)->name));
315
+ yp_buffer_append_bytes(buffer, yp_string_source(&((yp_call_node_t *)node)->name), yp_string_length(&((yp_call_node_t *)node)->name));
316
316
  yp_buffer_append_str(buffer, "\"", 1);
317
317
  yp_buffer_append_str(buffer, ")", 1);
318
318
  break;
@@ -338,9 +338,9 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
338
338
  prettyprint_node(buffer, parser, (yp_node_t *)((yp_call_operator_write_node_t *)node)->target);
339
339
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_call_operator_write_node_t *)node)->operator_loc);
340
340
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_call_operator_write_node_t *)node)->value);
341
- yp_buffer_append_str(buffer, ", ", 2); char operator_id_buffer[12];
342
- snprintf(operator_id_buffer, sizeof(operator_id_buffer), "%u", ((yp_call_operator_write_node_t *)node)->operator_id);
343
- yp_buffer_append_str(buffer, operator_id_buffer, strlen(operator_id_buffer));
341
+ yp_buffer_append_str(buffer, ", ", 2); char operator_buffer[12];
342
+ snprintf(operator_buffer, sizeof(operator_buffer), "%u", ((yp_call_operator_write_node_t *)node)->operator);
343
+ yp_buffer_append_str(buffer, operator_buffer, strlen(operator_buffer));
344
344
  yp_buffer_append_str(buffer, ")", 1);
345
345
  break;
346
346
  }
@@ -404,14 +404,17 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
404
404
  }
405
405
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_class_node_t *)node)->end_keyword_loc);
406
406
  yp_buffer_append_str(buffer, ", ", 2); yp_buffer_append_str(buffer, "\"", 1);
407
- yp_buffer_append_str(buffer, yp_string_source(&((yp_class_node_t *)node)->name), yp_string_length(&((yp_class_node_t *)node)->name));
407
+ yp_buffer_append_bytes(buffer, yp_string_source(&((yp_class_node_t *)node)->name), yp_string_length(&((yp_class_node_t *)node)->name));
408
408
  yp_buffer_append_str(buffer, "\"", 1);
409
409
  yp_buffer_append_str(buffer, ")", 1);
410
410
  break;
411
411
  }
412
412
  case YP_NODE_CLASS_VARIABLE_AND_WRITE_NODE: {
413
413
  yp_buffer_append_str(buffer, "ClassVariableAndWriteNode(", 26);
414
- prettyprint_location(buffer, parser, &((yp_class_variable_and_write_node_t *)node)->name_loc);
414
+ char name_buffer[12];
415
+ snprintf(name_buffer, sizeof(name_buffer), "%u", ((yp_class_variable_and_write_node_t *)node)->name);
416
+ yp_buffer_append_str(buffer, name_buffer, strlen(name_buffer));
417
+ yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_class_variable_and_write_node_t *)node)->name_loc);
415
418
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_class_variable_and_write_node_t *)node)->operator_loc);
416
419
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_class_variable_and_write_node_t *)node)->value);
417
420
  yp_buffer_append_str(buffer, ")", 1);
@@ -419,7 +422,10 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
419
422
  }
420
423
  case YP_NODE_CLASS_VARIABLE_OPERATOR_WRITE_NODE: {
421
424
  yp_buffer_append_str(buffer, "ClassVariableOperatorWriteNode(", 31);
422
- prettyprint_location(buffer, parser, &((yp_class_variable_operator_write_node_t *)node)->name_loc);
425
+ char name_buffer[12];
426
+ snprintf(name_buffer, sizeof(name_buffer), "%u", ((yp_class_variable_operator_write_node_t *)node)->name);
427
+ yp_buffer_append_str(buffer, name_buffer, strlen(name_buffer));
428
+ yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_class_variable_operator_write_node_t *)node)->name_loc);
423
429
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_class_variable_operator_write_node_t *)node)->operator_loc);
424
430
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_class_variable_operator_write_node_t *)node)->value);
425
431
  yp_buffer_append_str(buffer, ", ", 2); char operator_buffer[12];
@@ -430,7 +436,10 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
430
436
  }
431
437
  case YP_NODE_CLASS_VARIABLE_OR_WRITE_NODE: {
432
438
  yp_buffer_append_str(buffer, "ClassVariableOrWriteNode(", 25);
433
- prettyprint_location(buffer, parser, &((yp_class_variable_or_write_node_t *)node)->name_loc);
439
+ char name_buffer[12];
440
+ snprintf(name_buffer, sizeof(name_buffer), "%u", ((yp_class_variable_or_write_node_t *)node)->name);
441
+ yp_buffer_append_str(buffer, name_buffer, strlen(name_buffer));
442
+ yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_class_variable_or_write_node_t *)node)->name_loc);
434
443
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_class_variable_or_write_node_t *)node)->operator_loc);
435
444
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_class_variable_or_write_node_t *)node)->value);
436
445
  yp_buffer_append_str(buffer, ")", 1);
@@ -438,17 +447,26 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
438
447
  }
439
448
  case YP_NODE_CLASS_VARIABLE_READ_NODE: {
440
449
  yp_buffer_append_str(buffer, "ClassVariableReadNode(", 22);
450
+ char name_buffer[12];
451
+ snprintf(name_buffer, sizeof(name_buffer), "%u", ((yp_class_variable_read_node_t *)node)->name);
452
+ yp_buffer_append_str(buffer, name_buffer, strlen(name_buffer));
441
453
  yp_buffer_append_str(buffer, ")", 1);
442
454
  break;
443
455
  }
444
456
  case YP_NODE_CLASS_VARIABLE_TARGET_NODE: {
445
457
  yp_buffer_append_str(buffer, "ClassVariableTargetNode(", 24);
458
+ char name_buffer[12];
459
+ snprintf(name_buffer, sizeof(name_buffer), "%u", ((yp_class_variable_target_node_t *)node)->name);
460
+ yp_buffer_append_str(buffer, name_buffer, strlen(name_buffer));
446
461
  yp_buffer_append_str(buffer, ")", 1);
447
462
  break;
448
463
  }
449
464
  case YP_NODE_CLASS_VARIABLE_WRITE_NODE: {
450
465
  yp_buffer_append_str(buffer, "ClassVariableWriteNode(", 23);
451
- prettyprint_location(buffer, parser, &((yp_class_variable_write_node_t *)node)->name_loc);
466
+ char name_buffer[12];
467
+ snprintf(name_buffer, sizeof(name_buffer), "%u", ((yp_class_variable_write_node_t *)node)->name);
468
+ yp_buffer_append_str(buffer, name_buffer, strlen(name_buffer));
469
+ yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_class_variable_write_node_t *)node)->name_loc);
452
470
  yp_buffer_append_str(buffer, ", ", 2); if (((yp_class_variable_write_node_t *)node)->value == NULL) {
453
471
  yp_buffer_append_str(buffer, "nil", 3);
454
472
  } else {
@@ -822,8 +840,8 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
822
840
  case YP_NODE_GLOBAL_VARIABLE_WRITE_NODE: {
823
841
  yp_buffer_append_str(buffer, "GlobalVariableWriteNode(", 24);
824
842
  prettyprint_location(buffer, parser, &((yp_global_variable_write_node_t *)node)->name_loc);
825
- yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_global_variable_write_node_t *)node)->operator_loc);
826
843
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_global_variable_write_node_t *)node)->value);
844
+ yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_global_variable_write_node_t *)node)->operator_loc);
827
845
  yp_buffer_append_str(buffer, ")", 1);
828
846
  break;
829
847
  }
@@ -922,7 +940,10 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
922
940
  }
923
941
  case YP_NODE_INSTANCE_VARIABLE_AND_WRITE_NODE: {
924
942
  yp_buffer_append_str(buffer, "InstanceVariableAndWriteNode(", 29);
925
- prettyprint_location(buffer, parser, &((yp_instance_variable_and_write_node_t *)node)->name_loc);
943
+ char name_buffer[12];
944
+ snprintf(name_buffer, sizeof(name_buffer), "%u", ((yp_instance_variable_and_write_node_t *)node)->name);
945
+ yp_buffer_append_str(buffer, name_buffer, strlen(name_buffer));
946
+ yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_instance_variable_and_write_node_t *)node)->name_loc);
926
947
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_instance_variable_and_write_node_t *)node)->operator_loc);
927
948
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_instance_variable_and_write_node_t *)node)->value);
928
949
  yp_buffer_append_str(buffer, ")", 1);
@@ -930,7 +951,10 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
930
951
  }
931
952
  case YP_NODE_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE: {
932
953
  yp_buffer_append_str(buffer, "InstanceVariableOperatorWriteNode(", 34);
933
- prettyprint_location(buffer, parser, &((yp_instance_variable_operator_write_node_t *)node)->name_loc);
954
+ char name_buffer[12];
955
+ snprintf(name_buffer, sizeof(name_buffer), "%u", ((yp_instance_variable_operator_write_node_t *)node)->name);
956
+ yp_buffer_append_str(buffer, name_buffer, strlen(name_buffer));
957
+ yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_instance_variable_operator_write_node_t *)node)->name_loc);
934
958
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_instance_variable_operator_write_node_t *)node)->operator_loc);
935
959
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_instance_variable_operator_write_node_t *)node)->value);
936
960
  yp_buffer_append_str(buffer, ", ", 2); char operator_buffer[12];
@@ -941,7 +965,10 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
941
965
  }
942
966
  case YP_NODE_INSTANCE_VARIABLE_OR_WRITE_NODE: {
943
967
  yp_buffer_append_str(buffer, "InstanceVariableOrWriteNode(", 28);
944
- prettyprint_location(buffer, parser, &((yp_instance_variable_or_write_node_t *)node)->name_loc);
968
+ char name_buffer[12];
969
+ snprintf(name_buffer, sizeof(name_buffer), "%u", ((yp_instance_variable_or_write_node_t *)node)->name);
970
+ yp_buffer_append_str(buffer, name_buffer, strlen(name_buffer));
971
+ yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_instance_variable_or_write_node_t *)node)->name_loc);
945
972
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_instance_variable_or_write_node_t *)node)->operator_loc);
946
973
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_instance_variable_or_write_node_t *)node)->value);
947
974
  yp_buffer_append_str(buffer, ")", 1);
@@ -949,17 +976,26 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
949
976
  }
950
977
  case YP_NODE_INSTANCE_VARIABLE_READ_NODE: {
951
978
  yp_buffer_append_str(buffer, "InstanceVariableReadNode(", 25);
979
+ char name_buffer[12];
980
+ snprintf(name_buffer, sizeof(name_buffer), "%u", ((yp_instance_variable_read_node_t *)node)->name);
981
+ yp_buffer_append_str(buffer, name_buffer, strlen(name_buffer));
952
982
  yp_buffer_append_str(buffer, ")", 1);
953
983
  break;
954
984
  }
955
985
  case YP_NODE_INSTANCE_VARIABLE_TARGET_NODE: {
956
986
  yp_buffer_append_str(buffer, "InstanceVariableTargetNode(", 27);
987
+ char name_buffer[12];
988
+ snprintf(name_buffer, sizeof(name_buffer), "%u", ((yp_instance_variable_target_node_t *)node)->name);
989
+ yp_buffer_append_str(buffer, name_buffer, strlen(name_buffer));
957
990
  yp_buffer_append_str(buffer, ")", 1);
958
991
  break;
959
992
  }
960
993
  case YP_NODE_INSTANCE_VARIABLE_WRITE_NODE: {
961
994
  yp_buffer_append_str(buffer, "InstanceVariableWriteNode(", 26);
962
- prettyprint_location(buffer, parser, &((yp_instance_variable_write_node_t *)node)->name_loc);
995
+ char name_buffer[12];
996
+ snprintf(name_buffer, sizeof(name_buffer), "%u", ((yp_instance_variable_write_node_t *)node)->name);
997
+ yp_buffer_append_str(buffer, name_buffer, strlen(name_buffer));
998
+ yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_instance_variable_write_node_t *)node)->name_loc);
963
999
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_instance_variable_write_node_t *)node)->value);
964
1000
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_instance_variable_write_node_t *)node)->operator_loc);
965
1001
  yp_buffer_append_str(buffer, ")", 1);
@@ -1105,9 +1141,9 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
1105
1141
  prettyprint_location(buffer, parser, &((yp_local_variable_and_write_node_t *)node)->name_loc);
1106
1142
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_local_variable_and_write_node_t *)node)->operator_loc);
1107
1143
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_local_variable_and_write_node_t *)node)->value);
1108
- yp_buffer_append_str(buffer, ", ", 2); char constant_id_buffer[12];
1109
- snprintf(constant_id_buffer, sizeof(constant_id_buffer), "%u", ((yp_local_variable_and_write_node_t *)node)->constant_id);
1110
- yp_buffer_append_str(buffer, constant_id_buffer, strlen(constant_id_buffer));
1144
+ yp_buffer_append_str(buffer, ", ", 2); char name_buffer[12];
1145
+ snprintf(name_buffer, sizeof(name_buffer), "%u", ((yp_local_variable_and_write_node_t *)node)->name);
1146
+ yp_buffer_append_str(buffer, name_buffer, strlen(name_buffer));
1111
1147
  yp_buffer_append_str(buffer, ", ", 2); char depth_buffer[12];
1112
1148
  snprintf(depth_buffer, sizeof(depth_buffer), "+%d", ((yp_local_variable_and_write_node_t *)node)->depth);
1113
1149
  yp_buffer_append_str(buffer, depth_buffer, strlen(depth_buffer));
@@ -1119,12 +1155,12 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
1119
1155
  prettyprint_location(buffer, parser, &((yp_local_variable_operator_write_node_t *)node)->name_loc);
1120
1156
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_local_variable_operator_write_node_t *)node)->operator_loc);
1121
1157
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_local_variable_operator_write_node_t *)node)->value);
1122
- yp_buffer_append_str(buffer, ", ", 2); char constant_id_buffer[12];
1123
- snprintf(constant_id_buffer, sizeof(constant_id_buffer), "%u", ((yp_local_variable_operator_write_node_t *)node)->constant_id);
1124
- yp_buffer_append_str(buffer, constant_id_buffer, strlen(constant_id_buffer));
1125
- yp_buffer_append_str(buffer, ", ", 2); char operator_id_buffer[12];
1126
- snprintf(operator_id_buffer, sizeof(operator_id_buffer), "%u", ((yp_local_variable_operator_write_node_t *)node)->operator_id);
1127
- yp_buffer_append_str(buffer, operator_id_buffer, strlen(operator_id_buffer));
1158
+ yp_buffer_append_str(buffer, ", ", 2); char name_buffer[12];
1159
+ snprintf(name_buffer, sizeof(name_buffer), "%u", ((yp_local_variable_operator_write_node_t *)node)->name);
1160
+ yp_buffer_append_str(buffer, name_buffer, strlen(name_buffer));
1161
+ yp_buffer_append_str(buffer, ", ", 2); char operator_buffer[12];
1162
+ snprintf(operator_buffer, sizeof(operator_buffer), "%u", ((yp_local_variable_operator_write_node_t *)node)->operator);
1163
+ yp_buffer_append_str(buffer, operator_buffer, strlen(operator_buffer));
1128
1164
  yp_buffer_append_str(buffer, ", ", 2); char depth_buffer[12];
1129
1165
  snprintf(depth_buffer, sizeof(depth_buffer), "+%d", ((yp_local_variable_operator_write_node_t *)node)->depth);
1130
1166
  yp_buffer_append_str(buffer, depth_buffer, strlen(depth_buffer));
@@ -1136,9 +1172,9 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
1136
1172
  prettyprint_location(buffer, parser, &((yp_local_variable_or_write_node_t *)node)->name_loc);
1137
1173
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_local_variable_or_write_node_t *)node)->operator_loc);
1138
1174
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_local_variable_or_write_node_t *)node)->value);
1139
- yp_buffer_append_str(buffer, ", ", 2); char constant_id_buffer[12];
1140
- snprintf(constant_id_buffer, sizeof(constant_id_buffer), "%u", ((yp_local_variable_or_write_node_t *)node)->constant_id);
1141
- yp_buffer_append_str(buffer, constant_id_buffer, strlen(constant_id_buffer));
1175
+ yp_buffer_append_str(buffer, ", ", 2); char name_buffer[12];
1176
+ snprintf(name_buffer, sizeof(name_buffer), "%u", ((yp_local_variable_or_write_node_t *)node)->name);
1177
+ yp_buffer_append_str(buffer, name_buffer, strlen(name_buffer));
1142
1178
  yp_buffer_append_str(buffer, ", ", 2); char depth_buffer[12];
1143
1179
  snprintf(depth_buffer, sizeof(depth_buffer), "+%d", ((yp_local_variable_or_write_node_t *)node)->depth);
1144
1180
  yp_buffer_append_str(buffer, depth_buffer, strlen(depth_buffer));
@@ -1147,9 +1183,9 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
1147
1183
  }
1148
1184
  case YP_NODE_LOCAL_VARIABLE_READ_NODE: {
1149
1185
  yp_buffer_append_str(buffer, "LocalVariableReadNode(", 22);
1150
- char constant_id_buffer[12];
1151
- snprintf(constant_id_buffer, sizeof(constant_id_buffer), "%u", ((yp_local_variable_read_node_t *)node)->constant_id);
1152
- yp_buffer_append_str(buffer, constant_id_buffer, strlen(constant_id_buffer));
1186
+ char name_buffer[12];
1187
+ snprintf(name_buffer, sizeof(name_buffer), "%u", ((yp_local_variable_read_node_t *)node)->name);
1188
+ yp_buffer_append_str(buffer, name_buffer, strlen(name_buffer));
1153
1189
  yp_buffer_append_str(buffer, ", ", 2); char depth_buffer[12];
1154
1190
  snprintf(depth_buffer, sizeof(depth_buffer), "+%d", ((yp_local_variable_read_node_t *)node)->depth);
1155
1191
  yp_buffer_append_str(buffer, depth_buffer, strlen(depth_buffer));
@@ -1158,9 +1194,9 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
1158
1194
  }
1159
1195
  case YP_NODE_LOCAL_VARIABLE_TARGET_NODE: {
1160
1196
  yp_buffer_append_str(buffer, "LocalVariableTargetNode(", 24);
1161
- char constant_id_buffer[12];
1162
- snprintf(constant_id_buffer, sizeof(constant_id_buffer), "%u", ((yp_local_variable_target_node_t *)node)->constant_id);
1163
- yp_buffer_append_str(buffer, constant_id_buffer, strlen(constant_id_buffer));
1197
+ char name_buffer[12];
1198
+ snprintf(name_buffer, sizeof(name_buffer), "%u", ((yp_local_variable_target_node_t *)node)->name);
1199
+ yp_buffer_append_str(buffer, name_buffer, strlen(name_buffer));
1164
1200
  yp_buffer_append_str(buffer, ", ", 2); char depth_buffer[12];
1165
1201
  snprintf(depth_buffer, sizeof(depth_buffer), "+%d", ((yp_local_variable_target_node_t *)node)->depth);
1166
1202
  yp_buffer_append_str(buffer, depth_buffer, strlen(depth_buffer));
@@ -1169,14 +1205,14 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
1169
1205
  }
1170
1206
  case YP_NODE_LOCAL_VARIABLE_WRITE_NODE: {
1171
1207
  yp_buffer_append_str(buffer, "LocalVariableWriteNode(", 23);
1172
- char constant_id_buffer[12];
1173
- snprintf(constant_id_buffer, sizeof(constant_id_buffer), "%u", ((yp_local_variable_write_node_t *)node)->constant_id);
1174
- yp_buffer_append_str(buffer, constant_id_buffer, strlen(constant_id_buffer));
1208
+ char name_buffer[12];
1209
+ snprintf(name_buffer, sizeof(name_buffer), "%u", ((yp_local_variable_write_node_t *)node)->name);
1210
+ yp_buffer_append_str(buffer, name_buffer, strlen(name_buffer));
1175
1211
  yp_buffer_append_str(buffer, ", ", 2); char depth_buffer[12];
1176
1212
  snprintf(depth_buffer, sizeof(depth_buffer), "+%d", ((yp_local_variable_write_node_t *)node)->depth);
1177
1213
  yp_buffer_append_str(buffer, depth_buffer, strlen(depth_buffer));
1178
- yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_local_variable_write_node_t *)node)->value);
1179
1214
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_local_variable_write_node_t *)node)->name_loc);
1215
+ yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_local_variable_write_node_t *)node)->value);
1180
1216
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_local_variable_write_node_t *)node)->operator_loc);
1181
1217
  yp_buffer_append_str(buffer, ")", 1);
1182
1218
  break;
@@ -1221,7 +1257,7 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
1221
1257
  }
1222
1258
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_module_node_t *)node)->end_keyword_loc);
1223
1259
  yp_buffer_append_str(buffer, ", ", 2); yp_buffer_append_str(buffer, "\"", 1);
1224
- yp_buffer_append_str(buffer, yp_string_source(&((yp_module_node_t *)node)->name), yp_string_length(&((yp_module_node_t *)node)->name));
1260
+ yp_buffer_append_bytes(buffer, yp_string_source(&((yp_module_node_t *)node)->name), yp_string_length(&((yp_module_node_t *)node)->name));
1225
1261
  yp_buffer_append_str(buffer, "\"", 1);
1226
1262
  yp_buffer_append_str(buffer, ")", 1);
1227
1263
  break;
@@ -1282,14 +1318,17 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
1282
1318
  }
1283
1319
  case YP_NODE_NUMBERED_REFERENCE_READ_NODE: {
1284
1320
  yp_buffer_append_str(buffer, "NumberedReferenceReadNode(", 26);
1321
+ char number_buffer[12];
1322
+ snprintf(number_buffer, sizeof(number_buffer), "+%d", ((yp_numbered_reference_read_node_t *)node)->number);
1323
+ yp_buffer_append_str(buffer, number_buffer, strlen(number_buffer));
1285
1324
  yp_buffer_append_str(buffer, ")", 1);
1286
1325
  break;
1287
1326
  }
1288
1327
  case YP_NODE_OPTIONAL_PARAMETER_NODE: {
1289
1328
  yp_buffer_append_str(buffer, "OptionalParameterNode(", 22);
1290
- char constant_id_buffer[12];
1291
- snprintf(constant_id_buffer, sizeof(constant_id_buffer), "%u", ((yp_optional_parameter_node_t *)node)->constant_id);
1292
- yp_buffer_append_str(buffer, constant_id_buffer, strlen(constant_id_buffer));
1329
+ char name_buffer[12];
1330
+ snprintf(name_buffer, sizeof(name_buffer), "%u", ((yp_optional_parameter_node_t *)node)->name);
1331
+ yp_buffer_append_str(buffer, name_buffer, strlen(name_buffer));
1293
1332
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_optional_parameter_node_t *)node)->name_loc);
1294
1333
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_optional_parameter_node_t *)node)->operator_loc);
1295
1334
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_optional_parameter_node_t *)node)->value);
@@ -1452,7 +1491,7 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
1452
1491
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_regular_expression_node_t *)node)->content_loc);
1453
1492
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_regular_expression_node_t *)node)->closing_loc);
1454
1493
  yp_buffer_append_str(buffer, ", ", 2); yp_buffer_append_str(buffer, "\"", 1);
1455
- yp_buffer_append_str(buffer, yp_string_source(&((yp_regular_expression_node_t *)node)->unescaped), yp_string_length(&((yp_regular_expression_node_t *)node)->unescaped));
1494
+ yp_buffer_append_bytes(buffer, yp_string_source(&((yp_regular_expression_node_t *)node)->unescaped), yp_string_length(&((yp_regular_expression_node_t *)node)->unescaped));
1456
1495
  yp_buffer_append_str(buffer, "\"", 1);
1457
1496
  yp_buffer_append_str(buffer, ", ", 2); char flags_buffer[12];
1458
1497
  snprintf(flags_buffer, sizeof(flags_buffer), "+%d", node->flags >> 1);
@@ -1475,9 +1514,9 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
1475
1514
  }
1476
1515
  case YP_NODE_REQUIRED_PARAMETER_NODE: {
1477
1516
  yp_buffer_append_str(buffer, "RequiredParameterNode(", 22);
1478
- char constant_id_buffer[12];
1479
- snprintf(constant_id_buffer, sizeof(constant_id_buffer), "%u", ((yp_required_parameter_node_t *)node)->constant_id);
1480
- yp_buffer_append_str(buffer, constant_id_buffer, strlen(constant_id_buffer));
1517
+ char name_buffer[12];
1518
+ snprintf(name_buffer, sizeof(name_buffer), "%u", ((yp_required_parameter_node_t *)node)->name);
1519
+ yp_buffer_append_str(buffer, name_buffer, strlen(name_buffer));
1481
1520
  yp_buffer_append_str(buffer, ")", 1);
1482
1521
  break;
1483
1522
  }
@@ -1583,7 +1622,7 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
1583
1622
  case YP_NODE_SOURCE_FILE_NODE: {
1584
1623
  yp_buffer_append_str(buffer, "SourceFileNode(", 15);
1585
1624
  yp_buffer_append_str(buffer, "\"", 1);
1586
- yp_buffer_append_str(buffer, yp_string_source(&((yp_source_file_node_t *)node)->filepath), yp_string_length(&((yp_source_file_node_t *)node)->filepath));
1625
+ yp_buffer_append_bytes(buffer, yp_string_source(&((yp_source_file_node_t *)node)->filepath), yp_string_length(&((yp_source_file_node_t *)node)->filepath));
1587
1626
  yp_buffer_append_str(buffer, "\"", 1);
1588
1627
  yp_buffer_append_str(buffer, ")", 1);
1589
1628
  break;
@@ -1636,7 +1675,7 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
1636
1675
  prettyprint_location(buffer, parser, &((yp_string_node_t *)node)->closing_loc);
1637
1676
  }
1638
1677
  yp_buffer_append_str(buffer, ", ", 2); yp_buffer_append_str(buffer, "\"", 1);
1639
- yp_buffer_append_str(buffer, yp_string_source(&((yp_string_node_t *)node)->unescaped), yp_string_length(&((yp_string_node_t *)node)->unescaped));
1678
+ yp_buffer_append_bytes(buffer, yp_string_source(&((yp_string_node_t *)node)->unescaped), yp_string_length(&((yp_string_node_t *)node)->unescaped));
1640
1679
  yp_buffer_append_str(buffer, "\"", 1);
1641
1680
  yp_buffer_append_str(buffer, ")", 1);
1642
1681
  break;
@@ -1685,7 +1724,7 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
1685
1724
  prettyprint_location(buffer, parser, &((yp_symbol_node_t *)node)->closing_loc);
1686
1725
  }
1687
1726
  yp_buffer_append_str(buffer, ", ", 2); yp_buffer_append_str(buffer, "\"", 1);
1688
- yp_buffer_append_str(buffer, yp_string_source(&((yp_symbol_node_t *)node)->unescaped), yp_string_length(&((yp_symbol_node_t *)node)->unescaped));
1727
+ yp_buffer_append_bytes(buffer, yp_string_source(&((yp_symbol_node_t *)node)->unescaped), yp_string_length(&((yp_symbol_node_t *)node)->unescaped));
1689
1728
  yp_buffer_append_str(buffer, "\"", 1);
1690
1729
  yp_buffer_append_str(buffer, ")", 1);
1691
1730
  break;
@@ -1792,7 +1831,7 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
1792
1831
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_x_string_node_t *)node)->content_loc);
1793
1832
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_x_string_node_t *)node)->closing_loc);
1794
1833
  yp_buffer_append_str(buffer, ", ", 2); yp_buffer_append_str(buffer, "\"", 1);
1795
- yp_buffer_append_str(buffer, yp_string_source(&((yp_x_string_node_t *)node)->unescaped), yp_string_length(&((yp_x_string_node_t *)node)->unescaped));
1834
+ yp_buffer_append_bytes(buffer, yp_string_source(&((yp_x_string_node_t *)node)->unescaped), yp_string_length(&((yp_x_string_node_t *)node)->unescaped));
1796
1835
  yp_buffer_append_str(buffer, "\"", 1);
1797
1836
  yp_buffer_append_str(buffer, ")", 1);
1798
1837
  break;
data/src/regexp.c CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  // This is the parser that is going to handle parsing regular expressions.
4
4
  typedef struct {
5
- const char *start;
6
- const char *cursor;
7
- const char *end;
5
+ const uint8_t *start;
6
+ const uint8_t *cursor;
7
+ const uint8_t *end;
8
8
  yp_string_list_t *named_captures;
9
9
  bool encoding_changed;
10
10
  yp_encoding_t *encoding;
@@ -12,7 +12,7 @@ typedef struct {
12
12
 
13
13
  // This initializes a new parser with the given source.
14
14
  static void
15
- yp_regexp_parser_init(yp_regexp_parser_t *parser, const char *start, const char *end, yp_string_list_t *named_captures, bool encoding_changed, yp_encoding_t *encoding) {
15
+ yp_regexp_parser_init(yp_regexp_parser_t *parser, const uint8_t *start, const uint8_t *end, yp_string_list_t *named_captures, bool encoding_changed, yp_encoding_t *encoding) {
16
16
  *parser = (yp_regexp_parser_t) {
17
17
  .start = start,
18
18
  .cursor = start,
@@ -25,7 +25,7 @@ yp_regexp_parser_init(yp_regexp_parser_t *parser, const char *start, const char
25
25
 
26
26
  // This appends a new string to the list of named captures.
27
27
  static void
28
- yp_regexp_parser_named_capture(yp_regexp_parser_t *parser, const char *start, const char *end) {
28
+ yp_regexp_parser_named_capture(yp_regexp_parser_t *parser, const uint8_t *start, const uint8_t *end) {
29
29
  yp_string_t string;
30
30
  yp_string_shared_init(&string, start, end);
31
31
  yp_string_list_append(parser->named_captures, &string);
@@ -40,7 +40,7 @@ yp_regexp_char_is_eof(yp_regexp_parser_t *parser) {
40
40
 
41
41
  // Optionally accept a char and consume it if it exists.
42
42
  static inline bool
43
- yp_regexp_char_accept(yp_regexp_parser_t *parser, char value) {
43
+ yp_regexp_char_accept(yp_regexp_parser_t *parser, uint8_t value) {
44
44
  if (!yp_regexp_char_is_eof(parser) && *parser->cursor == value) {
45
45
  parser->cursor++;
46
46
  return true;
@@ -50,7 +50,7 @@ yp_regexp_char_accept(yp_regexp_parser_t *parser, char value) {
50
50
 
51
51
  // Expect a character to be present and consume it.
52
52
  static inline bool
53
- yp_regexp_char_expect(yp_regexp_parser_t *parser, char value) {
53
+ yp_regexp_char_expect(yp_regexp_parser_t *parser, uint8_t value) {
54
54
  if (!yp_regexp_char_is_eof(parser) && *parser->cursor == value) {
55
55
  parser->cursor++;
56
56
  return true;
@@ -60,12 +60,12 @@ yp_regexp_char_expect(yp_regexp_parser_t *parser, char value) {
60
60
 
61
61
  // This advances the current token to the next instance of the given character.
62
62
  static bool
63
- yp_regexp_char_find(yp_regexp_parser_t *parser, char value) {
63
+ yp_regexp_char_find(yp_regexp_parser_t *parser, uint8_t value) {
64
64
  if (yp_regexp_char_is_eof(parser)) {
65
65
  return false;
66
66
  }
67
67
 
68
- const char *end = (const char *) yp_memchr(parser->cursor, value, (size_t) (parser->end - parser->cursor), parser->encoding_changed, parser->encoding);
68
+ const uint8_t *end = (const uint8_t *) yp_memchr(parser->cursor, value, (size_t) (parser->end - parser->cursor), parser->encoding_changed, parser->encoding);
69
69
  if (end == NULL) {
70
70
  return false;
71
71
  }
@@ -107,7 +107,7 @@ yp_regexp_char_find(yp_regexp_parser_t *parser, char value) {
107
107
  // consumed so we're in the start state.
108
108
  static bool
109
109
  yp_regexp_parse_range_quantifier(yp_regexp_parser_t *parser) {
110
- const char *savepoint = parser->cursor;
110
+ const uint8_t *savepoint = parser->cursor;
111
111
 
112
112
  enum {
113
113
  YP_REGEXP_RANGE_QUANTIFIER_STATE_START,
@@ -252,7 +252,7 @@ yp_regexp_parse_character_set(yp_regexp_parser_t *parser) {
252
252
  // A left bracket can either mean a POSIX class or a character set.
253
253
  static bool
254
254
  yp_regexp_parse_lbracket(yp_regexp_parser_t *parser) {
255
- const char *reset = parser->cursor;
255
+ const uint8_t *reset = parser->cursor;
256
256
 
257
257
  if ((parser->cursor + 2 < parser->end) && parser->cursor[0] == '[' && parser->cursor[1] == ':') {
258
258
  parser->cursor++;
@@ -287,7 +287,7 @@ typedef enum {
287
287
 
288
288
  // This is the set of options that are configurable on the regular expression.
289
289
  typedef struct {
290
- unsigned char values[YP_REGEXP_OPTION_STATE_SLOTS];
290
+ uint8_t values[YP_REGEXP_OPTION_STATE_SLOTS];
291
291
  } yp_regexp_options_t;
292
292
 
293
293
  // Initialize a new set of options to their default values.
@@ -305,9 +305,9 @@ yp_regexp_options_init(yp_regexp_options_t *options) {
305
305
  // Attempt to add the given option to the set of options. Returns true if it was
306
306
  // added, false if it was already present.
307
307
  static bool
308
- yp_regexp_options_add(yp_regexp_options_t *options, unsigned char key) {
308
+ yp_regexp_options_add(yp_regexp_options_t *options, uint8_t key) {
309
309
  if (key >= YP_REGEXP_OPTION_STATE_SLOT_MINIMUM && key <= YP_REGEXP_OPTION_STATE_SLOT_MAXIMUM) {
310
- key = (unsigned char) (key - YP_REGEXP_OPTION_STATE_SLOT_MINIMUM);
310
+ key = (uint8_t) (key - YP_REGEXP_OPTION_STATE_SLOT_MINIMUM);
311
311
 
312
312
  switch (options->values[key]) {
313
313
  case YP_REGEXP_OPTION_STATE_INVALID:
@@ -328,9 +328,9 @@ yp_regexp_options_add(yp_regexp_options_t *options, unsigned char key) {
328
328
  // Attempt to remove the given option from the set of options. Returns true if
329
329
  // it was removed, false if it was already absent.
330
330
  static bool
331
- yp_regexp_options_remove(yp_regexp_options_t *options, unsigned char key) {
331
+ yp_regexp_options_remove(yp_regexp_options_t *options, uint8_t key) {
332
332
  if (key >= YP_REGEXP_OPTION_STATE_SLOT_MINIMUM && key <= YP_REGEXP_OPTION_STATE_SLOT_MAXIMUM) {
333
- key = (unsigned char) (key - YP_REGEXP_OPTION_STATE_SLOT_MINIMUM);
333
+ key = (uint8_t) (key - YP_REGEXP_OPTION_STATE_SLOT_MINIMUM);
334
334
 
335
335
  switch (options->values[key]) {
336
336
  case YP_REGEXP_OPTION_STATE_INVALID:
@@ -431,7 +431,7 @@ yp_regexp_parse_group(yp_regexp_parser_t *parser) {
431
431
  parser->cursor++;
432
432
  break;
433
433
  default: { // named capture group
434
- const char *start = parser->cursor;
434
+ const uint8_t *start = parser->cursor;
435
435
  if (!yp_regexp_char_find(parser, '>')) {
436
436
  return false;
437
437
  }
@@ -441,7 +441,7 @@ yp_regexp_parse_group(yp_regexp_parser_t *parser) {
441
441
  }
442
442
  break;
443
443
  case '\'': { // named capture group
444
- const char *start = ++parser->cursor;
444
+ const uint8_t *start = ++parser->cursor;
445
445
  if (!yp_regexp_char_find(parser, '\'')) {
446
446
  return false;
447
447
  }
@@ -456,7 +456,7 @@ yp_regexp_parse_group(yp_regexp_parser_t *parser) {
456
456
  break;
457
457
  case 'i': case 'm': case 'x': case 'd': case 'a': case 'u': // options
458
458
  while (!yp_regexp_char_is_eof(parser) && *parser->cursor != '-' && *parser->cursor != ':' && *parser->cursor != ')') {
459
- if (!yp_regexp_options_add(&options, (unsigned char) *parser->cursor)) {
459
+ if (!yp_regexp_options_add(&options, *parser->cursor)) {
460
460
  return false;
461
461
  }
462
462
  parser->cursor++;
@@ -474,7 +474,7 @@ yp_regexp_parse_group(yp_regexp_parser_t *parser) {
474
474
  case '-':
475
475
  parser->cursor++;
476
476
  while (!yp_regexp_char_is_eof(parser) && *parser->cursor != ':' && *parser->cursor != ')') {
477
- if (!yp_regexp_options_remove(&options, (unsigned char) *parser->cursor)) {
477
+ if (!yp_regexp_options_remove(&options, *parser->cursor)) {
478
478
  return false;
479
479
  }
480
480
  parser->cursor++;
@@ -573,7 +573,7 @@ yp_regexp_parse_pattern(yp_regexp_parser_t *parser) {
573
573
  // Parse a regular expression and extract the names of all of the named capture
574
574
  // groups.
575
575
  YP_EXPORTED_FUNCTION bool
576
- yp_regexp_named_capture_group_names(const char *source, size_t size, yp_string_list_t *named_captures, bool encoding_changed, yp_encoding_t *encoding) {
576
+ yp_regexp_named_capture_group_names(const uint8_t *source, size_t size, yp_string_list_t *named_captures, bool encoding_changed, yp_encoding_t *encoding) {
577
577
  yp_regexp_parser_t parser;
578
578
  yp_regexp_parser_init(&parser, source, source + size, named_captures, encoding_changed, encoding);
579
579
  return yp_regexp_parse_pattern(&parser);