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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -1
- data/Makefile +5 -1
- data/config.yml +156 -125
- data/docs/encoding.md +5 -5
- data/docs/serialization.md +2 -2
- data/ext/yarp/api_node.c +142 -98
- data/ext/yarp/extension.c +21 -7
- data/ext/yarp/extension.h +1 -1
- data/include/yarp/ast.h +327 -18
- data/include/yarp/defines.h +2 -1
- data/include/yarp/diagnostic.h +3 -3
- data/include/yarp/enc/yp_encoding.h +10 -10
- data/include/yarp/parser.h +19 -19
- data/include/yarp/regexp.h +1 -1
- data/include/yarp/unescape.h +4 -4
- data/include/yarp/util/yp_buffer.h +3 -0
- data/include/yarp/util/yp_char.h +16 -16
- data/include/yarp/util/yp_constant_pool.h +2 -2
- data/include/yarp/util/yp_newline_list.h +5 -5
- data/include/yarp/util/yp_string.h +4 -4
- data/include/yarp/util/yp_string_list.h +0 -3
- data/include/yarp/util/yp_strpbrk.h +1 -1
- data/include/yarp/version.h +2 -2
- data/include/yarp.h +5 -4
- data/lib/yarp/desugar_visitor.rb +59 -122
- data/lib/yarp/node.rb +230 -240
- data/lib/yarp/serialize.rb +16 -16
- data/lib/yarp.rb +5 -5
- data/src/diagnostic.c +1 -1
- data/src/enc/yp_big5.c +15 -42
- data/src/enc/yp_euc_jp.c +16 -43
- data/src/enc/yp_gbk.c +19 -46
- data/src/enc/yp_shift_jis.c +16 -43
- data/src/enc/yp_tables.c +36 -38
- data/src/enc/yp_unicode.c +20 -25
- data/src/enc/yp_windows_31j.c +16 -43
- data/src/node.c +1271 -899
- data/src/prettyprint.c +87 -48
- data/src/regexp.c +21 -21
- data/src/serialize.c +28 -15
- data/src/unescape.c +151 -121
- data/src/util/yp_buffer.c +7 -2
- data/src/util/yp_char.c +34 -34
- data/src/util/yp_constant_pool.c +4 -4
- data/src/util/yp_memchr.c +1 -1
- data/src/util/yp_newline_list.c +5 -4
- data/src/util/yp_string.c +22 -20
- data/src/util/yp_string_list.c +0 -6
- data/src/util/yp_strncasecmp.c +3 -6
- data/src/util/yp_strpbrk.c +8 -8
- data/src/yarp.c +355 -216
- data/yarp.gemspec +1 -1
- 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
|
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
|
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
|
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
|
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
|
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
|
data/docs/serialization.md
CHANGED
@@ -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
|
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
|
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
|
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
|
-
//
|
1370
|
-
argv[3] = rb_id2sym(constants[cast->
|
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[
|
1468
|
+
VALUE argv[5];
|
1469
|
+
|
1470
|
+
// name
|
1471
|
+
argv[0] = rb_id2sym(constants[cast->name - 1]);
|
1469
1472
|
|
1470
1473
|
// name_loc
|
1471
|
-
argv[
|
1474
|
+
argv[1] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source);
|
1472
1475
|
|
1473
1476
|
// operator_loc
|
1474
|
-
argv[
|
1477
|
+
argv[2] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source);
|
1475
1478
|
|
1476
1479
|
// value
|
1477
|
-
argv[
|
1480
|
+
argv[3] = rb_ary_pop(value_stack);
|
1478
1481
|
|
1479
1482
|
// location
|
1480
|
-
argv[
|
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(
|
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[
|
1491
|
+
VALUE argv[6];
|
1492
|
+
|
1493
|
+
// name
|
1494
|
+
argv[0] = rb_id2sym(constants[cast->name - 1]);
|
1489
1495
|
|
1490
1496
|
// name_loc
|
1491
|
-
argv[
|
1497
|
+
argv[1] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source);
|
1492
1498
|
|
1493
1499
|
// operator_loc
|
1494
|
-
argv[
|
1500
|
+
argv[2] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source);
|
1495
1501
|
|
1496
1502
|
// value
|
1497
|
-
argv[
|
1503
|
+
argv[3] = rb_ary_pop(value_stack);
|
1498
1504
|
|
1499
1505
|
// operator
|
1500
|
-
argv[
|
1506
|
+
argv[4] = rb_id2sym(constants[cast->operator - 1]);
|
1501
1507
|
|
1502
1508
|
// location
|
1503
|
-
argv[
|
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(
|
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[
|
1517
|
+
VALUE argv[5];
|
1518
|
+
|
1519
|
+
// name
|
1520
|
+
argv[0] = rb_id2sym(constants[cast->name - 1]);
|
1512
1521
|
|
1513
1522
|
// name_loc
|
1514
|
-
argv[
|
1523
|
+
argv[1] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source);
|
1515
1524
|
|
1516
1525
|
// operator_loc
|
1517
|
-
argv[
|
1526
|
+
argv[2] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source);
|
1518
1527
|
|
1519
1528
|
// value
|
1520
|
-
argv[
|
1529
|
+
argv[3] = rb_ary_pop(value_stack);
|
1521
1530
|
|
1522
1531
|
// location
|
1523
|
-
argv[
|
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(
|
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
|
-
|
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[
|
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(
|
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
|
-
|
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[
|
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(
|
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[
|
1568
|
+
VALUE argv[5];
|
1569
|
+
|
1570
|
+
// name
|
1571
|
+
argv[0] = rb_id2sym(constants[cast->name - 1]);
|
1552
1572
|
|
1553
1573
|
// name_loc
|
1554
|
-
argv[
|
1574
|
+
argv[1] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source);
|
1555
1575
|
|
1556
1576
|
// value
|
1557
|
-
argv[
|
1577
|
+
argv[2] = rb_ary_pop(value_stack);
|
1558
1578
|
|
1559
1579
|
// operator_loc
|
1560
|
-
argv[
|
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[
|
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(
|
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[
|
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[
|
2321
|
+
VALUE argv[5];
|
2322
|
+
|
2323
|
+
// name
|
2324
|
+
argv[0] = rb_id2sym(constants[cast->name - 1]);
|
2302
2325
|
|
2303
2326
|
// name_loc
|
2304
|
-
argv[
|
2327
|
+
argv[1] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source);
|
2305
2328
|
|
2306
2329
|
// operator_loc
|
2307
|
-
argv[
|
2330
|
+
argv[2] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source);
|
2308
2331
|
|
2309
2332
|
// value
|
2310
|
-
argv[
|
2333
|
+
argv[3] = rb_ary_pop(value_stack);
|
2311
2334
|
|
2312
2335
|
// location
|
2313
|
-
argv[
|
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(
|
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[
|
2344
|
+
VALUE argv[6];
|
2345
|
+
|
2346
|
+
// name
|
2347
|
+
argv[0] = rb_id2sym(constants[cast->name - 1]);
|
2322
2348
|
|
2323
2349
|
// name_loc
|
2324
|
-
argv[
|
2350
|
+
argv[1] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source);
|
2325
2351
|
|
2326
2352
|
// operator_loc
|
2327
|
-
argv[
|
2353
|
+
argv[2] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source);
|
2328
2354
|
|
2329
2355
|
// value
|
2330
|
-
argv[
|
2356
|
+
argv[3] = rb_ary_pop(value_stack);
|
2331
2357
|
|
2332
2358
|
// operator
|
2333
|
-
argv[
|
2359
|
+
argv[4] = rb_id2sym(constants[cast->operator - 1]);
|
2334
2360
|
|
2335
2361
|
// location
|
2336
|
-
argv[
|
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(
|
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[
|
2370
|
+
VALUE argv[5];
|
2371
|
+
|
2372
|
+
// name
|
2373
|
+
argv[0] = rb_id2sym(constants[cast->name - 1]);
|
2345
2374
|
|
2346
2375
|
// name_loc
|
2347
|
-
argv[
|
2376
|
+
argv[1] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source);
|
2348
2377
|
|
2349
2378
|
// operator_loc
|
2350
|
-
argv[
|
2379
|
+
argv[2] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source);
|
2351
2380
|
|
2352
2381
|
// value
|
2353
|
-
argv[
|
2382
|
+
argv[3] = rb_ary_pop(value_stack);
|
2354
2383
|
|
2355
2384
|
// location
|
2356
|
-
argv[
|
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(
|
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
|
-
|
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[
|
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(
|
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
|
-
|
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[
|
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(
|
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[
|
2421
|
+
VALUE argv[5];
|
2422
|
+
|
2423
|
+
// name
|
2424
|
+
argv[0] = rb_id2sym(constants[cast->name - 1]);
|
2385
2425
|
|
2386
2426
|
// name_loc
|
2387
|
-
argv[
|
2427
|
+
argv[1] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source);
|
2388
2428
|
|
2389
2429
|
// value
|
2390
|
-
argv[
|
2430
|
+
argv[2] = rb_ary_pop(value_stack);
|
2391
2431
|
|
2392
2432
|
// operator_loc
|
2393
|
-
argv[
|
2433
|
+
argv[3] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source);
|
2394
2434
|
|
2395
2435
|
// location
|
2396
|
-
argv[
|
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(
|
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
|
-
//
|
2604
|
-
argv[3] = rb_id2sym(constants[cast->
|
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
|
-
//
|
2630
|
-
argv[3] = rb_id2sym(constants[cast->
|
2669
|
+
// name
|
2670
|
+
argv[3] = rb_id2sym(constants[cast->name - 1]);
|
2631
2671
|
|
2632
|
-
//
|
2633
|
-
argv[4] = rb_id2sym(constants[cast->
|
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
|
-
//
|
2659
|
-
argv[3] = rb_id2sym(constants[cast->
|
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
|
-
//
|
2676
|
-
argv[0] = rb_id2sym(constants[cast->
|
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
|
-
//
|
2693
|
-
argv[0] = rb_id2sym(constants[cast->
|
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
|
-
//
|
2710
|
-
argv[0] = rb_id2sym(constants[cast->
|
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[
|
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
|
-
|
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[
|
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(
|
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
|
-
//
|
2901
|
-
argv[0] = rb_id2sym(constants[cast->
|
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
|
-
//
|
3209
|
-
argv[0] = rb_id2sym(constants[cast->
|
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
|
-
|
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;
|