rbs 2.8.4 → 3.0.0.dev.2
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/.github/workflows/ruby.yml +0 -3
- data/Gemfile +1 -1
- data/Gemfile.lock +17 -17
- data/README.md +1 -0
- data/Rakefile +66 -0
- data/core/array.rbs +1 -1
- data/core/builtin.rbs +1 -1
- data/core/hash.rbs +1 -1
- data/core/module.rbs +1 -1
- data/ext/rbs_extension/constants.c +18 -2
- data/ext/rbs_extension/constants.h +9 -1
- data/ext/rbs_extension/lexer.c +834 -777
- data/ext/rbs_extension/lexer.h +3 -1
- data/ext/rbs_extension/lexer.re +3 -1
- data/ext/rbs_extension/lexstate.c +4 -2
- data/ext/rbs_extension/parser.c +287 -57
- data/ext/rbs_extension/ruby_objs.c +71 -5
- data/ext/rbs_extension/ruby_objs.h +9 -2
- data/lib/rbs/annotate/rdoc_annotator.rb +1 -1
- data/lib/rbs/ast/declarations.rb +49 -2
- data/lib/rbs/ast/directives.rb +39 -0
- data/lib/rbs/ast/members.rb +49 -15
- data/lib/rbs/cli.rb +38 -19
- data/lib/rbs/collection/config/lockfile.rb +115 -0
- data/lib/rbs/collection/config/lockfile_generator.rb +99 -53
- data/lib/rbs/collection/config.rb +12 -40
- data/lib/rbs/collection/installer.rb +9 -13
- data/lib/rbs/collection/sources/base.rb +2 -2
- data/lib/rbs/collection/sources/git.rb +135 -62
- data/lib/rbs/collection/sources/rubygems.rb +10 -12
- data/lib/rbs/collection/sources/stdlib.rb +10 -13
- data/lib/rbs/collection/sources.rb +7 -1
- data/lib/rbs/collection.rb +1 -0
- data/lib/rbs/definition.rb +1 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +24 -8
- data/lib/rbs/definition_builder/method_builder.rb +3 -3
- data/lib/rbs/definition_builder.rb +456 -579
- data/lib/rbs/environment/use_map.rb +77 -0
- data/lib/rbs/environment.rb +356 -85
- data/lib/rbs/environment_loader.rb +20 -17
- data/lib/rbs/environment_walker.rb +1 -1
- data/lib/rbs/errors.rb +34 -37
- data/lib/rbs/locator.rb +3 -3
- data/lib/rbs/parser_aux.rb +8 -6
- data/lib/rbs/prototype/helpers.rb +29 -13
- data/lib/rbs/prototype/node_usage.rb +99 -0
- data/lib/rbs/prototype/rb.rb +3 -2
- data/lib/rbs/prototype/rbi.rb +6 -4
- data/lib/rbs/prototype/runtime.rb +25 -12
- data/lib/rbs/resolver/constant_resolver.rb +23 -7
- data/lib/rbs/resolver/type_name_resolver.rb +2 -1
- data/lib/rbs/sorter.rb +3 -3
- data/lib/rbs/substitution.rb +19 -0
- data/lib/rbs/test/setup.rb +1 -1
- data/lib/rbs/type_alias_dependency.rb +1 -1
- data/lib/rbs/type_alias_regularity.rb +3 -3
- data/lib/rbs/types.rb +1 -5
- data/lib/rbs/validator.rb +25 -3
- data/lib/rbs/variance_calculator.rb +2 -2
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +54 -19
- data/lib/rbs.rb +3 -2
- data/lib/rdoc_plugin/parser.rb +3 -3
- data/schema/members.json +15 -10
- data/sig/ancestor_graph.rbs +22 -2
- data/sig/collection/config/lockfile.rbs +80 -0
- data/sig/collection/config/lockfile_generator.rbs +53 -0
- data/sig/collection/config.rbs +5 -48
- data/sig/collection/installer.rbs +1 -1
- data/sig/collection/sources.rbs +76 -33
- data/sig/constant.rbs +1 -1
- data/sig/declarations.rbs +36 -3
- data/sig/definition.rbs +1 -1
- data/sig/definition_builder.rbs +94 -82
- data/sig/directives.rbs +61 -0
- data/sig/environment.rbs +150 -28
- data/sig/environment_loader.rbs +2 -2
- data/sig/errors.rbs +42 -0
- data/sig/members.rbs +31 -7
- data/sig/parser.rbs +8 -15
- data/sig/prototype/node_usage.rbs +20 -0
- data/sig/resolver/constant_resolver.rbs +1 -2
- data/sig/shims/bundler.rbs +31 -0
- data/sig/shims/rubygems.rbs +15 -0
- data/sig/shims.rbs +0 -22
- data/sig/substitution.rbs +6 -0
- data/sig/use_map.rbs +35 -0
- data/sig/validator.rbs +12 -5
- data/sig/writer.rbs +6 -2
- metadata +16 -9
- data/lib/rbs/constant_table.rb +0 -167
- data/lib/rbs/type_name_resolver.rb +0 -67
- data/sig/constant_table.rbs +0 -30
- data/sig/type_name_resolver.rbs +0 -26
data/ext/rbs_extension/lexer.h
CHANGED
@@ -58,6 +58,8 @@ enum TokenType {
|
|
58
58
|
kUNCHECKED, /* unchecked */
|
59
59
|
kUNTYPED, /* untyped */
|
60
60
|
kVOID, /* void */
|
61
|
+
kUSE, /* use */
|
62
|
+
kAS, /* as */
|
61
63
|
|
62
64
|
tLIDENT, /* Identifiers starting with lower case */
|
63
65
|
tUIDENT, /* Identifiers starting with upper case */
|
@@ -150,7 +152,7 @@ unsigned int peek(lexstate *state);
|
|
150
152
|
/**
|
151
153
|
* Skip one character.
|
152
154
|
* */
|
153
|
-
void
|
155
|
+
void rbs_skip(lexstate *state);
|
154
156
|
|
155
157
|
/**
|
156
158
|
* Skip n characters.
|
data/ext/rbs_extension/lexer.re
CHANGED
@@ -12,7 +12,7 @@ start:
|
|
12
12
|
re2c:flags:input = custom;
|
13
13
|
re2c:define:YYCTYPE = "unsigned int";
|
14
14
|
re2c:define:YYPEEK = "peek(state)";
|
15
|
-
re2c:define:YYSKIP = "
|
15
|
+
re2c:define:YYSKIP = "rbs_skip(state);";
|
16
16
|
re2c:define:YYBACKUP = "backup = *state;";
|
17
17
|
re2c:define:YYRESTORE = "*state = backup;";
|
18
18
|
re2c:yyfill:enable = 0;
|
@@ -93,6 +93,8 @@ start:
|
|
93
93
|
"unchecked" { return next_token(state, kUNCHECKED); }
|
94
94
|
"untyped" { return next_token(state, kUNTYPED); }
|
95
95
|
"void" { return next_token(state, kVOID); }
|
96
|
+
"use" { return next_token(state, kUSE); }
|
97
|
+
"as" { return next_token(state, kAS); }
|
96
98
|
|
97
99
|
dqstring = ["] ("\\"[abefnrstv"\\] | [^"\\\x00])* ["];
|
98
100
|
sqstring = ['] ("\\"['\\] | [^'\x00])* ['];
|
@@ -57,6 +57,8 @@ static const char *RBS_TOKENTYPE_NAMES[] = {
|
|
57
57
|
"kUNCHECKED", /* unchecked */
|
58
58
|
"kUNTYPED", /* untyped */
|
59
59
|
"kVOID", /* void */
|
60
|
+
"kUSE", /* use */
|
61
|
+
"kAS", /* as */
|
60
62
|
|
61
63
|
"tLIDENT", /* Identifiers starting with lower case */
|
62
64
|
"tUIDENT", /* Identifiers starting with upper case */
|
@@ -122,7 +124,7 @@ token next_token(lexstate *state, enum TokenType type) {
|
|
122
124
|
return t;
|
123
125
|
}
|
124
126
|
|
125
|
-
void
|
127
|
+
void rbs_skip(lexstate *state) {
|
126
128
|
if (!state->last_char) {
|
127
129
|
peek(state);
|
128
130
|
}
|
@@ -143,7 +145,7 @@ void skip(lexstate *state) {
|
|
143
145
|
void skipn(lexstate *state, size_t size) {
|
144
146
|
for (size_t i = 0; i < size; i ++) {
|
145
147
|
peek(state);
|
146
|
-
|
148
|
+
rbs_skip(state);
|
147
149
|
}
|
148
150
|
}
|
149
151
|
|
data/ext/rbs_extension/parser.c
CHANGED
@@ -37,6 +37,8 @@
|
|
37
37
|
case kPUBLIC: \
|
38
38
|
case kPRIVATE: \
|
39
39
|
case kUNTYPED: \
|
40
|
+
case kUSE: \
|
41
|
+
case kAS: \
|
40
42
|
/* nop */
|
41
43
|
|
42
44
|
typedef struct {
|
@@ -1034,7 +1036,6 @@ VALUE parse_type(parserstate *state) {
|
|
1034
1036
|
|
1035
1037
|
type_param ::= tUIDENT (module_type_params == false)
|
1036
1038
|
*/
|
1037
|
-
|
1038
1039
|
VALUE parse_type_params(parserstate *state, range *rg, bool module_type_params) {
|
1039
1040
|
VALUE params = rb_ary_new();
|
1040
1041
|
|
@@ -1277,7 +1278,7 @@ VALUE parse_type_decl(parserstate *state, position comment_pos, VALUE annotation
|
|
1277
1278
|
|
1278
1279
|
parser_pop_typevar_table(state);
|
1279
1280
|
|
1280
|
-
return
|
1281
|
+
return rbs_ast_decl_type_alias(
|
1281
1282
|
typename,
|
1282
1283
|
type_params,
|
1283
1284
|
type,
|
@@ -1485,7 +1486,7 @@ VALUE parse_member_def(parserstate *state, bool instance_only, bool accept_overl
|
|
1485
1486
|
range keyword_range;
|
1486
1487
|
range name_range;
|
1487
1488
|
range kind_range;
|
1488
|
-
range
|
1489
|
+
range overloading_range = NULL_RANGE;
|
1489
1490
|
|
1490
1491
|
VALUE visibility;
|
1491
1492
|
|
@@ -1524,8 +1525,8 @@ VALUE parse_member_def(parserstate *state, bool instance_only, bool accept_overl
|
|
1524
1525
|
}
|
1525
1526
|
|
1526
1527
|
VALUE name = parse_method_name(state, &name_range);
|
1527
|
-
VALUE
|
1528
|
-
VALUE
|
1528
|
+
VALUE overloads = rb_ary_new();
|
1529
|
+
VALUE overloading = Qfalse;
|
1529
1530
|
|
1530
1531
|
if (state->next_token.type == pDOT && RB_SYM2ID(name) == rb_intern("self?")) {
|
1531
1532
|
raise_syntax_error(
|
@@ -1541,23 +1542,33 @@ VALUE parse_member_def(parserstate *state, bool instance_only, bool accept_overl
|
|
1541
1542
|
|
1542
1543
|
bool loop = true;
|
1543
1544
|
while (loop) {
|
1545
|
+
VALUE annotations = rb_ary_new();
|
1546
|
+
position overload_annot_pos = NullPosition;
|
1547
|
+
|
1548
|
+
if (state->next_token.type == tANNOTATION) {
|
1549
|
+
parse_annotations(state, annotations, &overload_annot_pos);
|
1550
|
+
}
|
1551
|
+
|
1544
1552
|
switch (state->next_token.type) {
|
1545
1553
|
case pLPAREN:
|
1546
1554
|
case pARROW:
|
1547
1555
|
case pLBRACE:
|
1548
1556
|
case pLBRACKET:
|
1549
1557
|
case pQUESTION:
|
1550
|
-
|
1551
|
-
|
1552
|
-
|
1558
|
+
{
|
1559
|
+
VALUE method_type = parse_method_type(state);
|
1560
|
+
rb_ary_push(overloads, rbs_ast_members_method_definition_overload(annotations, method_type));
|
1561
|
+
member_range.end = state->current_token.range.end;
|
1562
|
+
break;
|
1563
|
+
}
|
1553
1564
|
|
1554
1565
|
case pDOT3:
|
1555
1566
|
if (accept_overload) {
|
1556
|
-
|
1567
|
+
overloading = Qtrue;
|
1557
1568
|
parser_advance(state);
|
1558
1569
|
loop = false;
|
1559
|
-
|
1560
|
-
member_range.end =
|
1570
|
+
overloading_range = state->current_token.range;
|
1571
|
+
member_range.end = overloading_range.end;
|
1561
1572
|
break;
|
1562
1573
|
} else {
|
1563
1574
|
raise_syntax_error(
|
@@ -1604,17 +1615,17 @@ VALUE parse_member_def(parserstate *state, bool instance_only, bool accept_overl
|
|
1604
1615
|
rbs_loc_add_required_child(loc, rb_intern("keyword"), keyword_range);
|
1605
1616
|
rbs_loc_add_required_child(loc, rb_intern("name"), name_range);
|
1606
1617
|
rbs_loc_add_optional_child(loc, rb_intern("kind"), kind_range);
|
1607
|
-
rbs_loc_add_optional_child(loc, rb_intern("
|
1618
|
+
rbs_loc_add_optional_child(loc, rb_intern("overloading"), overloading_range);
|
1608
1619
|
rbs_loc_add_optional_child(loc, rb_intern("visibility"), visibility_range);
|
1609
1620
|
|
1610
1621
|
return rbs_ast_members_method_definition(
|
1611
1622
|
name,
|
1612
1623
|
k,
|
1613
|
-
|
1624
|
+
overloads,
|
1614
1625
|
annotations,
|
1615
1626
|
location,
|
1616
1627
|
comment,
|
1617
|
-
|
1628
|
+
overloading,
|
1618
1629
|
visibility
|
1619
1630
|
);
|
1620
1631
|
}
|
@@ -2257,13 +2268,11 @@ VALUE parse_module_members(parserstate *state) {
|
|
2257
2268
|
}
|
2258
2269
|
|
2259
2270
|
/*
|
2260
|
-
module_decl ::= {
|
2261
|
-
| {
|
2271
|
+
module_decl ::= {module_name} module_type_params module_members <kEND>
|
2272
|
+
| {module_name} module_name module_type_params `:` module_self_types module_members <kEND>
|
2262
2273
|
*/
|
2263
|
-
VALUE
|
2274
|
+
VALUE parse_module_decl0(parserstate *state, range keyword_range, VALUE module_name, range name_range, VALUE comment, VALUE annotations) {
|
2264
2275
|
range decl_range;
|
2265
|
-
range keyword_range;
|
2266
|
-
range name_range;
|
2267
2276
|
range end_range;
|
2268
2277
|
range type_params_range;
|
2269
2278
|
range colon_range;
|
@@ -2271,15 +2280,8 @@ VALUE parse_module_decl(parserstate *state, position comment_pos, VALUE annotati
|
|
2271
2280
|
|
2272
2281
|
parser_push_typevar_table(state, true);
|
2273
2282
|
|
2274
|
-
|
2275
|
-
comment_pos = nonnull_pos_or(comment_pos, start);
|
2276
|
-
VALUE comment = get_comment(state, comment_pos.line);
|
2277
|
-
|
2278
|
-
keyword_range = state->current_token.range;
|
2279
|
-
decl_range.start = state->current_token.range.start;
|
2283
|
+
decl_range.start = keyword_range.start;
|
2280
2284
|
|
2281
|
-
parser_advance(state);
|
2282
|
-
VALUE module_name = parse_type_name(state, CLASS_NAME, &name_range);
|
2283
2285
|
VALUE type_params = parse_type_params(state, &type_params_range, true);
|
2284
2286
|
VALUE self_types = rb_ary_new();
|
2285
2287
|
|
@@ -2322,6 +2324,46 @@ VALUE parse_module_decl(parserstate *state, position comment_pos, VALUE annotati
|
|
2322
2324
|
);
|
2323
2325
|
}
|
2324
2326
|
|
2327
|
+
/*
|
2328
|
+
module_decl ::= {`module`} module_name `=` old_module_name <kEND>
|
2329
|
+
| {`module`} module_name module_decl0 <kEND>
|
2330
|
+
|
2331
|
+
*/
|
2332
|
+
VALUE parse_module_decl(parserstate *state, position comment_pos, VALUE annotations) {
|
2333
|
+
range keyword_range = state->current_token.range;
|
2334
|
+
range module_name_range;
|
2335
|
+
|
2336
|
+
comment_pos = nonnull_pos_or(comment_pos, state->current_token.range.start);
|
2337
|
+
VALUE comment = get_comment(state, comment_pos.line);
|
2338
|
+
|
2339
|
+
parser_advance(state);
|
2340
|
+
VALUE module_name = parse_type_name(state, CLASS_NAME, &module_name_range);
|
2341
|
+
|
2342
|
+
if (state->next_token.type == pEQ) {
|
2343
|
+
range eq_range = state->next_token.range;
|
2344
|
+
parser_advance(state);
|
2345
|
+
parser_advance(state);
|
2346
|
+
|
2347
|
+
range old_name_range;
|
2348
|
+
VALUE old_name = parse_type_name(state, CLASS_NAME, &old_name_range);
|
2349
|
+
|
2350
|
+
range decl_range;
|
2351
|
+
decl_range.start = keyword_range.start;
|
2352
|
+
decl_range.end = old_name_range.end;
|
2353
|
+
|
2354
|
+
VALUE location = rbs_new_location(state->buffer, decl_range);
|
2355
|
+
rbs_loc *loc = rbs_check_location(location);
|
2356
|
+
rbs_loc_add_required_child(loc, rb_intern("keyword"), keyword_range);
|
2357
|
+
rbs_loc_add_required_child(loc, rb_intern("new_name"), module_name_range);
|
2358
|
+
rbs_loc_add_required_child(loc, rb_intern("eq"), eq_range);
|
2359
|
+
rbs_loc_add_optional_child(loc, rb_intern("old_name"), old_name_range);
|
2360
|
+
|
2361
|
+
return rbs_ast_decl_module_alias(module_name, old_name, location, comment);
|
2362
|
+
} else {
|
2363
|
+
return parse_module_decl0(state, keyword_range, module_name, module_name_range, comment, annotations);
|
2364
|
+
}
|
2365
|
+
}
|
2366
|
+
|
2325
2367
|
/*
|
2326
2368
|
class_decl_super ::= {} `<` <class_instance_name>
|
2327
2369
|
| {<>}
|
@@ -2343,7 +2385,7 @@ VALUE parse_class_decl_super(parserstate *state, range *lt_range) {
|
|
2343
2385
|
args = rb_ary_new();
|
2344
2386
|
class_instance_name(state, CLASS_NAME, &name, args, &name_range, &args_range);
|
2345
2387
|
|
2346
|
-
super_range.end =
|
2388
|
+
super_range.end = state->current_token.range.end;
|
2347
2389
|
|
2348
2390
|
location = rbs_new_location(state->buffer, super_range);
|
2349
2391
|
loc = rbs_check_location(location);
|
@@ -2358,35 +2400,25 @@ VALUE parse_class_decl_super(parserstate *state, range *lt_range) {
|
|
2358
2400
|
}
|
2359
2401
|
|
2360
2402
|
/*
|
2361
|
-
class_decl ::= {
|
2403
|
+
class_decl ::= {class_name} type_params class_decl_super class_members <`end`>
|
2362
2404
|
*/
|
2363
|
-
VALUE
|
2405
|
+
VALUE parse_class_decl0(parserstate *state, range keyword_range, VALUE name, range name_range, VALUE comment, VALUE annotations) {
|
2364
2406
|
range decl_range;
|
2365
|
-
range keyword_range;
|
2366
|
-
range name_range;
|
2367
2407
|
range end_range;
|
2368
2408
|
range type_params_range;
|
2369
2409
|
range lt_range;
|
2370
2410
|
|
2371
|
-
VALUE name;
|
2372
2411
|
VALUE type_params;
|
2373
2412
|
VALUE super;
|
2374
2413
|
VALUE members;
|
2375
|
-
VALUE comment;
|
2376
2414
|
VALUE location;
|
2377
2415
|
|
2378
2416
|
rbs_loc *loc;
|
2379
2417
|
|
2380
2418
|
parser_push_typevar_table(state, true);
|
2381
2419
|
|
2382
|
-
decl_range.start =
|
2383
|
-
keyword_range = state->current_token.range;
|
2384
|
-
|
2385
|
-
comment_pos = nonnull_pos_or(comment_pos, decl_range.start);
|
2386
|
-
comment = get_comment(state, comment_pos.line);
|
2420
|
+
decl_range.start = keyword_range.start;
|
2387
2421
|
|
2388
|
-
parser_advance(state);
|
2389
|
-
name = parse_type_name(state, CLASS_NAME, &name_range);
|
2390
2422
|
type_params = parse_type_params(state, &type_params_range, true);
|
2391
2423
|
super = parse_class_decl_super(state, <_range);
|
2392
2424
|
members = parse_module_members(state);
|
@@ -2416,6 +2448,45 @@ VALUE parse_class_decl(parserstate *state, position comment_pos, VALUE annotatio
|
|
2416
2448
|
);
|
2417
2449
|
}
|
2418
2450
|
|
2451
|
+
/*
|
2452
|
+
class_decl ::= {`class`} class_name `=` <class_name>
|
2453
|
+
| {`class`} class_name <class_decl0>
|
2454
|
+
*/
|
2455
|
+
VALUE parse_class_decl(parserstate *state, position comment_pos, VALUE annotations) {
|
2456
|
+
range keyword_range = state->current_token.range;
|
2457
|
+
range class_name_range;
|
2458
|
+
|
2459
|
+
comment_pos = nonnull_pos_or(comment_pos, state->current_token.range.start);
|
2460
|
+
VALUE comment = get_comment(state, comment_pos.line);
|
2461
|
+
|
2462
|
+
parser_advance(state);
|
2463
|
+
VALUE class_name = parse_type_name(state, CLASS_NAME, &class_name_range);
|
2464
|
+
|
2465
|
+
if (state->next_token.type == pEQ) {
|
2466
|
+
range eq_range = state->next_token.range;
|
2467
|
+
parser_advance(state);
|
2468
|
+
parser_advance(state);
|
2469
|
+
|
2470
|
+
range old_name_range;
|
2471
|
+
VALUE old_name = parse_type_name(state, CLASS_NAME, &old_name_range);
|
2472
|
+
|
2473
|
+
range decl_range;
|
2474
|
+
decl_range.start = keyword_range.start;
|
2475
|
+
decl_range.end = old_name_range.end;
|
2476
|
+
|
2477
|
+
VALUE location = rbs_new_location(state->buffer, decl_range);
|
2478
|
+
rbs_loc *loc = rbs_check_location(location);
|
2479
|
+
rbs_loc_add_required_child(loc, rb_intern("keyword"), keyword_range);
|
2480
|
+
rbs_loc_add_required_child(loc, rb_intern("new_name"), class_name_range);
|
2481
|
+
rbs_loc_add_required_child(loc, rb_intern("eq"), eq_range);
|
2482
|
+
rbs_loc_add_optional_child(loc, rb_intern("old_name"), old_name_range);
|
2483
|
+
|
2484
|
+
return rbs_ast_decl_class_alias(class_name, old_name, location, comment);
|
2485
|
+
} else {
|
2486
|
+
return parse_class_decl0(state, keyword_range, class_name, class_name_range, comment, annotations);
|
2487
|
+
}
|
2488
|
+
}
|
2489
|
+
|
2419
2490
|
/*
|
2420
2491
|
nested_decl ::= {<const_decl>}
|
2421
2492
|
| {<class_decl>}
|
@@ -2491,18 +2562,185 @@ VALUE parse_decl(parserstate *state) {
|
|
2491
2562
|
}
|
2492
2563
|
}
|
2493
2564
|
|
2565
|
+
/*
|
2566
|
+
namespace ::= {} (`::`)? (`tUIDENT` `::`)* `tUIDENT` <`::`>
|
2567
|
+
| {} <> (empty -- returns empty namespace)
|
2568
|
+
*/
|
2569
|
+
VALUE parse_namespace(parserstate *state, range *rg) {
|
2570
|
+
bool is_absolute = false;
|
2571
|
+
|
2572
|
+
if (state->next_token.type == pCOLON2) {
|
2573
|
+
rg->start = state->next_token.range.start;
|
2574
|
+
rg->end = state->next_token.range.end;
|
2575
|
+
is_absolute = true;
|
2576
|
+
|
2577
|
+
parser_advance(state);
|
2578
|
+
}
|
2579
|
+
|
2580
|
+
VALUE path = rb_ary_new();
|
2581
|
+
|
2582
|
+
while (true) {
|
2583
|
+
if (state->next_token.type == tUIDENT && state->next_token2.type == pCOLON2) {
|
2584
|
+
rb_ary_push(path, ID2SYM(INTERN_TOKEN(state, state->next_token)));
|
2585
|
+
if (null_position_p(rg->start)) {
|
2586
|
+
rg->start = state->next_token.range.start;
|
2587
|
+
}
|
2588
|
+
rg->end = state->next_token2.range.end;
|
2589
|
+
parser_advance(state);
|
2590
|
+
parser_advance(state);
|
2591
|
+
} else {
|
2592
|
+
break;
|
2593
|
+
}
|
2594
|
+
}
|
2595
|
+
|
2596
|
+
return rbs_namespace(path, is_absolute ? Qtrue : Qfalse);
|
2597
|
+
}
|
2598
|
+
|
2599
|
+
/*
|
2600
|
+
use_clauses ::= {} use_clause `,` ... `,` <use_clause>
|
2601
|
+
|
2602
|
+
use_clause ::= {} namespace <tUIDENT>
|
2603
|
+
| {} namespace tUIDENT `as` <tUIDENT>
|
2604
|
+
| {} namespace <tSTAR>
|
2605
|
+
*/
|
2606
|
+
void parse_use_clauses(parserstate *state, VALUE clauses) {
|
2607
|
+
while (true) {
|
2608
|
+
range namespace_range = NULL_RANGE;
|
2609
|
+
VALUE namespace = parse_namespace(state, &namespace_range);
|
2610
|
+
|
2611
|
+
range clause_range = namespace_range;
|
2612
|
+
|
2613
|
+
switch (state->next_token.type)
|
2614
|
+
{
|
2615
|
+
case tLIDENT:
|
2616
|
+
case tULIDENT:
|
2617
|
+
case tUIDENT: {
|
2618
|
+
parser_advance(state);
|
2619
|
+
|
2620
|
+
enum TokenType ident_type = state->current_token.type;
|
2621
|
+
|
2622
|
+
range type_name_range;
|
2623
|
+
if (null_range_p(namespace_range)) {
|
2624
|
+
type_name_range = state->current_token.range;
|
2625
|
+
} else {
|
2626
|
+
type_name_range.start = namespace_range.start;
|
2627
|
+
type_name_range.end = state->current_token.range.end;
|
2628
|
+
}
|
2629
|
+
clause_range = type_name_range;
|
2630
|
+
|
2631
|
+
VALUE type_name = rbs_type_name(namespace, ID2SYM(INTERN_TOKEN(state, state->current_token)));
|
2632
|
+
|
2633
|
+
range keyword_range = NULL_RANGE;
|
2634
|
+
range new_name_range = NULL_RANGE;
|
2635
|
+
|
2636
|
+
VALUE new_name = Qnil;
|
2637
|
+
if (state->next_token.type == kAS) {
|
2638
|
+
parser_advance(state);
|
2639
|
+
keyword_range = state->current_token.range;
|
2640
|
+
|
2641
|
+
if (ident_type == tUIDENT) parser_advance_assert(state, tUIDENT);
|
2642
|
+
if (ident_type == tLIDENT) parser_advance_assert(state, tLIDENT);
|
2643
|
+
if (ident_type == tULIDENT) parser_advance_assert(state, tULIDENT);
|
2644
|
+
|
2645
|
+
new_name = ID2SYM(INTERN_TOKEN(state, state->current_token));
|
2646
|
+
new_name_range = state->current_token.range;
|
2647
|
+
clause_range.end = new_name_range.end;
|
2648
|
+
}
|
2649
|
+
|
2650
|
+
VALUE location = rbs_new_location(state->buffer, clause_range);
|
2651
|
+
rbs_loc *loc = rbs_check_location(location);
|
2652
|
+
rbs_loc_add_required_child(loc, rb_intern("type_name"), state->current_token.range);
|
2653
|
+
if (!null_range_p(keyword_range)) {
|
2654
|
+
rbs_loc_add_optional_child(loc, rb_intern("keyword"), keyword_range);
|
2655
|
+
}
|
2656
|
+
if (!null_range_p(new_name_range)) {
|
2657
|
+
rbs_loc_add_optional_child(loc, rb_intern("new_name"), new_name_range);
|
2658
|
+
}
|
2659
|
+
|
2660
|
+
rb_ary_push(clauses, rbs_ast_directives_use_single_clause(type_name, new_name, location));
|
2661
|
+
|
2662
|
+
break;
|
2663
|
+
}
|
2664
|
+
case pSTAR:
|
2665
|
+
{
|
2666
|
+
parser_advance(state);
|
2667
|
+
|
2668
|
+
range star_range = state->current_token.range;
|
2669
|
+
clause_range.end = star_range.end;
|
2670
|
+
|
2671
|
+
VALUE location = rbs_new_location(state->buffer, clause_range);
|
2672
|
+
rbs_loc *loc = rbs_check_location(location);
|
2673
|
+
rbs_loc_add_required_child(loc, rb_intern("namespace"), namespace_range);
|
2674
|
+
rbs_loc_add_required_child(loc, rb_intern("star"), star_range);
|
2675
|
+
|
2676
|
+
rb_ary_push(clauses, rbs_ast_directives_use_wildcard_clause(namespace, location));
|
2677
|
+
|
2678
|
+
break;
|
2679
|
+
}
|
2680
|
+
default:
|
2681
|
+
raise_syntax_error(
|
2682
|
+
state,
|
2683
|
+
state->next_token,
|
2684
|
+
"use clause is expected"
|
2685
|
+
);
|
2686
|
+
}
|
2687
|
+
|
2688
|
+
if (state->next_token.type == pCOMMA) {
|
2689
|
+
parser_advance(state);
|
2690
|
+
} else {
|
2691
|
+
break;
|
2692
|
+
}
|
2693
|
+
}
|
2694
|
+
|
2695
|
+
return;
|
2696
|
+
}
|
2697
|
+
|
2698
|
+
/*
|
2699
|
+
use_directive ::= {} `use` <clauses>
|
2700
|
+
*/
|
2701
|
+
VALUE parse_use_directive(parserstate *state) {
|
2702
|
+
if (state->next_token.type == kUSE) {
|
2703
|
+
parser_advance(state);
|
2704
|
+
|
2705
|
+
range keyword_range = state->current_token.range;
|
2706
|
+
|
2707
|
+
VALUE clauses = rb_ary_new();
|
2708
|
+
parse_use_clauses(state, clauses);
|
2709
|
+
|
2710
|
+
range directive_range = keyword_range;
|
2711
|
+
directive_range.end = state->current_token.range.end;
|
2712
|
+
|
2713
|
+
VALUE location = rbs_new_location(state->buffer, directive_range);
|
2714
|
+
rbs_loc *loc = rbs_check_location(location);
|
2715
|
+
rbs_loc_add_required_child(loc, rb_intern("keyword"), keyword_range);
|
2716
|
+
|
2717
|
+
return rbs_ast_directives_use(clauses, location);
|
2718
|
+
} else {
|
2719
|
+
return Qnil;
|
2720
|
+
}
|
2721
|
+
}
|
2722
|
+
|
2494
2723
|
VALUE parse_signature(parserstate *state) {
|
2724
|
+
VALUE dirs = rb_ary_new();
|
2495
2725
|
VALUE decls = rb_ary_new();
|
2496
2726
|
|
2497
2727
|
while (state->next_token.type != pEOF) {
|
2498
|
-
|
2728
|
+
if (state->next_token.type == kUSE) {
|
2729
|
+
VALUE use = parse_use_directive(state);
|
2730
|
+
rb_ary_push(dirs, use);
|
2731
|
+
} else {
|
2732
|
+
rb_ary_push(decls, parse_decl(state));
|
2733
|
+
}
|
2499
2734
|
}
|
2500
2735
|
|
2501
|
-
|
2736
|
+
VALUE ret = rb_ary_new();
|
2737
|
+
rb_ary_push(ret, dirs);
|
2738
|
+
rb_ary_push(ret, decls);
|
2739
|
+
return ret;
|
2502
2740
|
}
|
2503
2741
|
|
2504
2742
|
static VALUE
|
2505
|
-
rbsparser_parse_type(VALUE self, VALUE buffer, VALUE start_pos, VALUE end_pos, VALUE variables
|
2743
|
+
rbsparser_parse_type(VALUE self, VALUE buffer, VALUE start_pos, VALUE end_pos, VALUE variables)
|
2506
2744
|
{
|
2507
2745
|
parserstate *parser = alloc_parser(buffer, FIX2INT(start_pos), FIX2INT(end_pos), variables);
|
2508
2746
|
|
@@ -2512,17 +2750,13 @@ rbsparser_parse_type(VALUE self, VALUE buffer, VALUE start_pos, VALUE end_pos, V
|
|
2512
2750
|
|
2513
2751
|
VALUE type = parse_type(parser);
|
2514
2752
|
|
2515
|
-
if (RTEST(requires_eof)) {
|
2516
|
-
parser_advance_assert(parser, pEOF);
|
2517
|
-
}
|
2518
|
-
|
2519
2753
|
free_parser(parser);
|
2520
2754
|
|
2521
2755
|
return type;
|
2522
2756
|
}
|
2523
2757
|
|
2524
2758
|
static VALUE
|
2525
|
-
rbsparser_parse_method_type(VALUE self, VALUE buffer, VALUE start_pos, VALUE end_pos, VALUE variables
|
2759
|
+
rbsparser_parse_method_type(VALUE self, VALUE buffer, VALUE start_pos, VALUE end_pos, VALUE variables)
|
2526
2760
|
{
|
2527
2761
|
parserstate *parser = alloc_parser(buffer, FIX2INT(start_pos), FIX2INT(end_pos), variables);
|
2528
2762
|
|
@@ -2532,10 +2766,6 @@ rbsparser_parse_method_type(VALUE self, VALUE buffer, VALUE start_pos, VALUE end
|
|
2532
2766
|
|
2533
2767
|
VALUE method_type = parse_method_type(parser);
|
2534
2768
|
|
2535
|
-
if (RTEST(requires_eof)) {
|
2536
|
-
parser_advance_assert(parser, pEOF);
|
2537
|
-
}
|
2538
|
-
|
2539
2769
|
free_parser(parser);
|
2540
2770
|
|
2541
2771
|
return method_type;
|
@@ -2545,15 +2775,15 @@ static VALUE
|
|
2545
2775
|
rbsparser_parse_signature(VALUE self, VALUE buffer, VALUE end_pos)
|
2546
2776
|
{
|
2547
2777
|
parserstate *parser = alloc_parser(buffer, 0, FIX2INT(end_pos), Qnil);
|
2548
|
-
VALUE
|
2778
|
+
VALUE pair = parse_signature(parser);
|
2549
2779
|
free_parser(parser);
|
2550
2780
|
|
2551
|
-
return
|
2781
|
+
return pair;
|
2552
2782
|
}
|
2553
2783
|
|
2554
2784
|
void rbs__init_parser(void) {
|
2555
2785
|
RBS_Parser = rb_define_class_under(RBS, "Parser", rb_cObject);
|
2556
|
-
rb_define_singleton_method(RBS_Parser, "_parse_type", rbsparser_parse_type,
|
2557
|
-
rb_define_singleton_method(RBS_Parser, "_parse_method_type", rbsparser_parse_method_type,
|
2786
|
+
rb_define_singleton_method(RBS_Parser, "_parse_type", rbsparser_parse_type, 4);
|
2787
|
+
rb_define_singleton_method(RBS_Parser, "_parse_method_type", rbsparser_parse_method_type, 4);
|
2558
2788
|
rb_define_singleton_method(RBS_Parser, "_parse_signature", rbsparser_parse_signature, 2);
|
2559
2789
|
}
|
@@ -340,7 +340,7 @@ VALUE rbs_ast_decl_global(VALUE name, VALUE type, VALUE location, VALUE comment)
|
|
340
340
|
);
|
341
341
|
}
|
342
342
|
|
343
|
-
VALUE
|
343
|
+
VALUE rbs_ast_decl_type_alias(VALUE name, VALUE type_params, VALUE type, VALUE annotations, VALUE location, VALUE comment) {
|
344
344
|
VALUE args = rb_hash_new();
|
345
345
|
rb_hash_aset(args, ID2SYM(rb_intern("name")), name);
|
346
346
|
rb_hash_aset(args, ID2SYM(rb_intern("type_params")), type_params);
|
@@ -350,7 +350,7 @@ VALUE rbs_ast_decl_alias(VALUE name, VALUE type_params, VALUE type, VALUE annota
|
|
350
350
|
rb_hash_aset(args, ID2SYM(rb_intern("comment")), comment);
|
351
351
|
|
352
352
|
return CLASS_NEW_INSTANCE(
|
353
|
-
|
353
|
+
RBS_AST_Declarations_TypeAlias,
|
354
354
|
1,
|
355
355
|
&args
|
356
356
|
);
|
@@ -402,15 +402,55 @@ VALUE rbs_ast_decl_module(VALUE name, VALUE type_params, VALUE self_types, VALUE
|
|
402
402
|
);
|
403
403
|
}
|
404
404
|
|
405
|
-
VALUE
|
405
|
+
VALUE rbs_ast_decl_class_alias(VALUE new_name, VALUE old_name, VALUE location, VALUE comment) {
|
406
|
+
VALUE args = rb_hash_new();
|
407
|
+
rb_hash_aset(args, ID2SYM(rb_intern("new_name")), new_name);
|
408
|
+
rb_hash_aset(args, ID2SYM(rb_intern("old_name")), old_name);
|
409
|
+
rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
|
410
|
+
rb_hash_aset(args, ID2SYM(rb_intern("comment")), comment);
|
411
|
+
|
412
|
+
return CLASS_NEW_INSTANCE(
|
413
|
+
RBS_AST_Declarations_ClassAlias,
|
414
|
+
1,
|
415
|
+
&args
|
416
|
+
);
|
417
|
+
}
|
418
|
+
|
419
|
+
VALUE rbs_ast_decl_module_alias(VALUE new_name, VALUE old_name, VALUE location, VALUE comment) {
|
420
|
+
VALUE args = rb_hash_new();
|
421
|
+
rb_hash_aset(args, ID2SYM(rb_intern("new_name")), new_name);
|
422
|
+
rb_hash_aset(args, ID2SYM(rb_intern("old_name")), old_name);
|
423
|
+
rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
|
424
|
+
rb_hash_aset(args, ID2SYM(rb_intern("comment")), comment);
|
425
|
+
|
426
|
+
return CLASS_NEW_INSTANCE(
|
427
|
+
RBS_AST_Declarations_ModuleAlias,
|
428
|
+
1,
|
429
|
+
&args
|
430
|
+
);
|
431
|
+
}
|
432
|
+
|
433
|
+
VALUE rbs_ast_members_method_definition_overload(VALUE annotations, VALUE method_type) {
|
434
|
+
VALUE args = rb_hash_new();
|
435
|
+
rb_hash_aset(args, ID2SYM(rb_intern("annotations")), annotations);
|
436
|
+
rb_hash_aset(args, ID2SYM(rb_intern("method_type")), method_type);
|
437
|
+
|
438
|
+
return CLASS_NEW_INSTANCE(
|
439
|
+
RBS_AST_Members_MethodDefinition_Overload,
|
440
|
+
1,
|
441
|
+
&args
|
442
|
+
);
|
443
|
+
}
|
444
|
+
|
445
|
+
VALUE rbs_ast_members_method_definition(VALUE name, VALUE kind, VALUE overloads, VALUE annotations, VALUE location, VALUE comment, VALUE overloading, VALUE visibility) {
|
406
446
|
VALUE args = rb_hash_new();
|
407
447
|
rb_hash_aset(args, ID2SYM(rb_intern("name")), name);
|
408
448
|
rb_hash_aset(args, ID2SYM(rb_intern("kind")), kind);
|
409
|
-
rb_hash_aset(args, ID2SYM(rb_intern("
|
449
|
+
rb_hash_aset(args, ID2SYM(rb_intern("overloads")), overloads);
|
410
450
|
rb_hash_aset(args, ID2SYM(rb_intern("annotations")), annotations);
|
411
451
|
rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
|
412
452
|
rb_hash_aset(args, ID2SYM(rb_intern("comment")), comment);
|
413
|
-
rb_hash_aset(args, ID2SYM(rb_intern("
|
453
|
+
rb_hash_aset(args, ID2SYM(rb_intern("overloading")), overloading);
|
414
454
|
rb_hash_aset(args, ID2SYM(rb_intern("visibility")), visibility);
|
415
455
|
|
416
456
|
return CLASS_NEW_INSTANCE(
|
@@ -523,3 +563,29 @@ VALUE rbs_ast_decl_class(VALUE name, VALUE type_params, VALUE super_class, VALUE
|
|
523
563
|
&kwargs
|
524
564
|
);
|
525
565
|
}
|
566
|
+
|
567
|
+
VALUE rbs_ast_directives_use(VALUE clauses, VALUE location) {
|
568
|
+
VALUE kwargs = rb_hash_new();
|
569
|
+
rb_hash_aset(kwargs, ID2SYM(rb_intern("clauses")), clauses);
|
570
|
+
rb_hash_aset(kwargs, ID2SYM(rb_intern("location")), location);
|
571
|
+
|
572
|
+
return CLASS_NEW_INSTANCE(RBS_AST_Directives_Use, 1, &kwargs);
|
573
|
+
}
|
574
|
+
|
575
|
+
VALUE rbs_ast_directives_use_single_clause(VALUE type_name, VALUE new_name, VALUE location) {
|
576
|
+
VALUE kwargs = rb_hash_new();
|
577
|
+
rb_hash_aset(kwargs, ID2SYM(rb_intern("type_name")), type_name);
|
578
|
+
rb_hash_aset(kwargs, ID2SYM(rb_intern("new_name")), new_name);
|
579
|
+
rb_hash_aset(kwargs, ID2SYM(rb_intern("location")), location);
|
580
|
+
|
581
|
+
return CLASS_NEW_INSTANCE(RBS_AST_Directives_Use_SingleClause, 1, &kwargs);
|
582
|
+
}
|
583
|
+
|
584
|
+
VALUE rbs_ast_directives_use_wildcard_clause(VALUE namespace, VALUE location) {
|
585
|
+
VALUE kwargs = rb_hash_new();
|
586
|
+
rb_hash_aset(kwargs, ID2SYM(rb_intern("namespace")), namespace);
|
587
|
+
rb_hash_aset(kwargs, ID2SYM(rb_intern("location")), location);
|
588
|
+
|
589
|
+
return CLASS_NEW_INSTANCE(RBS_AST_Directives_Use_WildcardClause, 1, &kwargs);
|
590
|
+
}
|
591
|
+
|