yarp 0.9.0 → 0.11.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 (62) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +39 -1
  3. data/CONTRIBUTING.md +7 -0
  4. data/Makefile +5 -1
  5. data/config.yml +308 -166
  6. data/docs/configuration.md +0 -1
  7. data/docs/encoding.md +5 -5
  8. data/docs/mapping.md +91 -91
  9. data/docs/serialization.md +25 -22
  10. data/ext/yarp/api_node.c +1210 -483
  11. data/ext/yarp/extension.c +22 -8
  12. data/ext/yarp/extension.h +2 -2
  13. data/include/yarp/ast.h +692 -183
  14. data/include/yarp/defines.h +2 -1
  15. data/include/yarp/diagnostic.h +200 -3
  16. data/include/yarp/enc/yp_encoding.h +10 -10
  17. data/include/yarp/node.h +0 -4
  18. data/include/yarp/parser.h +19 -19
  19. data/include/yarp/regexp.h +1 -1
  20. data/include/yarp/unescape.h +4 -4
  21. data/include/yarp/util/yp_buffer.h +3 -0
  22. data/include/yarp/util/yp_char.h +16 -16
  23. data/include/yarp/util/yp_constant_pool.h +12 -5
  24. data/include/yarp/util/yp_newline_list.h +5 -5
  25. data/include/yarp/util/yp_string.h +4 -4
  26. data/include/yarp/util/yp_string_list.h +0 -3
  27. data/include/yarp/util/yp_strpbrk.h +1 -1
  28. data/include/yarp/version.h +2 -2
  29. data/include/yarp.h +5 -4
  30. data/lib/yarp/desugar_visitor.rb +59 -122
  31. data/lib/yarp/mutation_visitor.rb +22 -12
  32. data/lib/yarp/node.rb +3081 -501
  33. data/lib/yarp/parse_result/comments.rb +172 -0
  34. data/lib/yarp/parse_result/newlines.rb +60 -0
  35. data/lib/yarp/pattern.rb +239 -0
  36. data/lib/yarp/serialize.rb +152 -129
  37. data/lib/yarp.rb +109 -49
  38. data/src/diagnostic.c +254 -2
  39. data/src/enc/yp_big5.c +15 -42
  40. data/src/enc/yp_euc_jp.c +16 -43
  41. data/src/enc/yp_gbk.c +19 -46
  42. data/src/enc/yp_shift_jis.c +16 -43
  43. data/src/enc/yp_tables.c +36 -38
  44. data/src/enc/yp_unicode.c +20 -25
  45. data/src/enc/yp_windows_31j.c +16 -43
  46. data/src/node.c +1871 -1466
  47. data/src/prettyprint.c +463 -230
  48. data/src/regexp.c +21 -21
  49. data/src/serialize.c +352 -184
  50. data/src/unescape.c +152 -122
  51. data/src/util/yp_buffer.c +7 -2
  52. data/src/util/yp_char.c +35 -40
  53. data/src/util/yp_constant_pool.c +45 -12
  54. data/src/util/yp_memchr.c +1 -1
  55. data/src/util/yp_newline_list.c +10 -5
  56. data/src/util/yp_string.c +22 -20
  57. data/src/util/yp_string_list.c +4 -7
  58. data/src/util/yp_strncasecmp.c +3 -6
  59. data/src/util/yp_strpbrk.c +8 -8
  60. data/src/yarp.c +1288 -1021
  61. data/yarp.gemspec +4 -1
  62. metadata +6 -3
data/ext/yarp/extension.c CHANGED
@@ -83,7 +83,21 @@ dump(int argc, VALUE *argv, VALUE self) {
83
83
 
84
84
  yp_string_t input;
85
85
  input_load_string(&input, string);
86
- return dump_input(&input, check_string(filepath));
86
+
87
+ #ifdef YARP_DEBUG_MODE_BUILD
88
+ size_t length = yp_string_length(&input);
89
+ char* dup = malloc(length);
90
+ memcpy(dup, yp_string_source(&input), length);
91
+ yp_string_constant_init(&input, dup, length);
92
+ #endif
93
+
94
+ VALUE value = dump_input(&input, check_string(filepath));
95
+
96
+ #ifdef YARP_DEBUG_MODE_BUILD
97
+ free(dup);
98
+ #endif
99
+
100
+ return value;
87
101
  }
88
102
 
89
103
  // Dump the AST corresponding to the given file to a string.
