yarp 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
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/docs/encoding.md CHANGED
@@ -61,22 +61,22 @@ typedef struct {
61
61
  // Return the number of bytes that the next character takes if it is valid
62
62
  // in the encoding. Does not read more than n bytes. It is assumed that n is
63
63
  // at least 1.
64
- size_t (*char_width)(const char *c, ptrdiff_t n);
64
+ size_t (*char_width)(const uint8_t *b, ptrdiff_t n);
65
65
 
66
66
  // Return the number of bytes that the next character takes if it is valid
67
67
  // in the encoding and is alphabetical. Does not read more than n bytes. It
68
68
  // is assumed that n is at least 1.
69
- size_t (*alpha_char)(const char *c, ptrdiff_t n);
69
+ size_t (*alpha_char)(const uint8_t *b, ptrdiff_t n);
70
70
 
71
71
  // Return the number of bytes that the next character takes if it is valid
72
72
  // in the encoding and is alphanumeric. Does not read more than n bytes. It
73
73
  // is assumed that n is at least 1.
74
- size_t (*alnum_char)(const char *c, ptrdiff_t n);
74
+ size_t (*alnum_char)(const uint8_t *b, ptrdiff_t n);
75
75
 
76
76
  // Return true if the next character is valid in the encoding and is an
77
77
  // uppercase character. Does not read more than n bytes. It is assumed that
78
78
  // n is at least 1.
79
- bool (*isupper_char)(const char *c, ptrdiff_t n);
79
+ bool (*isupper_char)(const uint8_t *b, ptrdiff_t n);
80
80
 
81
81
  // The name of the encoding. This should correspond to a value that can be
82
82
  // passed to Encoding.find in Ruby.
@@ -90,7 +90,7 @@ typedef struct {
90
90
  // the ability here to call out to a user-defined function to get an encoding
91
91
  // struct. If the function returns something that isn't NULL, we set that to
92
92
  // our encoding and use it to parse identifiers.
93
- typedef yp_encoding_t *(*yp_encoding_decode_callback_t)(yp_parser_t *parser, const char *name, size_t width);
93
+ typedef yp_encoding_t *(*yp_encoding_decode_callback_t)(yp_parser_t *parser, const uint8_t *name, size_t width);
94
94
 
95
95
  // Register a callback that will be called when YARP encounters a magic comment
96
96
  // with an encoding referenced that it doesn't understand. The callback should
@@ -130,14 +130,14 @@ void yp_buffer_free(yp_buffer_t *);
130
130
 
131
131
  // Parse and serialize the AST represented by the given source to the given
132
132
  // buffer.
133
- void yp_parse_serialize(const char *, size_t, yp_buffer_t *, const char *);
133
+ void yp_parse_serialize(const uint8_t *source, size_t length, yp_buffer_t *buffer, const char *metadata);
134
134
  ```
135
135
 
136
136
  Typically you would use a stack-allocated `yp_buffer_t` and call `yp_parse_serialize`, as in:
137
137
 
138
138
  ```c
139
139
  void
140
- serialize(const char *source, size_t length) {
140
+ serialize(const uint8_t *source, size_t length) {
141
141
  yp_buffer_t buffer;
142
142
  if (!yp_buffer_init(&buffer)) return;
143
143
 
data/ext/yarp/api_node.c CHANGED
@@ -150,7 +150,7 @@ static VALUE rb_cYARPXStringNode;
150
150
  static VALUE rb_cYARPYieldNode;
151
151
 
152
152
  static VALUE
153
- yp_location_new(yp_parser_t *parser, const char *start, const char *end, VALUE source) {
153
+ yp_location_new(yp_parser_t *parser, const uint8_t *start, const uint8_t *end, VALUE source) {
154
154
  VALUE argv[] = { source, LONG2FIX(start - parser->start), LONG2FIX(end - start) };
155
155
  return rb_class_new_instance(3, argv, rb_cYARPLocation);
156
156
  }
@@ -162,7 +162,7 @@ yp_token_new(yp_parser_t *parser, yp_token_t *token, rb_encoding *encoding, VALU
162
162
 
163
163
  VALUE argv[] = {
164
164
  ID2SYM(type),
165
- rb_enc_str_new(token->start, token->end - token->start, encoding),
165
+ rb_enc_str_new((const char *) token->start, token->end - token->start, encoding),
166
166
  location
167
167
  };
168
168
 
@@ -171,13 +171,13 @@ yp_token_new(yp_parser_t *parser, yp_token_t *token, rb_encoding *encoding, VALU
171
171
 
172
172
  static VALUE
173
173
  yp_string_new(yp_string_t *string, rb_encoding *encoding) {
174
- return rb_enc_str_new(yp_string_source(string), yp_string_length(string), encoding);
174
+ return rb_enc_str_new((const char *) yp_string_source(string), yp_string_length(string), encoding);
175
175
  }
176
176
 
177
177
  // Create a YARP::Source object from the given parser.
178
178
  VALUE
179
179
  yp_source_new(yp_parser_t *parser) {
180
- VALUE source = rb_str_new(parser->start, parser->end - parser->start);
180
+ VALUE source = rb_str_new((const char *) parser->start, parser->end - parser->start);
181
181
  VALUE offsets = rb_ary_new_capa(parser->newline_list.size);
182
182
 
183
183
  for (size_t index = 0; index < parser->newline_list.size; index++) {
@@ -223,7 +223,7 @@ yp_ast_new(yp_parser_t *parser, yp_node_t *node, rb_encoding *encoding) {
223
223
  yp_constant_t constant = parser->constant_pool.constants[index];
224
224
 
225
225
  if (constant.id != 0) {
226
- constants[constant.id - 1] = rb_intern3(constant.start, constant.length, encoding);
226
+ constants[constant.id - 1] = rb_intern3((const char *) constant.start, constant.length, encoding);
227
227
  }
228
228
  }
229
229
 
@@ -1366,8 +1366,8 @@ yp_ast_new(yp_parser_t *parser, yp_node_t *node, rb_encoding *encoding) {
1366
1366
  // value
1367
1367
  argv[2] = rb_ary_pop(value_stack);
1368
1368
 
1369
- // operator_id
1370
- argv[3] = rb_id2sym(constants[cast->operator_id - 1]);
1369
+ // operator
1370
+ argv[3] = rb_id2sym(constants[cast->operator - 1]);
1371
1371
 
1372
1372
  // location
1373
1373
  argv[4] = yp_location_new(parser, node->location.start, node->location.end, source);
@@ -1465,104 +1465,124 @@ yp_ast_new(yp_parser_t *parser, yp_node_t *node, rb_encoding *encoding) {
1465
1465
  #line 137 "api_node.c.erb"
1466
1466
  case YP_NODE_CLASS_VARIABLE_AND_WRITE_NODE: {
1467
1467
  yp_class_variable_and_write_node_t *cast = (yp_class_variable_and_write_node_t *) node;
1468
- VALUE argv[4];
1468
+ VALUE argv[5];
1469
+
1470
+ // name
1471
+ argv[0] = rb_id2sym(constants[cast->name - 1]);
1469
1472
 
1470
1473
  // name_loc
1471
- argv[0] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source);
1474
+ argv[1] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source);
1472
1475
 
1473
1476
  // operator_loc
1474
- argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source);
1477
+ argv[2] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source);
1475
1478
 
1476
1479
  // value
1477
- argv[2] = rb_ary_pop(value_stack);
1480
+ argv[3] = rb_ary_pop(value_stack);
1478
1481
 
1479
1482
  // location
1480
- argv[3] = yp_location_new(parser, node->location.start, node->location.end, source);
1483
+ argv[4] = yp_location_new(parser, node->location.start, node->location.end, source);
1481
1484
 
1482
- rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPClassVariableAndWriteNode));
1485
+ rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPClassVariableAndWriteNode));
1483
1486
  break;
1484
1487
  }
1485
1488
  #line 137 "api_node.c.erb"
1486
1489
  case YP_NODE_CLASS_VARIABLE_OPERATOR_WRITE_NODE: {
1487
1490
  yp_class_variable_operator_write_node_t *cast = (yp_class_variable_operator_write_node_t *) node;
1488
- VALUE argv[5];
1491
+ VALUE argv[6];
1492
+
1493
+ // name
1494
+ argv[0] = rb_id2sym(constants[cast->name - 1]);
1489
1495
 
1490
1496
  // name_loc
1491
- argv[0] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source);
1497
+ argv[1] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source);
1492
1498
 
1493
1499
  // operator_loc
1494
- argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source);
1500
+ argv[2] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source);
1495
1501
 
