rbs 3.0.0.dev.1 → 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.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +0 -3
  3. data/CHANGELOG.md +28 -0
  4. data/Gemfile.lock +2 -2
  5. data/README.md +1 -0
  6. data/Rakefile +75 -1
  7. data/core/array.rbs +1 -1
  8. data/core/builtin.rbs +1 -1
  9. data/core/hash.rbs +1 -1
  10. data/core/module.rbs +1 -1
  11. data/ext/rbs_extension/constants.c +16 -2
  12. data/ext/rbs_extension/constants.h +8 -1
  13. data/ext/rbs_extension/extconf.rb +1 -1
  14. data/ext/rbs_extension/lexer.c +834 -777
  15. data/ext/rbs_extension/lexer.h +3 -1
  16. data/ext/rbs_extension/lexer.re +3 -1
  17. data/ext/rbs_extension/lexstate.c +4 -2
  18. data/ext/rbs_extension/parser.c +264 -44
  19. data/ext/rbs_extension/ruby_objs.c +56 -2
  20. data/ext/rbs_extension/ruby_objs.h +7 -1
  21. data/lib/rbs/annotate/rdoc_annotator.rb +1 -1
  22. data/lib/rbs/ast/declarations.rb +49 -2
  23. data/lib/rbs/ast/directives.rb +39 -0
  24. data/lib/rbs/cli.rb +32 -18
  25. data/lib/rbs/collection/config/lockfile_generator.rb +25 -20
  26. data/lib/rbs/collection/config.rb +2 -2
  27. data/lib/rbs/collection/sources/git.rb +1 -1
  28. data/lib/rbs/definition_builder/ancestor_builder.rb +24 -8
  29. data/lib/rbs/definition_builder.rb +8 -8
  30. data/lib/rbs/environment/use_map.rb +77 -0
  31. data/lib/rbs/environment.rb +352 -83
  32. data/lib/rbs/environment_loader.rb +9 -7
  33. data/lib/rbs/environment_walker.rb +1 -1
  34. data/lib/rbs/errors.rb +34 -37
  35. data/lib/rbs/locator.rb +1 -1
  36. data/lib/rbs/parser_aux.rb +8 -6
  37. data/lib/rbs/resolver/constant_resolver.rb +23 -7
  38. data/lib/rbs/resolver/type_name_resolver.rb +2 -1
  39. data/lib/rbs/sorter.rb +3 -3
  40. data/lib/rbs/test/setup.rb +1 -1
  41. data/lib/rbs/type_alias_dependency.rb +1 -1
  42. data/lib/rbs/type_alias_regularity.rb +3 -3
  43. data/lib/rbs/validator.rb +23 -2
  44. data/lib/rbs/variance_calculator.rb +2 -2
  45. data/lib/rbs/version.rb +1 -1
  46. data/lib/rbs/writer.rb +28 -2
  47. data/lib/rbs.rb +2 -2
  48. data/lib/rdoc_plugin/parser.rb +2 -2
  49. data/rbs.gemspec +1 -1
  50. data/sig/ancestor_graph.rbs +22 -2
  51. data/sig/collection/config/lockfile_generator.rbs +8 -10
  52. data/sig/collection/config.rbs +1 -1
  53. data/sig/collection/sources.rbs +12 -6
  54. data/sig/constant.rbs +1 -1
  55. data/sig/declarations.rbs +36 -3
  56. data/sig/definition.rbs +1 -1
  57. data/sig/definition_builder.rbs +0 -1
  58. data/sig/directives.rbs +61 -0
  59. data/sig/environment.rbs +150 -28
  60. data/sig/environment_loader.rbs +1 -1
  61. data/sig/errors.rbs +22 -1
  62. data/sig/parser.rbs +8 -15
  63. data/sig/resolver/constant_resolver.rbs +1 -2
  64. data/sig/shims/bundler.rbs +18 -0
  65. data/sig/shims/rubygems.rbs +6 -0
  66. data/sig/use_map.rbs +35 -0
  67. data/sig/validator.rbs +12 -5
  68. data/sig/writer.rbs +4 -2
  69. metadata +7 -9
  70. data/lib/rbs/constant_table.rb +0 -167
  71. data/lib/rbs/type_name_resolver.rb +0 -67
  72. data/sig/constant_table.rbs +0 -30
  73. data/sig/type_name_resolver.rbs +0 -26
  74. data/steep/Gemfile +0 -3
  75. data/steep/Gemfile.lock +0 -61