@@ -246,7 +260,7 @@ parse_lex_input(yp_string_t *input, const char *filepath, bool return_nodes) {
246
260
  yp_parser_register_encoding_changed_callback(&parser, parse_lex_encoding_changed_callback);
247
261
 
248
262
  VALUE offsets = rb_ary_new();
249
- VALUE source_argv[] = { rb_str_new(yp_string_source(input), yp_string_length(input)), offsets };
263
+ VALUE source_argv[] = { rb_str_new((const char *) yp_string_source(input), yp_string_length(input)), offsets };
250
264
  VALUE source = rb_class_new_instance(2, source_argv, rb_cYARPSource);
251
265
 
252
266
  parse_lex_data_t parse_lex_data = {
@@ -333,7 +347,7 @@ parse_input(yp_string_t *input, const char *filepath) {
333
347
  yp_node_t *node = yp_parse(&parser);
334
348
  rb_encoding *encoding = rb_enc_find(parser.encoding.name);
335
349
 
336
- VALUE source = yp_source_new(&parser);
350
+ VALUE source = yp_source_new(&parser, encoding);
337
351
  VALUE result_argv[] = {
338
352
  yp_ast_new(&parser, node, encoding),
339
353
  parser_comments(&parser, source),
@@ -428,7 +442,7 @@ named_captures(VALUE self, VALUE source) {
428
442
  yp_string_list_t string_list;
429
443
  yp_string_list_init(&string_list);
430
444
 
431
- if (!yp_regexp_named_capture_group_names(RSTRING_PTR(source), RSTRING_LEN(source), &string_list, false, &yp_encoding_utf_8)) {
445
+ if (!yp_regexp_named_capture_group_names((const uint8_t *) RSTRING_PTR(source), RSTRING_LEN(source), &string_list, false, &yp_encoding_utf_8)) {
432
446
  yp_string_list_free(&string_list);
433
447
  return Qnil;
434
448
  }
@@ -436,7 +450,7 @@ named_captures(VALUE self, VALUE source) {
436
450
  VALUE names = rb_ary_new();
437
451
  for (size_t index = 0; index < string_list.length; index++) {
438
452
  const yp_string_t *string = &string_list.strings[index];
439
- rb_ary_push(names, rb_str_new(yp_string_source(string), yp_string_length(string)));
453
+ rb_ary_push(names, rb_str_new((const char *) yp_string_source(string), yp_string_length(string)));
440
454
  }
441
455
 
442
456
  yp_string_list_free(&string_list);
@@ -449,8 +463,8 @@ static VALUE
449
463
  unescape(VALUE source, yp_unescape_type_t unescape_type) {
450
464
  yp_string_t result;
451
465
 
452
- if (yp_unescape_string(RSTRING_PTR(source), RSTRING_LEN(source), unescape_type, &result)) {
453
- VALUE str = rb_str_new(yp_string_source(&result), yp_string_length(&result));
466
+ if (yp_unescape_string((const uint8_t *) RSTRING_PTR(source), RSTRING_LEN(source), unescape_type, &result)) {
467
+ VALUE str = rb_str_new((const char *) yp_string_source(&result), yp_string_length(&result));
454
468
  yp_string_free(&result);
455
469
  return str;
456
470
  } else {
@@ -484,7 +498,7 @@ static VALUE
484
498
  memsize(VALUE self, VALUE string) {
485
499
  yp_parser_t parser;
486
500
  size_t length = RSTRING_LEN(string);
487
- yp_parser_init(&parser, RSTRING_PTR(string), length, NULL);
501
+ yp_parser_init(&parser, (const uint8_t *) RSTRING_PTR(string), length, NULL);
488
502
 
489
503
  yp_node_t *node = yp_parse(&parser);
490
504
  yp_memsize_t memsize;
data/ext/yarp/extension.h CHANGED
@@ -1,13 +1,13 @@
1
1
  #ifndef YARP_EXT_NODE_H
2
2
  #define YARP_EXT_NODE_H
3
3
 
4
- #define EXPECTED_YARP_VERSION "0.9.0"
4
+ #define EXPECTED_YARP_VERSION "0.11.0"
5
5
 
6
6
  #include <ruby.h>
7
7
  #include <ruby/encoding.h>
8
8
  #include "yarp.h"
9
9
 
10
- VALUE yp_source_new(yp_parser_t *parser);
10
+ VALUE yp_source_new(yp_parser_t *parser, rb_encoding *encoding);
11
11
  VALUE yp_token_new(yp_parser_t *parser, yp_token_t *token, rb_encoding *encoding, VALUE source);
12
12
  VALUE yp_ast_new(yp_parser_t *parser, yp_node_t *node, rb_encoding *encoding);
13
13