1496
1502
  // value
1497
- argv[2] = rb_ary_pop(value_stack);
1503
+ argv[3] = rb_ary_pop(value_stack);
1498
1504
 
1499
1505
  // operator
1500
- argv[3] = rb_id2sym(constants[cast->operator - 1]);
1506
+ argv[4] = rb_id2sym(constants[cast->operator - 1]);
1501
1507
 
1502
1508
  // location
1503
- argv[4] = yp_location_new(parser, node->location.start, node->location.end, source);
1509
+ argv[5] = yp_location_new(parser, node->location.start, node->location.end, source);
1504
1510
 
1505
- rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPClassVariableOperatorWriteNode));
1511
+ rb_ary_push(value_stack, rb_class_new_instance(6, argv, rb_cYARPClassVariableOperatorWriteNode));
1506
1512
  break;
1507
1513
  }
1508
1514
  #line 137 "api_node.c.erb"
1509
1515
  case YP_NODE_CLASS_VARIABLE_OR_WRITE_NODE: {
1510
1516
  yp_class_variable_or_write_node_t *cast = (yp_class_variable_or_write_node_t *) node;
1511
- VALUE argv[4];
1517
+ VALUE argv[5];
1518
+
1519
+ // name
1520
+ argv[0] = rb_id2sym(constants[cast->name - 1]);
1512
1521
 
1513
1522
  // name_loc
1514
- argv[0] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source);
1523
+ argv[1] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source);
1515
1524
 