@@ -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 skip(lexstate *state);
155
+ void rbs_skip(lexstate *state);
154
156
 
155
157
  /**
156
158
  * Skip n characters.
@@ -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 = "skip(state);";
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 skip(lexstate *state) {
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
- skip(state);
148
+ rbs_skip(state);
147
149
  }
148
150
  }
149
151
 
@@ -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 rbs_ast_decl_alias(
1281
+ return rbs_ast_decl_type_alias(
1281
1282
  typename,
1282
1283
  type_params,
1283
1284
  type,
@@ -2267,13 +2268,11 @@ VALUE parse_module_members(parserstate *state) {
2267
2268
  }
2268
2269
 
2269
2270
  /*
2270
- module_decl ::= {`module`} module_name module_type_params module_members <kEND>
2271
- | {`module`} module_name module_type_params `:` module_self_types module_members <kEND>
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>
2272
2273
  */
2273
- VALUE parse_module_decl(parserstate *state, position comment_pos, VALUE annotations) {
2274
+ VALUE parse_module_decl0(parserstate *state, range keyword_range, VALUE module_name, range name_range, VALUE comment, VALUE annotations) {
2274
2275
  range decl_range;
2275
- range keyword_range;
2276
- range name_range;
2277
2276
  range end_range;
2278
2277
  range type_params_range;
2279
2278
  range colon_range;
@@ -2281,15 +2280,8 @@ VALUE parse_module_decl(parserstate *state, position comment_pos, VALUE annotati
2281
2280
 
2282
2281
  parser_push_typevar_table(state, true);
2283
2282
 
2284
- position start = state->current_token.range.start;
2285
- comment_pos = nonnull_pos_or(comment_pos, start);
2286
- VALUE comment = get_comment(state, comment_pos.line);
2287
-
2288
- keyword_range = state->current_token.range;
2289
- decl_range.start = state->current_token.range.start;
2283
+ decl_range.start = keyword_range.start;
2290
2284
 
2291
- parser_advance(state);
2292
- VALUE module_name = parse_type_name(state, CLASS_NAME, &name_range);
2293
2285
  VALUE type_params = parse_type_params(state, &type_params_range, true);
2294
2286
  VALUE self_types = rb_ary_new();
2295
2287
 
@@ -2332,6 +2324,46 @@ VALUE parse_module_decl(parserstate *state, position comment_pos, VALUE annotati
2332
2324
  );
2333
2325
  }
2334
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
+
2335
2367
  /*
2336
2368
  class_decl_super ::= {} `<` <class_instance_name>
2337
2369
  | {<>}
@@ -2368,35 +2400,25 @@ VALUE parse_class_decl_super(parserstate *state, range *lt_range) {
2368
2400
  }
2369
2401
 
2370
2402
  /*
2371
- class_decl ::= {`class`} class_name type_params class_decl_super class_members <`end`>
2403
+ class_decl ::= {class_name} type_params class_decl_super class_members <`end`>
2372
2404
  */
2373
- VALUE parse_class_decl(parserstate *state, position comment_pos, VALUE annotations) {
2405
+ VALUE parse_class_decl0(parserstate *state, range keyword_range, VALUE name, range name_range, VALUE comment, VALUE annotations) {
2374
2406
  range decl_range;
2375
- range keyword_range;
2376
- range name_range;
2377
2407
  range end_range;
2378
2408
  range type_params_range;
2379
2409
  range lt_range;
2380
2410
 
2381
- VALUE name;
2382
2411
  VALUE type_params;
2383
2412
  VALUE super;
2384
2413
  VALUE members;
2385
- VALUE comment;
2386
2414
  VALUE location;
2387
2415
 
2388
2416
  rbs_loc *loc;
2389
2417
 
2390
2418
  parser_push_typevar_table(state, true);
2391
2419
 
2392
- decl_range.start = state->current_token.range.start;
2393
- keyword_range = state->current_token.range;
2394
-
2395
- comment_pos = nonnull_pos_or(comment_pos, decl_range.start);
2396
- comment = get_comment(state, comment_pos.line);
2420
+ decl_range.start = keyword_range.start;
2397
2421
 
2398
- parser_advance(state);
2399
- name = parse_type_name(state, CLASS_NAME, &name_range);
2400
2422
  type_params = parse_type_params(state, &type_params_range, true);
2401
2423
  super = parse_class_decl_super(state, &lt_range);
2402
2424
  members = parse_module_members(state);
@@ -2426,6 +2448,45 @@ VALUE parse_class_decl(parserstate *state, position comment_pos, VALUE annotatio
2426
2448
  );
2427
2449
  }
2428
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
+
2429
2490
  /*
2430
2491
  nested_decl ::= {<const_decl>}
2431
2492
  | {<class_decl>}
@@ -2501,18 +2562,185 @@ VALUE parse_decl(parserstate *state) {
2501
2562
  }
2502
2563
  }
2503
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
+
2504
2723
  VALUE parse_signature(parserstate *state) {
2724
+ VALUE dirs = rb_ary_new();
2505
2725
  VALUE decls = rb_ary_new();
2506
2726
 
2507
2727
  while (state->next_token.type != pEOF) {
2508
- rb_ary_push(decls, parse_decl(state));
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
+ }
2509
2734
  }
2510
2735
 
2511
- return decls;
2736
+ VALUE ret = rb_ary_new();
2737
+ rb_ary_push(ret, dirs);
2738
+ rb_ary_push(ret, decls);
2739
+ return ret;
2512
2740
  }
2513
2741
 
2514
2742
  static VALUE
2515
- rbsparser_parse_type(VALUE self, VALUE buffer, VALUE start_pos, VALUE end_pos, VALUE variables, VALUE requires_eof)
2743
+ rbsparser_parse_type(VALUE self, VALUE buffer, VALUE start_pos, VALUE end_pos, VALUE variables)
2516
2744
  {
2517
2745
  parserstate *parser = alloc_parser(buffer, FIX2INT(start_pos), FIX2INT(end_pos), variables);
2518
2746
 
@@ -2522,17 +2750,13 @@ rbsparser_parse_type(VALUE self, VALUE buffer, VALUE start_pos, VALUE end_pos, V
2522
2750
 
2523
2751
  VALUE type = parse_type(parser);
2524
2752
 
2525
- if (RTEST(requires_eof)) {
2526
- parser_advance_assert(parser, pEOF);
2527
- }
2528
-
2529
2753
  free_parser(parser);
2530
2754
 
2531
2755
  return type;
2532
2756
  }
2533
2757
 
2534
2758
  static VALUE
2535
- rbsparser_parse_method_type(VALUE self, VALUE buffer, VALUE start_pos, VALUE end_pos, VALUE variables, VALUE requires_eof)
2759
+ rbsparser_parse_method_type(VALUE self, VALUE buffer, VALUE start_pos, VALUE end_pos, VALUE variables)
2536
2760
  {
2537
2761
  parserstate *parser = alloc_parser(buffer, FIX2INT(start_pos), FIX2INT(end_pos), variables);
2538
2762
 
@@ -2542,10 +2766,6 @@ rbsparser_parse_method_type(VALUE self, VALUE buffer, VALUE start_pos, VALUE end
2542
2766
 
2543
2767
  VALUE method_type = parse_method_type(parser);
2544
2768
 
2545
- if (RTEST(requires_eof)) {
2546
- parser_advance_assert(parser, pEOF);
2547
- }
2548
-
2549
2769
  free_parser(parser);
2550
2770
 
2551
2771
  return method_type;
@@ -2555,15 +2775,15 @@ static VALUE
2555
2775
  rbsparser_parse_signature(VALUE self, VALUE buffer, VALUE end_pos)
2556
2776
  {
2557
2777
  parserstate *parser = alloc_parser(buffer, 0, FIX2INT(end_pos), Qnil);
2558
- VALUE signature = parse_signature(parser);
2778
+ VALUE pair = parse_signature(parser);
2559
2779
  free_parser(parser);
2560
2780
 
2561
- return signature;
2781
+ return pair;
2562
2782
  }
2563
2783
 
2564
2784
  void rbs__init_parser(void) {
2565
2785
  RBS_Parser = rb_define_class_under(RBS, "Parser", rb_cObject);
2566
- rb_define_singleton_method(RBS_Parser, "_parse_type", rbsparser_parse_type, 5);
2567
- rb_define_singleton_method(RBS_Parser, "_parse_method_type", rbsparser_parse_method_type, 5);
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);
2568
2788
  rb_define_singleton_method(RBS_Parser, "_parse_signature", rbsparser_parse_signature, 2);
2569
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 rbs_ast_decl_alias(VALUE name, VALUE type_params, VALUE type, VALUE annotations, VALUE location, VALUE comment) {
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
- RBS_AST_Declarations_Alias,
353
+ RBS_AST_Declarations_TypeAlias,
354
354
  1,
355
355
  &args
356
356
  );
@@ -402,6 +402,34 @@ VALUE rbs_ast_decl_module(VALUE name, VALUE type_params, VALUE self_types, VALUE
402
402
  );
403
403
  }
404
404
 
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
+
405
433
  VALUE rbs_ast_members_method_definition_overload(VALUE annotations, VALUE method_type) {
406
434
  VALUE args = rb_hash_new();
407
435
  rb_hash_aset(args, ID2SYM(rb_intern("annotations")), annotations);
@@ -535,3 +563,29 @@ VALUE rbs_ast_decl_class(VALUE name, VALUE type_params, VALUE super_class, VALUE
535
563
  &kwargs
536
564
  );
537
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
+
@@ -7,7 +7,7 @@ VALUE rbs_alias(VALUE typename, VALUE args, VALUE location);
7
7
  VALUE rbs_ast_annotation(VALUE string, VALUE location);
8
8
  VALUE rbs_ast_comment(VALUE string, VALUE location);
9
9
  VALUE rbs_ast_type_param(VALUE name, VALUE variance, bool unchecked, VALUE upper_bound, VALUE location);
10
- VALUE rbs_ast_decl_alias(VALUE name, VALUE type_params, VALUE type, VALUE annotations, VALUE location, VALUE comment);
10
+ VALUE rbs_ast_decl_type_alias(VALUE name, VALUE type_params, VALUE type, VALUE annotations, VALUE location, VALUE comment);
11
11
  VALUE rbs_ast_decl_class_super(VALUE name, VALUE args, VALUE location);
12
12
  VALUE rbs_ast_decl_class(VALUE name, VALUE type_params, VALUE super_class, VALUE members, VALUE annotations, VALUE location, VALUE comment);
13
13
  VALUE rbs_ast_decl_constant(VALUE name, VALUE type, VALUE location, VALUE comment);
@@ -15,6 +15,8 @@ VALUE rbs_ast_decl_global(VALUE name, VALUE type, VALUE location, VALUE comment)
15
15
  VALUE rbs_ast_decl_interface(VALUE name, VALUE type_params, VALUE members, VALUE annotations, VALUE location, VALUE comment);
16
16
  VALUE rbs_ast_decl_module_self(VALUE name, VALUE args, VALUE location);
17
17
  VALUE rbs_ast_decl_module(VALUE name, VALUE type_params, VALUE self_types, VALUE members, VALUE annotations, VALUE location, VALUE comment);
18
+ VALUE rbs_ast_decl_module_alias(VALUE new_name, VALUE old_name, VALUE location, VALUE comment);
19
+ VALUE rbs_ast_decl_class_alias(VALUE new_name, VALUE old_name, VALUE location, VALUE comment);
18
20
  VALUE rbs_ast_members_alias(VALUE new_name, VALUE old_name, VALUE kind, VALUE annotations, VALUE location, VALUE comment);
19
21
  VALUE rbs_ast_members_attribute(VALUE klass, VALUE name, VALUE type, VALUE ivar_name, VALUE kind, VALUE annotations, VALUE location, VALUE comment, VALUE visibility);
20
22
  VALUE rbs_ast_members_method_definition(VALUE name, VALUE kind, VALUE overloads, VALUE annotations, VALUE location, VALUE comment, VALUE overloading, VALUE visibility);
@@ -41,4 +43,8 @@ VALUE rbs_type_name(VALUE namespace, VALUE name);
41
43
  VALUE rbs_union(VALUE types, VALUE location);
42
44
  VALUE rbs_variable(VALUE name, VALUE location);
43
45
 
46
+ VALUE rbs_ast_directives_use(VALUE clauses, VALUE location);
47
+ VALUE rbs_ast_directives_use_single_clause(VALUE type_name, VALUE new_name, VALUE location);
48
+ VALUE rbs_ast_directives_use_wildcard_clause(VALUE namespace, VALUE location);
49
+
44
50
  #endif
@@ -16,7 +16,7 @@ module RBS
16
16
  def annotate_file(path, preserve:)
17
17
  content = path.read()
18
18
 
19
- decls = Parser.parse_signature(content)
19
+ _, _, decls = Parser.parse_signature(content)
20
20
 
21
21
  annotate_decls(decls)
22
22
 
@@ -265,7 +265,7 @@ module RBS
265
265
  end
266
266
  end
267
267
 
268
- class Alias < Base
268
+ class TypeAlias < Base
269
269
  attr_reader :name
270
270
  attr_reader :type_params
271
271
  attr_reader :type
@@ -283,7 +283,7 @@ module RBS
283
283
  end
284
284
 
285
285
  def ==(other)
286
- other.is_a?(Alias) &&
286
+ other.is_a?(TypeAlias) &&
287
287
  other.name == name &&
288
288
  other.type_params == type_params &&
289
289
  other.type == type
@@ -379,6 +379,53 @@ module RBS
379
379
  }.to_json(state)
380
380
  end
381
381
  end
382
+
383
+ class AliasDecl < Base
384
+ attr_reader :new_name, :old_name, :location, :comment
385
+
386
+ def initialize(new_name:, old_name:, location:, comment:)
387
+ @new_name = new_name
388
+ @old_name = old_name
389
+ @location = location
390
+ @comment = comment
391
+ end
392
+
393
+ def ==(other)
394
+ other.is_a?(self.class) &&
395
+ other.new_name == new_name &&
396
+ other.old_name == old_name
397
+ end
398
+
399
+ alias eql? ==
400
+
401
+ def hash
402
+ self.class.hash ^ new_name.hash ^ old_name.hash
403
+ end
404
+ end
405
+
406
+ class ClassAlias < AliasDecl
407
+ def to_json(state = _ = nil)
408
+ {
409
+ declaration: :class_alias,
410
+ new_name: new_name,
411
+ old_name: old_name,
412
+ location: location,
413
+ comment: comment
414
+ }.to_json(state)
415
+ end
416
+ end
417
+
418
+ class ModuleAlias < AliasDecl
419
+ def to_json(state = _ = nil)
420
+ {
421
+ declaration: :module_alias,
422
+ new_name: new_name,
423
+ old_name: old_name,
424
+ location: location,
425
+ comment: comment
426
+ }.to_json(state)
427
+ end
428
+ end
382
429
  end
383
430
  end
384
431
  end