1516
1525
  // operator_loc
1517
- argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source);
1526
+ argv[2] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source);
1518
1527
 
1519
1528
  // value
1520
- argv[2] = rb_ary_pop(value_stack);
1529
+ argv[3] = rb_ary_pop(value_stack);
1521
1530
 
1522
1531
  // location
1523
- argv[3] = yp_location_new(parser, node->location.start, node->location.end, source);
1532
+ argv[4] = yp_location_new(parser, node->location.start, node->location.end, source);
1524
1533
 
1525
- rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPClassVariableOrWriteNode));
1534
+ rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPClassVariableOrWriteNode));
1526
1535
  break;
1527
1536
  }
1528
1537
  #line 137 "api_node.c.erb"
1529
1538
  case YP_NODE_CLASS_VARIABLE_READ_NODE: {
1530
- VALUE argv[1];
1539
+ yp_class_variable_read_node_t *cast = (yp_class_variable_read_node_t *) node;
1540
+ VALUE argv[2];
1541
+
1542
+ // name
1543
+ argv[0] = rb_id2sym(constants[cast->name - 1]);
1531
1544
 
1532
1545
  // location
1533
- argv[0] = yp_location_new(parser, node->location.start, node->location.end, source);
1546
+ argv[1] = yp_location_new(parser, node->location.start, node->location.end, source);
1534
1547
 
1535
- rb_ary_push(value_stack, rb_class_new_instance(1, argv, rb_cYARPClassVariableReadNode));
1548
+ rb_ary_push(value_stack, rb_class_new_instance(2, argv, rb_cYARPClassVariableReadNode));
1536
1549
  break;
1537
1550
  }
1538
1551
  #line 137 "api_node.c.erb"
1539
1552
  case YP_NODE_CLASS_VARIABLE_TARGET_NODE: {
1540
- VALUE argv[1];
1553
+ yp_class_variable_target_node_t *cast = (yp_class_variable_target_node_t *) node;
1554
+ VALUE argv[2];
1555
+
1556
+ // name
1557
+ argv[0] = rb_id2sym(constants[cast->name - 1]);
1541
1558
 
1542
1559
  // location
1543
- argv[0] = yp_location_new(parser, node->location.start, node->location.end, source);
1560
+ argv[1] = yp_location_new(parser, node->location.start, node->location.end, source);
1544
1561
 
1545
- rb_ary_push(value_stack, rb_class_new_instance(1, argv, rb_cYARPClassVariableTargetNode));
1562
+ rb_ary_push(value_stack, rb_class_new_instance(2, argv, rb_cYARPClassVariableTargetNode));
1546
1563
  break;
1547
1564
  }
1548
1565
  #line 137 "api_node.c.erb"
1549
1566
  case YP_NODE_CLASS_VARIABLE_WRITE_NODE: {
1550
1567
  yp_class_variable_write_node_t *cast = (yp_class_variable_write_node_t *) node;
1551
- VALUE argv[4];
1568
+ VALUE argv[5];
1569
+
1570
+ // name
1571
+ argv[0] = rb_id2sym(constants[cast->name - 1]);
1552
1572
 
1553
1573
  // name_loc
1554
- argv[0] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source);
1574
+ argv[1] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source);
1555
1575
 
1556
1576
  // value
1557
- argv[1] = rb_ary_pop(value_stack);
1577
+ argv[2] = rb_ary_pop(value_stack);
1558
1578
 
1559
1579
  // operator_loc
1560
- argv[2] = cast->operator_loc.start == NULL ? Qnil : yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source);
1580
+ argv[3] = cast->operator_loc.start == NULL ? Qnil : yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source);
1561
1581
 
1562
1582
  // location
1563
- argv[3] = yp_location_new(parser, node->location.start, node->location.end, source);
1583
+ argv[4] = yp_location_new(parser, node->location.start, node->location.end, source);
1564
1584
 
1565
- rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPClassVariableWriteNode));
1585
+ rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPClassVariableWriteNode));
1566
1586
  break;
1567
1587
  }
1568
1588
  #line 137 "api_node.c.erb"
@@ -2169,11 +2189,11 @@ yp_ast_new(yp_parser_t *parser, yp_node_t *node, rb_encoding *encoding) {
2169
2189
  // name_loc
2170
2190
  argv[0] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source);
2171
2191
 
2172
- // operator_loc
2173
- argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source);
2174
-
2175
2192
  // value
2176
- argv[2] = rb_ary_pop(value_stack);
2193
+ argv[1] = rb_ary_pop(value_stack);
2194
+
2195
+ // operator_loc
2196
+ argv[2] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source);
2177
2197
 
2178
2198
  // location
2179
2199
  argv[3] = yp_location_new(parser, node->location.start, node->location.end, source);
@@ -2298,104 +2318,124 @@ yp_ast_new(yp_parser_t *parser, yp_node_t *node, rb_encoding *encoding) {
2298
2318
  #line 137 "api_node.c.erb"
2299
2319
  case YP_NODE_INSTANCE_VARIABLE_AND_WRITE_NODE: {
2300
2320
  yp_instance_variable_and_write_node_t *cast = (yp_instance_variable_and_write_node_t *) node;
2301
- VALUE argv[4];
2321
+ VALUE argv[5];
2322
+
2323
+ // name
2324
+ argv[0] = rb_id2sym(constants[cast->name - 1]);
2302
2325
 
2303
2326
  // name_loc
2304
- argv[0] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source);
2327
+ argv[1] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source);
2305
2328
 
2306
2329
  // operator_loc
2307
- argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source);
2330
+ argv[2] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source);
2308
2331
 
2309
2332
  // value
2310
- argv[2] = rb_ary_pop(value_stack);
2333
+ argv[3] = rb_ary_pop(value_stack);
2311
2334
 
2312
2335
  // location
2313
- argv[3] = yp_location_new(parser, node->location.start, node->location.end, source);
2336
+ argv[4] = yp_location_new(parser, node->location.start, node->location.end, source);
2314
2337
 
2315
- rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPInstanceVariableAndWriteNode));
2338
+ rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPInstanceVariableAndWriteNode));
2316
2339
  break;
2317
2340
  }
2318
2341
  #line 137 "api_node.c.erb"
2319
2342
  case YP_NODE_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE: {
2320
2343
  yp_instance_variable_operator_write_node_t *cast = (yp_instance_variable_operator_write_node_t *) node;
2321
- VALUE argv[5];
2344
+ VALUE argv[6];
2345
+
2346
+ // name
2347
+ argv[0] = rb_id2sym(constants[cast->name - 1]);
2322
2348
 
2323
2349
  // name_loc
2324
- argv[0] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source);
2350
+ argv[1] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source);
2325
2351
 
2326
2352
  // operator_loc
2327
- argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source);
2353
+ argv[2] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source);
2328
2354
 
2329
2355
  // value
2330
- argv[2] = rb_ary_pop(value_stack);
2356
+ argv[3] = rb_ary_pop(value_stack);
2331
2357
 
2332
2358
  // operator
2333
- argv[3] = rb_id2sym(constants[cast->operator - 1]);
2359
+ argv[4] = rb_id2sym(constants[cast->operator - 1]);
2334
2360
 
2335
2361
  // location
2336
- argv[4] = yp_location_new(parser, node->location.start, node->location.end, source);
2362
+ argv[5] = yp_location_new(parser, node->location.start, node->location.end, source);
2337
2363
 
2338
- rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPInstanceVariableOperatorWriteNode));
2364
+ rb_ary_push(value_stack, rb_class_new_instance(6, argv, rb_cYARPInstanceVariableOperatorWriteNode));
2339
2365
  break;
2340
2366
  }
2341
2367
  #line 137 "api_node.c.erb"
2342
2368
  case YP_NODE_INSTANCE_VARIABLE_OR_WRITE_NODE: {
2343
2369
  yp_instance_variable_or_write_node_t *cast = (yp_instance_variable_or_write_node_t *) node;
2344
- VALUE argv[4];
2370
+ VALUE argv[5];
2371
+
2372
+ // name
2373
+ argv[0] = rb_id2sym(constants[cast->name - 1]);
2345
2374
 
2346
2375
  // name_loc
2347
- argv[0] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source);
2376
+ argv[1] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source);
2348
2377
 
2349
2378
  // operator_loc
2350
- argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source);
2379
+ argv[2] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source);
2351
2380
 
2352
2381
  // value
2353
- argv[2] = rb_ary_pop(value_stack);
2382
+ argv[3] = rb_ary_pop(value_stack);
2354
2383
 
2355
2384
  // location
2356
- argv[3] = yp_location_new(parser, node->location.start, node->location.end, source);
2385
+ argv[4] = yp_location_new(parser, node->location.start, node->location.end, source);
2357
2386
 
2358
- rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPInstanceVariableOrWriteNode));
2387
+ rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPInstanceVariableOrWriteNode));
2359
2388
  break;
2360
2389
  }
2361
2390
  #line 137 "api_node.c.erb"
2362
2391
  case YP_NODE_INSTANCE_VARIABLE_READ_NODE: {
2363
- VALUE argv[1];
2392
+ yp_instance_variable_read_node_t *cast = (yp_instance_variable_read_node_t *) node;
2393
+ VALUE argv[2];
2394
+
2395
+ // name
2396
+ argv[0] = rb_id2sym(constants[cast->name - 1]);
2364
2397
 
2365
2398
  // location
2366
- argv[0] = yp_location_new(parser, node->location.start, node->location.end, source);
2399
+ argv[1] = yp_location_new(parser, node->location.start, node->location.end, source);
2367
2400
 
2368
- rb_ary_push(value_stack, rb_class_new_instance(1, argv, rb_cYARPInstanceVariableReadNode));
2401
+ rb_ary_push(value_stack, rb_class_new_instance(2, argv, rb_cYARPInstanceVariableReadNode));
2369
2402
  break;
2370
2403
  }
2371
2404
  #line 137 "api_node.c.erb"
2372
2405
  case YP_NODE_INSTANCE_VARIABLE_TARGET_NODE: {
2373
- VALUE argv[1];
2406
+ yp_instance_variable_target_node_t *cast = (yp_instance_variable_target_node_t *) node;
2407
+ VALUE argv[2];
2408
+
2409
+ // name
2410
+ argv[0] = rb_id2sym(constants[cast->name - 1]);
2374
2411
 
2375
2412
  // location
2376
- argv[0] = yp_location_new(parser, node->location.start, node->location.end, source);
2413
+ argv[1] = yp_location_new(parser, node->location.start, node->location.end, source);
2377
2414
 
2378
- rb_ary_push(value_stack, rb_class_new_instance(1, argv, rb_cYARPInstanceVariableTargetNode));
2415
+ rb_ary_push(value_stack, rb_class_new_instance(2, argv, rb_cYARPInstanceVariableTargetNode));
2379
2416
  break;
2380
2417
  }
2381
2418
  #line 137 "api_node.c.erb"
2382
2419
  case YP_NODE_INSTANCE_VARIABLE_WRITE_NODE: {
2383
2420
  yp_instance_variable_write_node_t *cast = (yp_instance_variable_write_node_t *) node;
2384
- VALUE argv[4];
2421
+ VALUE argv[5];
2422
+
2423
+ // name
2424
+ argv[0] = rb_id2sym(constants[cast->name - 1]);
2385
2425
 
2386
2426
  // name_loc
2387
- argv[0] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source);
2427
+ argv[1] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source);
2388
2428
 
2389
2429
  // value
2390
- argv[1] = rb_ary_pop(value_stack);
2430
+ argv[2] = rb_ary_pop(value_stack);
2391
2431
 
2392
2432
  // operator_loc
2393
- argv[2] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source);
2433
+ argv[3] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source);
2394
2434
 
2395
2435
  // location
2396
- argv[3] = yp_location_new(parser, node->location.start, node->location.end, source);
2436
+ argv[4] = yp_location_new(parser, node->location.start, node->location.end, source);
2397
2437
 
2398
- rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPInstanceVariableWriteNode));
2438
+ rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPInstanceVariableWriteNode));
2399
2439
  break;
2400
2440
  }
2401
2441
  #line 137 "api_node.c.erb"
@@ -2600,8 +2640,8 @@ yp_ast_new(yp_parser_t *parser, yp_node_t *node, rb_encoding *encoding) {
2600
2640
  // value
2601
2641
  argv[2] = rb_ary_pop(value_stack);
2602
2642
 
2603
- // constant_id
2604
- argv[3] = rb_id2sym(constants[cast->constant_id - 1]);
2643
+ // name
2644
+ argv[3] = rb_id2sym(constants[cast->name - 1]);
2605
2645
 
2606
2646
  // depth
2607
2647
  argv[4] = ULONG2NUM(cast->depth);
@@ -2626,11 +2666,11 @@ yp_ast_new(yp_parser_t *parser, yp_node_t *node, rb_encoding *encoding) {
2626
2666
  // value
2627
2667
  argv[2] = rb_ary_pop(value_stack);
2628
2668
 
2629
- // constant_id
2630
- argv[3] = rb_id2sym(constants[cast->constant_id - 1]);
2669
+ // name
2670
+ argv[3] = rb_id2sym(constants[cast->name - 1]);
2631
2671
 
2632
- // operator_id
2633
- argv[4] = rb_id2sym(constants[cast->operator_id - 1]);
2672
+ // operator
2673
+ argv[4] = rb_id2sym(constants[cast->operator - 1]);
2634
2674
 
2635
2675
  // depth
2636
2676
  argv[5] = ULONG2NUM(cast->depth);
@@ -2655,8 +2695,8 @@ yp_ast_new(yp_parser_t *parser, yp_node_t *node, rb_encoding *encoding) {
2655
2695
  // value
2656
2696
  argv[2] = rb_ary_pop(value_stack);
2657
2697
 
2658
- // constant_id
2659
- argv[3] = rb_id2sym(constants[cast->constant_id - 1]);
2698
+ // name
2699
+ argv[3] = rb_id2sym(constants[cast->name - 1]);
2660
2700
 
2661
2701
  // depth
2662
2702
  argv[4] = ULONG2NUM(cast->depth);
@@ -2672,8 +2712,8 @@ yp_ast_new(yp_parser_t *parser, yp_node_t *node, rb_encoding *encoding) {
2672
2712
  yp_local_variable_read_node_t *cast = (yp_local_variable_read_node_t *) node;
2673
2713
  VALUE argv[3];
2674
2714
 
2675
- // constant_id
2676
- argv[0] = rb_id2sym(constants[cast->constant_id - 1]);
2715
+ // name
2716
+ argv[0] = rb_id2sym(constants[cast->name - 1]);
2677
2717
 
2678
2718
  // depth
2679
2719
  argv[1] = ULONG2NUM(cast->depth);
@@ -2689,8 +2729,8 @@ yp_ast_new(yp_parser_t *parser, yp_node_t *node, rb_encoding *encoding) {
2689
2729
  yp_local_variable_target_node_t *cast = (yp_local_variable_target_node_t *) node;
2690
2730
  VALUE argv[3];
2691
2731
 
2692
- // constant_id
2693
- argv[0] = rb_id2sym(constants[cast->constant_id - 1]);
2732
+ // name
2733
+ argv[0] = rb_id2sym(constants[cast->name - 1]);
2694
2734
 
2695
2735
  // depth
2696
2736
  argv[1] = ULONG2NUM(cast->depth);
@@ -2706,17 +2746,17 @@ yp_ast_new(yp_parser_t *parser, yp_node_t *node, rb_encoding *encoding) {
2706
2746
  yp_local_variable_write_node_t *cast = (yp_local_variable_write_node_t *) node;
2707
2747
  VALUE argv[6];
2708
2748
 
2709
- // constant_id
2710
- argv[0] = rb_id2sym(constants[cast->constant_id - 1]);
2749
+ // name
2750
+ argv[0] = rb_id2sym(constants[cast->name - 1]);
2711
2751
 
2712
2752
  // depth
2713
2753
  argv[1] = ULONG2NUM(cast->depth);
2714
2754
 
2715
- // value
2716
- argv[2] = rb_ary_pop(value_stack);
2717
-
2718
2755
  // name_loc
2719
- argv[3] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source);
2756
+ argv[2] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source);
2757
+
2758
+ // value
2759
+ argv[3] = rb_ary_pop(value_stack);
2720
2760
 
2721
2761
  // operator_loc
2722
2762
  argv[4] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source);
@@ -2884,12 +2924,16 @@ yp_ast_new(yp_parser_t *parser, yp_node_t *node, rb_encoding *encoding) {
2884
2924
  }
2885
2925
  #line 137 "api_node.c.erb"
2886
2926
  case YP_NODE_NUMBERED_REFERENCE_READ_NODE: {
2887
- VALUE argv[1];
2927
+ yp_numbered_reference_read_node_t *cast = (yp_numbered_reference_read_node_t *) node;
2928
+ VALUE argv[2];
2929
+
2930
+ // number
2931
+ argv[0] = ULONG2NUM(cast->number);
2888
2932
 
2889
2933
  // location
2890
- argv[0] = yp_location_new(parser, node->location.start, node->location.end, source);
2934
+ argv[1] = yp_location_new(parser, node->location.start, node->location.end, source);
2891
2935
 
2892
- rb_ary_push(value_stack, rb_class_new_instance(1, argv, rb_cYARPNumberedReferenceReadNode));
2936
+ rb_ary_push(value_stack, rb_class_new_instance(2, argv, rb_cYARPNumberedReferenceReadNode));
2893
2937
  break;
2894
2938
  }
2895
2939
  #line 137 "api_node.c.erb"
@@ -2897,8 +2941,8 @@ yp_ast_new(yp_parser_t *parser, yp_node_t *node, rb_encoding *encoding) {
2897
2941
  yp_optional_parameter_node_t *cast = (yp_optional_parameter_node_t *) node;
2898
2942
  VALUE argv[5];
2899
2943
 
2900
- // constant_id
2901
- argv[0] = rb_id2sym(constants[cast->constant_id - 1]);
2944
+ // name
2945
+ argv[0] = rb_id2sym(constants[cast->name - 1]);
2902
2946
 
2903
2947
  // name_loc
2904
2948
  argv[1] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source);
@@ -3205,8 +3249,8 @@ yp_ast_new(yp_parser_t *parser, yp_node_t *node, rb_encoding *encoding) {
3205
3249
  yp_required_parameter_node_t *cast = (yp_required_parameter_node_t *) node;
3206
3250
  VALUE argv[2];
3207
3251
 
3208
- // constant_id
3209
- argv[0] = rb_id2sym(constants[cast->constant_id - 1]);
3252
+ // name
3253
+ argv[0] = rb_id2sym(constants[cast->name - 1]);
3210
3254
 
3211
3255
  // location
3212
3256
  argv[1] = yp_location_new(parser, node->location.start, node->location.end, source);
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 = {
@@ -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,7 +1,7 @@
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.10.0"
5
5
 
6
6
  #include <ruby.h>
7
7
  #include <ruby/encoding.h>