rbs 3.7.0 → 3.8.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +3 -3
  3. data/.github/workflows/ruby.yml +7 -7
  4. data/CHANGELOG.md +52 -0
  5. data/core/array.rbs +1743 -1580
  6. data/core/basic_object.rbs +38 -35
  7. data/core/comparable.rbs +1 -1
  8. data/core/complex.rbs +165 -93
  9. data/core/data.rbs +1 -1
  10. data/core/dir.rbs +1 -17
  11. data/core/encoding.rbs +12 -6
  12. data/core/enumerable.rbs +270 -266
  13. data/core/enumerator.rbs +0 -2
  14. data/core/env.rbs +1 -1
  15. data/core/errno.rbs +33 -16
  16. data/core/errors.rbs +2 -2
  17. data/core/exception.rbs +236 -170
  18. data/core/fiber.rbs +3 -2
  19. data/core/file.rbs +32 -74
  20. data/core/float.rbs +125 -72
  21. data/core/gc.rbs +138 -40
  22. data/core/hash.rbs +120 -141
  23. data/core/integer.rbs +79 -50
  24. data/core/io/buffer.rbs +49 -43
  25. data/core/io.rbs +97 -144
  26. data/core/kernel.rbs +290 -200
  27. data/core/match_data.rbs +76 -2
  28. data/core/math.rbs +0 -36
  29. data/core/module.rbs +28 -23
  30. data/core/nil_class.rbs +0 -3
  31. data/core/numeric.rbs +100 -103
  32. data/core/object.rbs +0 -4
  33. data/core/object_space/weak_key_map.rbs +3 -4
  34. data/core/object_space.rbs +3 -3
  35. data/core/proc.rbs +0 -2
  36. data/core/process.rbs +109 -57
  37. data/core/ractor.rbs +37 -4
  38. data/core/range.rbs +114 -87
  39. data/core/rational.rbs +0 -2
  40. data/core/rbs/unnamed/argf.rbs +234 -33
  41. data/core/rbs/unnamed/env_class.rbs +35 -53
  42. data/core/rbs/unnamed/random.rbs +1 -2
  43. data/core/regexp.rbs +4 -52
  44. data/core/ruby_vm.rbs +88 -9
  45. data/core/rubygems/config_file.rbs +3 -0
  46. data/core/rubygems/errors.rbs +0 -5
  47. data/core/rubygems/platform.rbs +0 -9
  48. data/core/rubygems/rubygems.rbs +0 -5
  49. data/core/rubygems/version.rbs +6 -6
  50. data/core/set.rbs +3 -15
  51. data/core/string.rbs +130 -136
  52. data/core/struct.rbs +6 -18
  53. data/core/symbol.rbs +14 -21
  54. data/core/thread.rbs +32 -35
  55. data/core/time.rbs +127 -50
  56. data/core/trace_point.rbs +16 -0
  57. data/core/true_class.rbs +0 -1
  58. data/core/warning.rbs +9 -2
  59. data/docs/architecture.md +1 -1
  60. data/docs/syntax.md +1 -1
  61. data/ext/rbs_extension/location.c +29 -19
  62. data/ext/rbs_extension/parser.c +267 -292
  63. data/ext/rbs_extension/parserstate.c +56 -22
  64. data/lib/rbs/annotate/annotations.rb +3 -3
  65. data/lib/rbs/annotate/rdoc_source.rb +2 -2
  66. data/lib/rbs/cli/diff.rb +3 -3
  67. data/lib/rbs/cli/validate.rb +1 -1
  68. data/lib/rbs/cli.rb +13 -13
  69. data/lib/rbs/collection/config.rb +3 -1
  70. data/lib/rbs/definition_builder/ancestor_builder.rb +3 -3
  71. data/lib/rbs/environment_loader.rb +1 -1
  72. data/lib/rbs/namespace.rb +1 -0
  73. data/lib/rbs/parser_aux.rb +2 -2
  74. data/lib/rbs/prototype/rb.rb +11 -8
  75. data/lib/rbs/prototype/rbi.rb +9 -5
  76. data/lib/rbs/prototype/runtime/value_object_generator.rb +7 -5
  77. data/lib/rbs/prototype/runtime.rb +4 -5
  78. data/lib/rbs/type_name.rb +14 -9
  79. data/lib/rbs/unit_test/type_assertions.rb +2 -2
  80. data/lib/rbs/validator.rb +3 -1
  81. data/lib/rbs/version.rb +1 -1
  82. data/lib/rdoc_plugin/parser.rb +2 -2
  83. data/rbs.gemspec +4 -0
  84. data/sig/ancestor_graph.rbs +4 -4
  85. data/sig/namespace.rbs +2 -3
  86. data/sig/resolver/constant_resolver.rbs +2 -2
  87. data/sig/resolver/context.rbs +1 -1
  88. data/sig/type_alias_regularity.rbs +5 -5
  89. data/sig/typename.rbs +8 -5
  90. data/sig/use_map.rbs +1 -1
  91. data/sig/validator.rbs +2 -2
  92. data/stdlib/base64/0/base64.rbs +0 -9
  93. data/stdlib/benchmark/0/benchmark.rbs +11 -2
  94. data/stdlib/bigdecimal/0/big_decimal.rbs +26 -182
  95. data/stdlib/cgi/0/core.rbs +47 -0
  96. data/stdlib/coverage/0/coverage.rbs +0 -3
  97. data/stdlib/csv/0/csv.rbs +18 -58
  98. data/stdlib/date/0/date.rbs +4 -19
  99. data/stdlib/did_you_mean/0/did_you_mean.rbs +0 -5
  100. data/stdlib/digest/0/digest.rbs +25 -2
  101. data/stdlib/erb/0/erb.rbs +0 -1
  102. data/stdlib/etc/0/etc.rbs +51 -34
  103. data/stdlib/fileutils/0/fileutils.rbs +3 -44
  104. data/stdlib/io-console/0/io-console.rbs +69 -15
  105. data/stdlib/ipaddr/0/ipaddr.rbs +8 -4
  106. data/stdlib/json/0/json.rbs +56 -71
  107. data/stdlib/logger/0/log_device.rbs +1 -1
  108. data/stdlib/logger/0/logger.rbs +3 -18
  109. data/stdlib/net-http/0/net-http.rbs +19 -77
  110. data/stdlib/nkf/0/nkf.rbs +30 -0
  111. data/stdlib/objspace/0/objspace.rbs +1 -2
  112. data/stdlib/observable/0/observable.rbs +1 -1
  113. data/stdlib/open-uri/0/open-uri.rbs +52 -0
  114. data/stdlib/open3/0/open3.rbs +0 -8
  115. data/stdlib/openssl/0/openssl.rbs +136 -69
  116. data/stdlib/optparse/0/optparse.rbs +58 -18
  117. data/stdlib/pathname/0/pathname.rbs +2 -8
  118. data/stdlib/pp/0/pp.rbs +3 -1
  119. data/stdlib/prettyprint/0/prettyprint.rbs +0 -4
  120. data/stdlib/pstore/0/pstore.rbs +0 -6
  121. data/stdlib/psych/0/psych.rbs +15 -4
  122. data/stdlib/pty/0/pty.rbs +46 -4
  123. data/stdlib/rdoc/0/code_object.rbs +0 -4
  124. data/stdlib/rdoc/0/markup.rbs +10 -12
  125. data/stdlib/rdoc/0/rdoc.rbs +1 -2
  126. data/stdlib/resolv/0/resolv.rbs +8 -3
  127. data/stdlib/ripper/0/ripper.rbs +0 -2
  128. data/stdlib/securerandom/0/securerandom.rbs +0 -2
  129. data/stdlib/shellwords/0/shellwords.rbs +11 -12
  130. data/stdlib/singleton/0/singleton.rbs +0 -1
  131. data/stdlib/socket/0/addrinfo.rbs +0 -1
  132. data/stdlib/socket/0/basic_socket.rbs +0 -5
  133. data/stdlib/socket/0/socket.rbs +49 -25
  134. data/stdlib/socket/0/tcp_server.rbs +0 -3
  135. data/stdlib/socket/0/tcp_socket.rbs +58 -3
  136. data/stdlib/socket/0/udp_socket.rbs +0 -1
  137. data/stdlib/socket/0/unix_server.rbs +0 -3
  138. data/stdlib/strscan/0/string_scanner.rbs +1265 -422
  139. data/stdlib/tempfile/0/tempfile.rbs +135 -28
  140. data/stdlib/time/0/time.rbs +48 -35
  141. data/stdlib/timeout/0/timeout.rbs +11 -8
  142. data/stdlib/tmpdir/0/tmpdir.rbs +8 -1
  143. data/stdlib/tsort/0/tsort.rbs +0 -4
  144. data/stdlib/uri/0/common.rbs +11 -30
  145. data/stdlib/uri/0/ftp.rbs +1 -1
  146. data/stdlib/uri/0/generic.rbs +22 -18
  147. data/stdlib/uri/0/http.rbs +2 -2
  148. data/stdlib/uri/0/rfc2396_parser.rbs +3 -0
  149. data/stdlib/zlib/0/buf_error.rbs +1 -70
  150. data/stdlib/zlib/0/data_error.rbs +1 -70
  151. data/stdlib/zlib/0/deflate.rbs +8 -72
  152. data/stdlib/zlib/0/error.rbs +1 -70
  153. data/stdlib/zlib/0/gzip_file/crc_error.rbs +2 -105
  154. data/stdlib/zlib/0/gzip_file/error.rbs +2 -105
  155. data/stdlib/zlib/0/gzip_file/length_error.rbs +2 -105
  156. data/stdlib/zlib/0/gzip_file/no_footer.rbs +2 -105
  157. data/stdlib/zlib/0/gzip_file.rbs +1 -71
  158. data/stdlib/zlib/0/gzip_reader.rbs +3 -74
  159. data/stdlib/zlib/0/gzip_writer.rbs +1 -70
  160. data/stdlib/zlib/0/inflate.rbs +4 -71
  161. data/stdlib/zlib/0/mem_error.rbs +1 -70
  162. data/stdlib/zlib/0/need_dict.rbs +1 -70
  163. data/stdlib/zlib/0/stream_end.rbs +1 -70
  164. data/stdlib/zlib/0/stream_error.rbs +1 -70
  165. data/stdlib/zlib/0/version_error.rbs +1 -70
  166. data/stdlib/zlib/0/zlib.rbs +0 -2
  167. data/stdlib/zlib/0/zstream.rbs +4 -72
  168. metadata +4 -6
@@ -146,7 +146,6 @@ void parser_advance_no_gap(parserstate *state) {
146
146
  static VALUE parse_type_name(parserstate *state, TypeNameKind kind, range *rg) {
147
147
  VALUE absolute = Qfalse;
148
148
  VALUE path = EMPTY_ARRAY;
149
- VALUE namespace;
150
149
 
151
150
  if (rg) {
152
151
  rg->start = state->current_token.range.start;
@@ -169,7 +168,8 @@ static VALUE parse_type_name(parserstate *state, TypeNameKind kind, range *rg) {
169
168
  parser_advance(state);
170
169
  parser_advance(state);
171
170
  }
172
- namespace = rbs_namespace(path, absolute);
171
+
172
+ VALUE namespace = rbs_namespace(path, absolute);
173
173
 
174
174
  switch (state->current_token.type) {
175
175
  case tLIDENT:
@@ -267,7 +267,6 @@ static bool is_keyword_token(enum TokenType type) {
267
267
  */
268
268
  static VALUE parse_function_param(parserstate *state) {
269
269
  range type_range;
270
-
271
270
  type_range.start = state->next_token.range.start;
272
271
  VALUE type = parse_type(state);
273
272
  type_range.end = state->current_token.range.end;
@@ -283,11 +282,13 @@ static VALUE parse_function_param(parserstate *state) {
283
282
  return rbs_function_param(type, Qnil, location);
284
283
  } else {
285
284
  range name_range = state->next_token.range;
286
- range param_range;
287
285
 
288
286
  parser_advance(state);
289
- param_range.start = type_range.start;
290
- param_range.end = name_range.end;
287
+
288
+ range param_range = {
289
+ .start = type_range.start,
290
+ .end = name_range.end,
291
+ };
291
292
 
292
293
  if (!is_keyword_token(state->current_token.type)) {
293
294
  raise_syntax_error(
@@ -320,28 +321,22 @@ static ID intern_token_start_end(parserstate *state, token start_token, token en
320
321
  | {} keyword <`?`> `:`
321
322
  */
322
323
  static VALUE parse_keyword_key(parserstate *state) {
323
- VALUE key;
324
-
325
324
  parser_advance(state);
326
325
 
327
326
  if (state->next_token.type == pQUESTION) {
328
- key = ID2SYM(intern_token_start_end(state, state->current_token, state->next_token));
327
+ VALUE key = ID2SYM(intern_token_start_end(state, state->current_token, state->next_token));
329
328
  parser_advance(state);
329
+ return key;
330
330
  } else {
331
- key = ID2SYM(INTERN_TOKEN(state, state->current_token));
331
+ return ID2SYM(INTERN_TOKEN(state, state->current_token));
332
332
  }
333
-
334
- return key;
335
333
  }
336
334
 
337
335
  /*
338
336
  keyword ::= {} keyword `:` <function_param>
339
337
  */
340
338
  static void parse_keyword(parserstate *state, VALUE keywords, VALUE memo) {
341
- VALUE key;
342
- VALUE param;
343
-
344
- key = parse_keyword_key(state);
339
+ VALUE key = parse_keyword_key(state);
345
340
 
346
341
  if (!NIL_P(rb_hash_aref(memo, key))) {
347
342
  raise_syntax_error(
@@ -354,7 +349,7 @@ static void parse_keyword(parserstate *state, VALUE keywords, VALUE memo) {
354
349
  }
355
350
 
356
351
  parser_advance_assert(state, pCOLON);
357
- param = parse_function_param(state);
352
+ VALUE param = parse_function_param(state);
358
353
 
359
354
  rb_hash_aset(keywords, key, param);
360
355
 
@@ -591,6 +586,7 @@ EOP:
591
586
  static VALUE parse_optional(parserstate *state) {
592
587
  range rg;
593
588
  rg.start = state->next_token.range.start;
589
+
594
590
  VALUE type = parse_simple(state);
595
591
 
596
592
  if (state->next_token.type == pQUESTION) {
@@ -604,13 +600,15 @@ static VALUE parse_optional(parserstate *state) {
604
600
  }
605
601
 
606
602
  static void initialize_method_params(method_params *params){
607
- params->required_positionals = EMPTY_ARRAY;
608
- params->optional_positionals = EMPTY_ARRAY;
609
- params->rest_positionals = Qnil;
610
- params->trailing_positionals = EMPTY_ARRAY;
611
- params->required_keywords = rb_hash_new();
612
- params->optional_keywords = rb_hash_new();
613
- params->rest_keywords = Qnil;
603
+ *params = (method_params) {
604
+ .required_positionals = EMPTY_ARRAY,
605
+ .optional_positionals = EMPTY_ARRAY,
606
+ .rest_positionals = Qnil,
607
+ .trailing_positionals = EMPTY_ARRAY,
608
+ .required_keywords = rb_hash_new(),
609
+ .optional_keywords = rb_hash_new(),
610
+ .rest_keywords = Qnil,
611
+ };
614
612
  }
615
613
 
616
614
  /*
@@ -790,9 +788,10 @@ static VALUE parse_record_attributes(parserstate *state) {
790
788
  case tDQSTRING:
791
789
  case tINTEGER:
792
790
  case kTRUE:
793
- case kFALSE:
791
+ case kFALSE: {
794
792
  key = rb_funcall(parse_simple(state), rb_intern("literal"), 0);
795
793
  break;
794
+ }
796
795
  default:
797
796
  raise_syntax_error(
798
797
  state,
@@ -864,15 +863,12 @@ static VALUE parse_symbol(parserstate *state) {
864
863
  | {} `[` type_list <`]`>
865
864
  */
866
865
  static VALUE parse_instance_type(parserstate *state, bool parse_alias) {
867
- range name_range;
868
- range args_range;
869
- range type_range;
870
-
871
866
  TypeNameKind expected_kind = INTERFACE_NAME | CLASS_NAME;
872
867
  if (parse_alias) {
873
868
  expected_kind |= ALIAS_NAME;
874
869
  }
875
870
 
871
+ range name_range;
876
872
  VALUE typename = parse_type_name(state, expected_kind, &name_range);
877
873
  VALUE types = EMPTY_ARRAY;
878
874
 
@@ -887,6 +883,7 @@ static VALUE parse_instance_type(parserstate *state, bool parse_alias) {
887
883
  rbs_abort();
888
884
  }
889
885
 
886
+ range args_range;
890
887
  if (state->next_token.type == pLBRACKET) {
891
888
  parser_advance(state);
892
889
  args_range.start = state->current_token.range.start;
@@ -897,8 +894,10 @@ static VALUE parse_instance_type(parserstate *state, bool parse_alias) {
897
894
  args_range = NULL_RANGE;
898
895
  }
899
896
 
900
- type_range.start = name_range.start;
901
- type_range.end = nonnull_pos_or(args_range.end, name_range.end);
897
+ range type_range = {
898
+ .start = name_range.start,
899
+ .end = nonnull_pos_or(args_range.end, name_range.end),
900
+ };
902
901
 
903
902
  VALUE location = rbs_new_location(state->buffer, type_range);
904
903
  rbs_loc *loc = rbs_check_location(location);
@@ -921,15 +920,14 @@ static VALUE parse_instance_type(parserstate *state, bool parse_alias) {
921
920
  singleton_type ::= {`singleton`} `(` type_name <`)`>
922
921
  */
923
922
  static VALUE parse_singleton_type(parserstate *state) {
924
- range name_range;
925
- range type_range;
926
-
927
923
  parser_assert(state, kSINGLETON);
928
924
 
925
+ range type_range;
929
926
  type_range.start = state->current_token.range.start;
930
927
  parser_advance_assert(state, pLPAREN);
931
928
  parser_advance(state);
932
929
 
930
+ range name_range;
933
931
  VALUE typename = parse_type_name(state, CLASS_NAME, &name_range);
934
932
 
935
933
  parser_advance_assert(state, pRPAREN);
@@ -962,24 +960,33 @@ static VALUE parse_simple(parserstate *state) {
962
960
  parser_advance_assert(state, pRPAREN);
963
961
  return type;
964
962
  }
965
- case kBOOL:
963
+ case kBOOL: {
966
964
  return rbs_bases_bool(rbs_location_current_token(state));
967
- case kBOT:
965
+ }
966
+ case kBOT: {
968
967
  return rbs_bases_bottom(rbs_location_current_token(state));
969
- case kCLASS:
968
+ }
969
+ case kCLASS: {
970
970
  return rbs_bases_class(rbs_location_current_token(state));
971
- case kINSTANCE:
971
+ }
972
+ case kINSTANCE: {
972
973
  return rbs_bases_instance(rbs_location_current_token(state));
973
- case kNIL:
974
+ }
975
+ case kNIL: {
974
976
  return rbs_bases_nil(rbs_location_current_token(state));
975
- case kSELF:
977
+ }
978
+ case kSELF: {
976
979
  return rbs_bases_self(rbs_location_current_token(state));
977
- case kTOP:
980
+ }
981
+ case kTOP: {
978
982
  return rbs_bases_top(rbs_location_current_token(state));
979
- case kVOID:
983
+ }
984
+ case kVOID: {
980
985
  return rbs_bases_void(rbs_location_current_token(state));
981
- case kUNTYPED:
986
+ }
987
+ case kUNTYPED: {
982
988
  return rbs_bases_any(rbs_location_current_token(state));
989
+ }
983
990
  case k__TODO__: {
984
991
  VALUE type = rbs_bases_any(rbs_location_current_token(state));
985
992
  rb_funcall(type, rb_intern("todo!"), 0);
@@ -996,10 +1003,12 @@ static VALUE parse_simple(parserstate *state) {
996
1003
  rbs_location_current_token(state)
997
1004
  );
998
1005
  }
999
- case kTRUE:
1006
+ case kTRUE: {
1000
1007
  return rbs_literal(Qtrue, rbs_location_current_token(state));
1001
- case kFALSE:
1008
+ }
1009
+ case kFALSE: {
1002
1010
  return rbs_literal(Qfalse, rbs_location_current_token(state));
1011
+ }
1003
1012
  case tSQSTRING:
1004
1013
  case tDQSTRING: {
1005
1014
  VALUE literal = rbs_unquote_string(state, state->current_token.range, 0);
@@ -1022,10 +1031,12 @@ static VALUE parse_simple(parserstate *state) {
1022
1031
  }
1023
1032
  case tULIDENT: // fallthrough
1024
1033
  case tLIDENT: // fallthrough
1025
- case pCOLON2:
1034
+ case pCOLON2: {
1026
1035
  return parse_instance_type(state, true);
1027
- case kSINGLETON:
1036
+ }
1037
+ case kSINGLETON: {
1028
1038
  return parse_singleton_type(state);
1039
+ }
1029
1040
  case pLBRACKET: {
1030
1041
  range rg;
1031
1042
  rg.start = state->current_token.range.start;
@@ -1067,8 +1078,8 @@ static VALUE parse_simple(parserstate *state) {
1067
1078
  */
1068
1079
  static VALUE parse_intersection(parserstate *state) {
1069
1080
  range rg;
1070
-
1071
1081
  rg.start = state->next_token.range.start;
1082
+
1072
1083
  VALUE type = parse_optional(state);
1073
1084
  VALUE intersection_types = rb_ary_new();
1074
1085
 
@@ -1094,8 +1105,8 @@ static VALUE parse_intersection(parserstate *state) {
1094
1105
  */
1095
1106
  VALUE parse_type(parserstate *state) {
1096
1107
  range rg;
1097
-
1098
1108
  rg.start = state->next_token.range.start;
1109
+
1099
1110
  VALUE type = parse_intersection(state);
1100
1111
  VALUE union_types = rb_ary_new();
1101
1112
 
@@ -1134,21 +1145,16 @@ static VALUE parse_type_params(parserstate *state, range *rg, bool module_type_p
1134
1145
  rg->start = state->current_token.range.start;
1135
1146
 
1136
1147
  while (true) {
1137
- VALUE name;
1138
1148
  bool unchecked = false;
1139
1149
  VALUE variance = ID2SYM(rb_intern("invariant"));
1140
1150
  VALUE upper_bound = Qnil;
1141
1151
  VALUE default_type = Qnil;
1142
1152
 
1143
- range param_range = NULL_RANGE;
1144
- range name_range;
1145
- range variance_range = NULL_RANGE;
1146
- range unchecked_range = NULL_RANGE;
1147
- range upper_bound_range = NULL_RANGE;
1148
- range default_type_range = NULL_RANGE;
1149
-
1153
+ range param_range;
1150
1154
  param_range.start = state->next_token.range.start;
1151
1155
 
1156
+ range variance_range = NULL_RANGE;
1157
+ range unchecked_range = NULL_RANGE;
1152
1158
  if (module_type_params) {
1153
1159
  if (state->next_token.type == kUNCHECKED) {
1154
1160
  unchecked = true;
@@ -1174,13 +1180,14 @@ static VALUE parse_type_params(parserstate *state, range *rg, bool module_type_p
1174
1180
  }
1175
1181
 
1176
1182
  parser_advance_assert(state, tUIDENT);
1177
- name_range = state->current_token.range;
1183
+ range name_range = state->current_token.range;
1178
1184
 
1179
1185
  ID id = INTERN_TOKEN(state, state->current_token);
1180
- name = ID2SYM(id);
1186
+ VALUE name = ID2SYM(id);
1181
1187
 
1182
1188
  parser_insert_typevar(state, id);
1183
1189
 
1190
+ range upper_bound_range = NULL_RANGE;
1184
1191
  if (state->next_token.type == pLT) {
1185
1192
  parser_advance(state);
1186
1193
  upper_bound_range.start = state->current_token.range.start;
@@ -1188,6 +1195,7 @@ static VALUE parse_type_params(parserstate *state, range *rg, bool module_type_p
1188
1195
  upper_bound_range.end = state->current_token.range.end;
1189
1196
  }
1190
1197
 
1198
+ range default_type_range = NULL_RANGE;
1191
1199
  if (module_type_params) {
1192
1200
  if (state->next_token.type == pEQ) {
1193
1201
  parser_advance(state);
@@ -1257,20 +1265,19 @@ static VALUE parse_type_params(parserstate *state, range *rg, bool module_type_p
1257
1265
  method_type ::= {} type_params <function>
1258
1266
  */
1259
1267
  VALUE parse_method_type(parserstate *state) {
1260
- range rg;
1261
- range params_range = NULL_RANGE;
1262
- range type_range;
1263
-
1264
- VALUE function = Qnil;
1265
- VALUE block = Qnil;
1266
1268
  parser_push_typevar_table(state, false);
1267
1269
 
1270
+ range rg;
1268
1271
  rg.start = state->next_token.range.start;
1269
1272
 
1273
+ range params_range = NULL_RANGE;
1270
1274
  VALUE type_params = parse_type_params(state, &params_range, false);
1271
1275
 
1276
+ range type_range;
1272
1277
  type_range.start = state->next_token.range.start;
1273
1278
 
1279
+ VALUE function = Qnil;
1280
+ VALUE block = Qnil;
1274
1281
  parse_function(state, &function, &block, NULL);
1275
1282
 
1276
1283
  rg.end = state->current_token.range.end;
@@ -1297,29 +1304,20 @@ VALUE parse_method_type(parserstate *state) {
1297
1304
  */
1298
1305
  static VALUE parse_global_decl(parserstate *state) {
1299
1306
  range decl_range;
1300
- range name_range, colon_range;
1301
-
1302
- VALUE typename;
1303
- VALUE type;
1304
- VALUE location;
1305
- VALUE comment;
1306
-
1307
- rbs_loc *loc;
1308
-
1309
1307
  decl_range.start = state->current_token.range.start;
1310
- comment = get_comment(state, decl_range.start.line);
1311
1308
 
1312
- name_range = state->current_token.range;
1313
- typename = ID2SYM(INTERN_TOKEN(state, state->current_token));
1309
+ VALUE comment = get_comment(state, decl_range.start.line);
1310
+ range name_range = state->current_token.range;
1311
+ VALUE typename = ID2SYM(INTERN_TOKEN(state, state->current_token));
1314
1312
 
1315
1313
  parser_advance_assert(state, pCOLON);
1316
- colon_range = state->current_token.range;
1314
+ range colon_range = state->current_token.range;
1317
1315
 
1318
- type = parse_type(state);
1316
+ VALUE type = parse_type(state);
1319
1317
  decl_range.end = state->current_token.range.end;
1320
1318
 
1321
- location = rbs_new_location(state->buffer, decl_range);
1322
- loc = rbs_check_location(location);
1319
+ VALUE location = rbs_new_location(state->buffer, decl_range);
1320
+ rbs_loc *loc = rbs_check_location(location);
1323
1321
  rbs_loc_alloc_children(loc, 2);
1324
1322
  rbs_loc_add_required_child(loc, rb_intern("name"), name_range);
1325
1323
  rbs_loc_add_required_child(loc, rb_intern("colon"), colon_range);
@@ -1332,28 +1330,21 @@ static VALUE parse_global_decl(parserstate *state) {
1332
1330
  */
1333
1331
  static VALUE parse_const_decl(parserstate *state) {
1334
1332
  range decl_range;
1335
- range name_range, colon_range;
1336
-
1337
- VALUE typename;
1338
- VALUE type;
1339
- VALUE location;
1340
- VALUE comment;
1341
-
1342
- rbs_loc *loc;
1343
1333
 
1344
1334
  decl_range.start = state->current_token.range.start;
1345
- comment = get_comment(state, decl_range.start.line);
1335
+ VALUE comment = get_comment(state, decl_range.start.line);
1346
1336
 
1347
- typename = parse_type_name(state, CLASS_NAME, &name_range);
1337
+ range name_range;
1338
+ VALUE typename = parse_type_name(state, CLASS_NAME, &name_range);
1348
1339
 
1349
1340
  parser_advance_assert(state, pCOLON);
1350
- colon_range = state->current_token.range;
1341
+ range colon_range = state->current_token.range;
1351
1342
 
1352
- type = parse_type(state);
1343
+ VALUE type = parse_type(state);
1353
1344
  decl_range.end = state->current_token.range.end;
1354
1345
 
1355
- location = rbs_new_location(state->buffer, decl_range);
1356
- loc = rbs_check_location(location);
1346
+ VALUE location = rbs_new_location(state->buffer, decl_range);
1347
+ rbs_loc *loc = rbs_check_location(location);
1357
1348
  rbs_loc_alloc_children(loc, 2);
1358
1349
  rbs_loc_add_required_child(loc, rb_intern("name"), name_range);
1359
1350
  rbs_loc_add_required_child(loc, rb_intern("colon"), colon_range);
@@ -1365,23 +1356,24 @@ static VALUE parse_const_decl(parserstate *state) {
1365
1356
  type_decl ::= {kTYPE} alias_name `=` <type>
1366
1357
  */
1367
1358
  static VALUE parse_type_decl(parserstate *state, position comment_pos, VALUE annotations) {
1368
- range decl_range;
1369
- range keyword_range, name_range, params_range, eq_range;
1370
-
1371
1359
  parser_push_typevar_table(state, true);
1372
1360
 
1361
+ range decl_range;
1373
1362
  decl_range.start = state->current_token.range.start;
1374
1363
  comment_pos = nonnull_pos_or(comment_pos, decl_range.start);
1375
1364
 
1376
- keyword_range = state->current_token.range;
1365
+ range keyword_range = state->current_token.range;
1377
1366
 
1378
1367
  parser_advance(state);
1368
+
1369
+ range name_range;
1379
1370
  VALUE typename = parse_type_name(state, ALIAS_NAME, &name_range);
1380
1371
 
1372
+ range params_range;
1381
1373
  VALUE type_params = parse_type_params(state, &params_range, true);
1382
1374
 
1383
1375
  parser_advance_assert(state, pEQ);
1384
- eq_range = state->current_token.range;
1376
+ range eq_range = state->current_token.range;
1385
1377
 
1386
1378
  VALUE type = parse_type(state);
1387
1379
  decl_range.end = state->current_token.range.end;
@@ -1520,8 +1512,9 @@ static VALUE parse_method_name(parserstate *state, range *range) {
1520
1512
  *range = state->current_token.range;
1521
1513
  return ID2SYM(INTERN_TOKEN(state, state->current_token));
1522
1514
 
1523
- case tQIDENT:
1515
+ case tQIDENT: {
1524
1516
  return rb_to_symbol(rbs_unquote_string(state, state->current_token.range, 0));
1517
+ }
1525
1518
 
1526
1519
  case pBAR:
1527
1520
  case pHAT:
@@ -1566,8 +1559,6 @@ static InstanceSingletonKind parse_instance_singleton_kind(parserstate *state, b
1566
1559
  parser_advance(state);
1567
1560
  parser_advance(state);
1568
1561
  kind = SINGLETON_KIND;
1569
- rg->start = self_range.start;
1570
- rg->end = state->current_token.range.end;
1571
1562
  } else if (
1572
1563
  state->next_token2.type == pQUESTION
1573
1564
  && state->next_token.range.end.char_pos == state->next_token2.range.start.char_pos
@@ -1577,9 +1568,12 @@ static InstanceSingletonKind parse_instance_singleton_kind(parserstate *state, b
1577
1568
  parser_advance(state);
1578
1569
  parser_advance(state);
1579
1570
  kind = INSTANCE_SINGLETON_KIND;
1580
- rg->start = self_range.start;
1581
- rg->end = state->current_token.range.end;
1582
1571
  }
1572
+
1573
+ *rg = (range) {
1574
+ .start = self_range.start,
1575
+ .end = state->current_token.range.end,
1576
+ };
1583
1577
  } else {
1584
1578
  *rg = NULL_RANGE;
1585
1579
  }
@@ -1601,40 +1595,38 @@ static InstanceSingletonKind parse_instance_singleton_kind(parserstate *state, b
1601
1595
  * */
1602
1596
  static VALUE parse_member_def(parserstate *state, bool instance_only, bool accept_overload, position comment_pos, VALUE annotations) {
1603
1597
  range member_range;
1604
- range visibility_range;
1605
- range keyword_range;
1606
- range name_range;
1607
- range kind_range;
1608
- range overloading_range = NULL_RANGE;
1609
-
1610
- VALUE visibility;
1611
-
1612
1598
  member_range.start = state->current_token.range.start;
1613
1599
  comment_pos = nonnull_pos_or(comment_pos, member_range.start);
1600
+
1614
1601
  VALUE comment = get_comment(state, comment_pos.line);
1615
1602
 
1603
+ range visibility_range;
1604
+ VALUE visibility;
1616
1605
  switch (state->current_token.type)
1617
1606
  {
1618
- case kPRIVATE:
1607
+ case kPRIVATE: {
1619
1608
  visibility_range = state->current_token.range;
1620
1609
  visibility = ID2SYM(rb_intern("private"));
1621
1610
  member_range.start = visibility_range.start;
1622
1611
  parser_advance(state);
1623
1612
  break;
1624
- case kPUBLIC:
1613
+ }
1614
+ case kPUBLIC: {
1625
1615
  visibility_range = state->current_token.range;
1626
1616
  visibility = ID2SYM(rb_intern("public"));
1627
1617
  member_range.start = visibility_range.start;
1628
1618
  parser_advance(state);
1629
1619
  break;
1620
+ }
1630
1621
  default:
1631
1622
  visibility_range = NULL_RANGE;
1632
1623
  visibility = Qnil;
1633
1624
  break;
1634
1625
  }
1635
1626
 
1636
- keyword_range = state->current_token.range;
1627
+ range keyword_range = state->current_token.range;
1637
1628
 
1629
+ range kind_range;
1638
1630
  InstanceSingletonKind kind;
1639
1631
  if (instance_only) {
1640
1632
  kind_range = NULL_RANGE;
@@ -1643,6 +1635,7 @@ static VALUE parse_member_def(parserstate *state, bool instance_only, bool accep
1643
1635
  kind = parse_instance_singleton_kind(state, NIL_P(visibility), &kind_range);
1644
1636
  }
1645
1637
 
1638
+ range name_range;
1646
1639
  VALUE name = parse_method_name(state, &name_range);
1647
1640
  VALUE overloads = rb_ary_new();
1648
1641
  VALUE overloading = Qfalse;
@@ -1659,6 +1652,7 @@ static VALUE parse_member_def(parserstate *state, bool instance_only, bool accep
1659
1652
 
1660
1653
  parser_push_typevar_table(state, kind != INSTANCE_KIND);
1661
1654
 
1655
+ range overloading_range = NULL_RANGE;
1662
1656
  bool loop = true;
1663
1657
  while (loop) {
1664
1658
  VALUE annotations = EMPTY_ARRAY;
@@ -1781,18 +1775,13 @@ void class_instance_name(parserstate *state, TypeNameKind kind, VALUE *name, VAL
1781
1775
  * */
1782
1776
  static VALUE parse_mixin_member(parserstate *state, bool from_interface, position comment_pos, VALUE annotations) {
1783
1777
  range member_range;
1784
- range name_range;
1785
- range keyword_range;
1786
- range args_range = NULL_RANGE;
1787
- bool reset_typevar_scope;
1788
- enum TokenType type;
1789
-
1790
1778
  member_range.start = state->current_token.range.start;
1791
1779
  comment_pos = nonnull_pos_or(comment_pos, member_range.start);
1792
1780
 
1793
- type = state->current_token.type;
1794
- keyword_range = state->current_token.range;
1781
+ enum TokenType type = state->current_token.type;
1782
+ range keyword_range = state->current_token.range;
1795
1783
 
1784
+ bool reset_typevar_scope;
1796
1785
  switch (type)
1797
1786
  {
1798
1787
  case kINCLUDE:
@@ -1822,6 +1811,8 @@ static VALUE parse_mixin_member(parserstate *state, bool from_interface, positio
1822
1811
 
1823
1812
  VALUE name;
1824
1813
  VALUE args = EMPTY_ARRAY;
1814
+ range name_range;
1815
+ range args_range = NULL_RANGE;
1825
1816
  class_instance_name(
1826
1817
  state,
1827
1818
  from_interface ? INTERFACE_NAME : (INTERFACE_NAME | CLASS_NAME),
@@ -1863,19 +1854,14 @@ static VALUE parse_mixin_member(parserstate *state, bool from_interface, positio
1863
1854
  * */
1864
1855
  static VALUE parse_alias_member(parserstate *state, bool instance_only, position comment_pos, VALUE annotations) {
1865
1856
  range member_range;
1866
- range keyword_range, new_name_range, old_name_range;
1867
- range new_kind_range, old_kind_range;
1868
-
1869
1857
  member_range.start = state->current_token.range.start;
1870
- keyword_range = state->current_token.range;
1858
+ range keyword_range = state->current_token.range;
1871
1859
 
1872
1860
  comment_pos = nonnull_pos_or(comment_pos, member_range.start);
1873
1861
  VALUE comment = get_comment(state, comment_pos.line);
1874
1862
 
1875
- VALUE new_name;
1876
- VALUE old_name;
1877
- VALUE kind;
1878
-
1863
+ VALUE kind, new_name, old_name;
1864
+ range new_kind_range, old_kind_range, new_name_range, old_name_range;
1879
1865
  if (!instance_only && state->next_token.type == kSELF) {
1880
1866
  kind = ID2SYM(rb_intern("singleton"));
1881
1867
 
@@ -1925,11 +1911,6 @@ static VALUE parse_alias_member(parserstate *state, bool instance_only, position
1925
1911
  | {tA2IDENT} `:` <type>
1926
1912
  */
1927
1913
  static VALUE parse_variable_member(parserstate *state, position comment_pos, VALUE annotations) {
1928
- range member_range;
1929
- range name_range, colon_range;
1930
- range kind_range = NULL_RANGE;
1931
- rbs_loc *loc;
1932
-
1933
1914
  if (rb_array_len(annotations) > 0) {
1934
1915
  raise_syntax_error(
1935
1916
  state,
@@ -1938,83 +1919,82 @@ static VALUE parse_variable_member(parserstate *state, position comment_pos, VAL
1938
1919
  );
1939
1920
  }
1940
1921
 
1922
+ range member_range;
1941
1923
  member_range.start = state->current_token.range.start;
1942
1924
  comment_pos = nonnull_pos_or(comment_pos, member_range.start);
1943
1925
  VALUE comment = get_comment(state, comment_pos.line);
1944
1926
 
1945
- VALUE location;
1946
- VALUE name;
1947
- VALUE type;
1948
-
1949
1927
  switch (state->current_token.type)
1950
1928
  {
1951
- case tAIDENT:
1952
- name_range = state->current_token.range;
1953
- name = ID2SYM(INTERN_TOKEN(state, state->current_token));
1929
+ case tAIDENT: {
1930
+ range name_range = state->current_token.range;
1931
+ VALUE name = ID2SYM(INTERN_TOKEN(state, state->current_token));
1954
1932
 
1955
1933
  parser_advance_assert(state, pCOLON);
1956
- colon_range = state->current_token.range;
1934
+ range colon_range = state->current_token.range;
1957
1935
 
1958
- type = parse_type(state);
1936
+ VALUE type = parse_type(state);
1959
1937
  member_range.end = state->current_token.range.end;
1960
1938
 
1961
- location = rbs_new_location(state->buffer, member_range);
1962
- loc = rbs_check_location(location);
1939
+ VALUE location = rbs_new_location(state->buffer, member_range);
1940
+ rbs_loc *loc = rbs_check_location(location);
1963
1941
  rbs_loc_alloc_children(loc, 3);
1964
1942
  rbs_loc_add_required_child(loc, rb_intern("name"), name_range);
1965
1943
  rbs_loc_add_required_child(loc, rb_intern("colon"), colon_range);
1966
- rbs_loc_add_optional_child(loc, rb_intern("kind"), kind_range);
1944
+ rbs_loc_add_optional_child(loc, rb_intern("kind"), NULL_RANGE);
1967
1945
 
1968
1946
  return rbs_ast_members_instance_variable(name, type, location, comment);
1969
-
1970
- case tA2IDENT:
1971
- name_range = state->current_token.range;
1972
- name = ID2SYM(INTERN_TOKEN(state, state->current_token));
1947
+ }
1948
+ case tA2IDENT: {
1949
+ range name_range = state->current_token.range;
1950
+ VALUE name = ID2SYM(INTERN_TOKEN(state, state->current_token));
1973
1951
 
1974
1952
  parser_advance_assert(state, pCOLON);
1975
- colon_range = state->current_token.range;
1953
+ range colon_range = state->current_token.range;
1976
1954
 
1977
1955
  parser_push_typevar_table(state, true);
1978
- type = parse_type(state);
1956
+ VALUE type = parse_type(state);
1979
1957
  parser_pop_typevar_table(state);
1980
1958
  member_range.end = state->current_token.range.end;
1981
1959
 
1982
- location = rbs_new_location(state->buffer, member_range);
1983
- loc = rbs_check_location(location);
1960
+ VALUE location = rbs_new_location(state->buffer, member_range);
1961
+ rbs_loc *loc = rbs_check_location(location);
1984
1962
  rbs_loc_alloc_children(loc, 3);
1985
1963
  rbs_loc_add_required_child(loc, rb_intern("name"), name_range);
1986
1964
  rbs_loc_add_required_child(loc, rb_intern("colon"), colon_range);
1987
- rbs_loc_add_optional_child(loc, rb_intern("kind"), kind_range);
1965
+ rbs_loc_add_optional_child(loc, rb_intern("kind"), NULL_RANGE);
1988
1966
 
1989
1967
  return rbs_ast_members_class_variable(name, type, location, comment);
1990
-
1991
- case kSELF:
1992
- kind_range.start = state->current_token.range.start;
1993
- kind_range.end = state->next_token.range.end;
1968
+ }
1969
+ case kSELF: {
1970
+ range kind_range = {
1971
+ .start = state->current_token.range.start,
1972
+ .end = state->next_token.range.end
1973
+ };
1994
1974
 
1995
1975
  parser_advance_assert(state, pDOT);
1996
1976
  parser_advance_assert(state, tAIDENT);
1997
1977
 
1998
- name_range = state->current_token.range;
1999
- name = ID2SYM(INTERN_TOKEN(state, state->current_token));
1978
+ range name_range = state->current_token.range;
1979
+ VALUE name = ID2SYM(INTERN_TOKEN(state, state->current_token));
2000
1980
 
2001
1981
  parser_advance_assert(state, pCOLON);
2002
- colon_range = state->current_token.range;
1982
+ range colon_range = state->current_token.range;
2003
1983
 
2004
1984
  parser_push_typevar_table(state, true);
2005
- type = parse_type(state);
1985
+ VALUE type = parse_type(state);
2006
1986
  parser_pop_typevar_table(state);
2007
1987
  member_range.end = state->current_token.range.end;
2008
1988
 
2009
- location = rbs_new_location(state->buffer, member_range);
2010
- loc = rbs_check_location(location);
1989
+ VALUE location = rbs_new_location(state->buffer, member_range);
1990
+ rbs_loc *loc = rbs_check_location(location);
2011
1991
  rbs_loc_alloc_children(loc, 3);
2012
1992
  rbs_loc_add_required_child(loc, rb_intern("name"), name_range);
2013
1993
  rbs_loc_add_required_child(loc, rb_intern("colon"), colon_range);
2014
1994
  rbs_loc_add_optional_child(loc, rb_intern("kind"), kind_range);
2015
1995
 
2016
1996
  return rbs_ast_members_class_instance_variable(name, type, location, comment);
2017
-
1997
+ }
2018
1998
  default:
2019
1999
  rbs_abort();
2020
2000
  }
@@ -2062,24 +2042,12 @@ static VALUE parse_visibility_member(parserstate *state, VALUE annotations) {
2062
2042
  */
2063
2043
  static VALUE parse_attribute_member(parserstate *state, position comment_pos, VALUE annotations) {
2064
2044
  range member_range;
2065
- range keyword_range, name_range, colon_range;
2066
- range kind_range = NULL_RANGE, ivar_range = NULL_RANGE, ivar_name_range = NULL_RANGE, visibility_range = NULL_RANGE;
2067
-
2068
- InstanceSingletonKind is_kind;
2069
- VALUE kind;
2070
- VALUE attr_name;
2071
- VALUE ivar_name;
2072
- VALUE type;
2073
- VALUE comment;
2074
- VALUE location;
2075
- VALUE visibility;
2076
- rbs_loc *loc;
2077
- enum TokenType attr_type;
2078
-
2079
2045
  member_range.start = state->current_token.range.start;
2080
2046
  comment_pos = nonnull_pos_or(comment_pos, member_range.start);
2081
- comment = get_comment(state, comment_pos.line);
2047
+ VALUE comment = get_comment(state, comment_pos.line);
2082
2048
 
2049
+ VALUE visibility;
2050
+ range visibility_range;
2083
2051
  switch (state->current_token.type)
2084
2052
  {
2085
2053
  case kPRIVATE:
@@ -2098,18 +2066,18 @@ static VALUE parse_attribute_member(parserstate *state, position comment_pos, VA
2098
2066
  break;
2099
2067
  }
2100
2068
 
2101
- attr_type = state->current_token.type;
2102
- keyword_range = state->current_token.range;
2069
+ enum TokenType attr_type = state->current_token.type;
2070
+ range keyword_range = state->current_token.range;
2103
2071
 
2104
- is_kind = parse_instance_singleton_kind(state, false, &kind_range);
2105
- if (is_kind == INSTANCE_KIND) {
2106
- kind = ID2SYM(rb_intern("instance"));
2107
- } else {
2108
- kind = ID2SYM(rb_intern("singleton"));
2109
- }
2072
+ range kind_range;
2073
+ InstanceSingletonKind is_kind = parse_instance_singleton_kind(state, false, &kind_range);
2074
+ VALUE kind = ID2SYM(rb_intern((is_kind == INSTANCE_KIND) ? "instance" : "singleton"));
2110
2075
 
2111
- attr_name = parse_method_name(state, &name_range);
2076
+ range name_range;
2077
+ VALUE attr_name = parse_method_name(state, &name_range);
2112
2078
 
2079
+ VALUE ivar_name;
2080
+ range ivar_range, ivar_name_range;
2113
2081
  if (state->next_token.type == pLPAREN) {
2114
2082
  parser_advance_assert(state, pLPAREN);
2115
2083
  ivar_range.start = state->current_token.range.start;
@@ -2119,24 +2087,27 @@ static VALUE parse_attribute_member(parserstate *state, position comment_pos, VA
2119
2087
  ivar_name_range = state->current_token.range;
2120
2088
  } else {
2121
2089
  ivar_name = Qfalse;
2090
+ ivar_name_range = NULL_RANGE;
2122
2091
  }
2123
2092
 
2124
2093
  parser_advance_assert(state, pRPAREN);
2125
2094
  ivar_range.end = state->current_token.range.end;
2126
2095
  } else {
2096
+ ivar_range = NULL_RANGE;
2127
2097
  ivar_name = Qnil;
2098
+ ivar_name_range = NULL_RANGE;
2128
2099
  }
2129
2100
 
2130
2101
  parser_advance_assert(state, pCOLON);
2131
- colon_range = state->current_token.range;
2102
+ range colon_range = state->current_token.range;
2132
2103
 
2133
2104
  parser_push_typevar_table(state, is_kind == SINGLETON_KIND);
2134
- type = parse_type(state);
2105
+ VALUE type = parse_type(state);
2135
2106
  parser_pop_typevar_table(state);
2136
2107
  member_range.end = state->current_token.range.end;
2137
2108
 
2138
- location = rbs_new_location(state->buffer, member_range);
2139
- loc = rbs_check_location(location);
2109
+ VALUE location = rbs_new_location(state->buffer, member_range);
2110
+ rbs_loc *loc = rbs_check_location(location);
2140
2111
  rbs_loc_alloc_children(loc, 7);
2141
2112
  rbs_loc_add_required_child(loc, rb_intern("keyword"), keyword_range);
2142
2113
  rbs_loc_add_required_child(loc, rb_intern("name"), name_range);
@@ -2179,19 +2150,22 @@ static VALUE parse_interface_members(parserstate *state) {
2179
2150
 
2180
2151
  VALUE member;
2181
2152
  switch (state->current_token.type) {
2182
- case kDEF:
2153
+ case kDEF: {
2183
2154
  member = parse_member_def(state, true, true, annot_pos, annotations);
2184
2155
  break;
2156
+ }
2185
2157
 
2186
2158
  case kINCLUDE:
2187
2159
  case kEXTEND:
2188
- case kPREPEND:
2160
+ case kPREPEND: {
2189
2161
  member = parse_mixin_member(state, true, annot_pos, annotations);
2190
2162
  break;
2163
+ }
2191
2164
 
2192
- case kALIAS:
2165
+ case kALIAS: {
2193
2166
  member = parse_alias_member(state, true, annot_pos, annotations);
2194
2167
  break;
2168
+ }
2195
2169
 
2196
2170
  default:
2197
2171
  raise_syntax_error(
@@ -2212,24 +2186,24 @@ static VALUE parse_interface_members(parserstate *state) {
2212
2186
  interface_decl ::= {`interface`} interface_name module_type_params interface_members <kEND>
2213
2187
  */
2214
2188
  static VALUE parse_interface_decl(parserstate *state, position comment_pos, VALUE annotations) {
2215
- range member_range;
2216
- range name_range, keyword_range, end_range;
2217
- range type_params_range = NULL_RANGE;
2189
+ parser_push_typevar_table(state, true);
2218
2190
 
2191
+ range member_range;
2219
2192
  member_range.start = state->current_token.range.start;
2220
2193
  comment_pos = nonnull_pos_or(comment_pos, member_range.start);
2221
2194
 
2222
- parser_push_typevar_table(state, true);
2223
- keyword_range = state->current_token.range;
2195
+ range keyword_range = state->current_token.range;
2224
2196
 
2225
2197
  parser_advance(state);
2226
2198
 
2199
+ range name_range;
2227
2200
  VALUE name = parse_type_name(state, INTERFACE_NAME, &name_range);
2201
+ range type_params_range;
2228
2202
  VALUE params = parse_type_params(state, &type_params_range, true);
2229
2203
  VALUE members = parse_interface_members(state);
2230
2204
 
2231
2205
  parser_advance_assert(state, kEND);
2232
- end_range = state->current_token.range;
2206
+ range end_range = state->current_token.range;
2233
2207
  member_range.end = end_range.end;
2234
2208
 
2235
2209
  parser_pop_typevar_table(state);
@@ -2260,18 +2234,16 @@ static VALUE parse_interface_decl(parserstate *state, position comment_pos, VALU
2260
2234
  */
2261
2235
  static void parse_module_self_types(parserstate *state, VALUE *array) {
2262
2236
  while (true) {
2263
- range self_range;
2264
- range name_range;
2265
- range args_range = NULL_RANGE;
2266
-
2267
2237
  parser_advance(state);
2268
2238
 
2239
+ range self_range;
2269
2240
  self_range.start = state->current_token.range.start;
2270
-
2241
+ range name_range;
2271
2242
  VALUE module_name = parse_type_name(state, CLASS_NAME | INTERFACE_NAME, &name_range);
2272
2243
  self_range.end = name_range.end;
2273
2244
 
2274
2245
  VALUE args = EMPTY_ARRAY;
2246
+ range args_range = NULL_RANGE;
2275
2247
  if (state->next_token.type == pLBRACKET) {
2276
2248
  parser_advance(state);
2277
2249
  args_range.start = state->current_token.range.start;
@@ -2315,55 +2287,61 @@ static VALUE parse_module_members(parserstate *state) {
2315
2287
  VALUE members = EMPTY_ARRAY;
2316
2288
 
2317
2289
  while (state->next_token.type != kEND) {
2318
- VALUE member;
2319
2290
  VALUE annotations = EMPTY_ARRAY;
2320
2291
  position annot_pos = NullPosition;
2321
-
2322
2292
  parse_annotations(state, &annotations, &annot_pos);
2323
2293
 
2324
2294
  parser_advance(state);
2325
2295
 
2296
+ VALUE member;
2326
2297
  switch (state->current_token.type)
2327
2298
  {
2328
- case kDEF:
2299
+ case kDEF: {
2329
2300
  member = parse_member_def(state, false, true, annot_pos, annotations);
2330
2301
  break;
2302
+ }
2331
2303
 
2332
2304
  case kINCLUDE:
2333
2305
  case kEXTEND:
2334
- case kPREPEND:
2306
+ case kPREPEND: {
2335
2307
  member = parse_mixin_member(state, false, annot_pos, annotations);
2336
2308
  break;
2309
+ }
2337
2310
 
2338
- case kALIAS:
2311
+ case kALIAS: {
2339
2312
  member = parse_alias_member(state, false, annot_pos, annotations);
2340
2313
  break;
2314
+ }
2341
2315
 
2342
2316
  case tAIDENT:
2343
2317
  case tA2IDENT:
2344
- case kSELF:
2318
+ case kSELF: {
2345
2319
  member = parse_variable_member(state, annot_pos, annotations);
2346
2320
  break;
2321
+ }
2347
2322
 
2348
2323
  case kATTRREADER:
2349
2324
  case kATTRWRITER:
2350
- case kATTRACCESSOR:
2325
+ case kATTRACCESSOR: {
2351
2326
  member = parse_attribute_member(state, annot_pos, annotations);
2352
2327
  break;
2328
+ }
2353
2329
 
2354
2330
  case kPUBLIC:
2355
2331
  case kPRIVATE:
2356
2332
  if (state->next_token.range.start.line == state->current_token.range.start.line) {
2357
2333
  switch (state->next_token.type)
2358
2334
  {
2359
- case kDEF:
2335
+ case kDEF: {
2360
2336
  member = parse_member_def(state, false, true, annot_pos, annotations);
2361
2337
  break;
2338
+ }
2362
2339
  case kATTRREADER:
2363
2340
  case kATTRWRITER:
2364
- case kATTRACCESSOR:
2341
+ case kATTRACCESSOR: {
2365
2342
  member = parse_attribute_member(state, annot_pos, annotations);
2366
2343
  break;
2344
+ }
2367
2345
  default:
2368
2346
  raise_syntax_error(state, state->next_token, "method or attribute definition is expected after visibility modifier");
2369
2347
  }
@@ -2389,19 +2367,16 @@ static VALUE parse_module_members(parserstate *state) {
2389
2367
  | {module_name} module_name module_type_params `:` module_self_types module_members <kEND>
2390
2368
  */
2391
2369
  static VALUE parse_module_decl0(parserstate *state, range keyword_range, VALUE module_name, range name_range, VALUE comment, VALUE annotations) {
2392
- range decl_range;
2393
- range end_range;
2394
- range type_params_range;
2395
- range colon_range;
2396
- range self_types_range;
2397
-
2398
2370
  parser_push_typevar_table(state, true);
2399
2371
 
2372
+ range decl_range;
2400
2373
  decl_range.start = keyword_range.start;
2401
-
2374
+ range type_params_range;
2402
2375
  VALUE type_params = parse_type_params(state, &type_params_range, true);
2403
- VALUE self_types = EMPTY_ARRAY;
2404
2376
 
2377
+ VALUE self_types = EMPTY_ARRAY;
2378
+ range colon_range;
2379
+ range self_types_range;
2405
2380
  if (state->next_token.type == pCOLON) {
2406
2381
  parser_advance(state);
2407
2382
  colon_range = state->current_token.range;
@@ -2416,7 +2391,7 @@ static VALUE parse_module_decl0(parserstate *state, range keyword_range, VALUE m
2416
2391
  VALUE members = parse_module_members(state);
2417
2392
 
2418
2393
  parser_advance_assert(state, kEND);
2419
- end_range = state->current_token.range;
2394
+ range end_range = state->current_token.range;
2420
2395
  decl_range.end = state->current_token.range.end;
2421
2396
 
2422
2397
  VALUE location = rbs_new_location(state->buffer, decl_range);
@@ -2449,12 +2424,12 @@ static VALUE parse_module_decl0(parserstate *state, range keyword_range, VALUE m
2449
2424
  */
2450
2425
  static VALUE parse_module_decl(parserstate *state, position comment_pos, VALUE annotations) {
2451
2426
  range keyword_range = state->current_token.range;
2452
- range module_name_range;
2453
2427
 
2454
2428
  comment_pos = nonnull_pos_or(comment_pos, state->current_token.range.start);
2455
2429
  VALUE comment = get_comment(state, comment_pos.line);
2456
2430
 
2457
2431
  parser_advance(state);
2432
+ range module_name_range;
2458
2433
  VALUE module_name = parse_type_name(state, CLASS_NAME, &module_name_range);
2459
2434
 
2460
2435
  if (state->next_token.type == pEQ) {
@@ -2465,9 +2440,10 @@ static VALUE parse_module_decl(parserstate *state, position comment_pos, VALUE a
2465
2440
  range old_name_range;
2466
2441
  VALUE old_name = parse_type_name(state, CLASS_NAME, &old_name_range);
2467
2442
 
2468
- range decl_range;
2469
- decl_range.start = keyword_range.start;
2470
- decl_range.end = old_name_range.end;
2443
+ range decl_range = {
2444
+ .start = keyword_range.start,
2445
+ .end = old_name_range.end
2446
+ };
2471
2447
 
2472
2448
  VALUE location = rbs_new_location(state->buffer, decl_range);
2473
2449
  rbs_loc *loc = rbs_check_location(location);
@@ -2489,25 +2465,20 @@ static VALUE parse_module_decl(parserstate *state, position comment_pos, VALUE a
2489
2465
  */
2490
2466
  static VALUE parse_class_decl_super(parserstate *state, range *lt_range) {
2491
2467
  if (parser_advance_if(state, pLT)) {
2492
- range super_range;
2493
- range name_range;
2494
- range args_range = NULL_RANGE;
2495
-
2496
- VALUE name;
2497
- VALUE args;
2498
- VALUE location;
2499
- rbs_loc *loc;
2500
-
2501
2468
  *lt_range = state->current_token.range;
2469
+
2470
+ range super_range;
2502
2471
  super_range.start = state->next_token.range.start;
2503
2472
 
2504
- args = EMPTY_ARRAY;
2473
+ VALUE name;
2474
+ VALUE args = EMPTY_ARRAY;
2475
+ range name_range, args_range;
2505
2476
  class_instance_name(state, CLASS_NAME, &name, &args, &name_range, &args_range);
2506
2477
 
2507
2478
  super_range.end = state->current_token.range.end;
2508
2479
 
2509
- location = rbs_new_location(state->buffer, super_range);
2510
- loc = rbs_check_location(location);
2480
+ VALUE location = rbs_new_location(state->buffer, super_range);
2481
+ rbs_loc *loc = rbs_check_location(location);
2511
2482
  rbs_loc_alloc_children(loc, 2);
2512
2483
  rbs_loc_add_required_child(loc, rb_intern("name"), name_range);
2513
2484
  rbs_loc_add_optional_child(loc, rb_intern("args"), args_range);
@@ -2523,34 +2494,29 @@ static VALUE parse_class_decl_super(parserstate *state, range *lt_range) {
2523
2494
  class_decl ::= {class_name} type_params class_decl_super class_members <`end`>
2524
2495
  */
2525
2496
  static VALUE parse_class_decl0(parserstate *state, range keyword_range, VALUE name, range name_range, VALUE comment, VALUE annotations) {
2526
- range decl_range;
2527
- range end_range;
2528
- range type_params_range;
2529
- range lt_range;
2497
+ parser_push_typevar_table(state, true);
2530
2498
 
2531
- VALUE type_params;
2532
- VALUE super;
2533
- VALUE members;
2534
- VALUE location;
2499
+ range decl_range;
2500
+ decl_range.start = keyword_range.start;
2535
2501
 
2536
- rbs_loc *loc;
2502
+ range type_params_range;
2503
+ VALUE type_params = parse_type_params(state, &type_params_range, true);
2537
2504
 
2538
- parser_push_typevar_table(state, true);
2505
+ range lt_range;
2506
+ VALUE super = parse_class_decl_super(state, &lt_range);
2539
2507
 
2540
- decl_range.start = keyword_range.start;
2508
+ VALUE members = parse_module_members(state);
2541
2509
 
2542
- type_params = parse_type_params(state, &type_params_range, true);
2543
- super = parse_class_decl_super(state, &lt_range);
2544
- members = parse_module_members(state);
2545
2510
  parser_advance_assert(state, kEND);
2546
- end_range = state->current_token.range;
2511
+
2512
+ range end_range = state->current_token.range;
2547
2513
 
2548
2514
  decl_range.end = end_range.end;
2549
2515
 
2550
2516
  parser_pop_typevar_table(state);
2551
2517
 
2552
- location = rbs_new_location(state->buffer, decl_range);
2553
- loc = rbs_check_location(location);
2518
+ VALUE location = rbs_new_location(state->buffer, decl_range);
2519
+ rbs_loc *loc = rbs_check_location(location);
2554
2520
  rbs_loc_alloc_children(loc, 5);
2555
2521
  rbs_loc_add_required_child(loc, rb_intern("keyword"), keyword_range);
2556
2522
  rbs_loc_add_required_child(loc, rb_intern("name"), name_range);
@@ -2575,12 +2541,12 @@ static VALUE parse_class_decl0(parserstate *state, range keyword_range, VALUE na
2575
2541
  */
2576
2542
  static VALUE parse_class_decl(parserstate *state, position comment_pos, VALUE annotations) {
2577
2543
  range keyword_range = state->current_token.range;
2578
- range class_name_range;
2579
2544
 
2580
2545
  comment_pos = nonnull_pos_or(comment_pos, state->current_token.range.start);
2581
2546
  VALUE comment = get_comment(state, comment_pos.line);
2582
2547
 
2583
2548
  parser_advance(state);
2549
+ range class_name_range;
2584
2550
  VALUE class_name = parse_type_name(state, CLASS_NAME, &class_name_range);
2585
2551
 
2586
2552
  if (state->next_token.type == pEQ) {
@@ -2591,9 +2557,10 @@ static VALUE parse_class_decl(parserstate *state, position comment_pos, VALUE an
2591
2557
  range old_name_range;
2592
2558
  VALUE old_name = parse_type_name(state, CLASS_NAME, &old_name_range);
2593
2559
 
2594
- range decl_range;
2595
- decl_range.start = keyword_range.start;
2596
- decl_range.end = old_name_range.end;
2560
+ range decl_range = {
2561
+ .start = keyword_range.start,
2562
+ .end = old_name_range.end,
2563
+ };
2597
2564
 
2598
2565
  VALUE location = rbs_new_location(state->buffer, decl_range);
2599
2566
  rbs_loc *loc = rbs_check_location(location);
@@ -2617,30 +2584,35 @@ static VALUE parse_class_decl(parserstate *state, position comment_pos, VALUE an
2617
2584
  | {<class_decl>}
2618
2585
  */
2619
2586
  static VALUE parse_nested_decl(parserstate *state, const char *nested_in, position annot_pos, VALUE annotations) {
2620
- VALUE decl;
2621
-
2622
2587
  parser_push_typevar_table(state, true);
2623
2588
 
2589
+ VALUE decl;
2624
2590
  switch (state->current_token.type) {
2625
2591
  case tUIDENT:
2626
- case pCOLON2:
2592
+ case pCOLON2: {
2627
2593
  decl = parse_const_decl(state);
2628
2594
  break;
2629
- case tGIDENT:
2595
+ }
2596
+ case tGIDENT: {
2630
2597
  decl = parse_global_decl(state);
2631
2598
  break;
2632
- case kTYPE:
2599
+ }
2600
+ case kTYPE: {
2633
2601
  decl = parse_type_decl(state, annot_pos, annotations);
2634
2602
  break;
2635
- case kINTERFACE:
2603
+ }
2604
+ case kINTERFACE: {
2636
2605
  decl = parse_interface_decl(state, annot_pos, annotations);
2637
2606
  break;
2638
- case kMODULE:
2607
+ }
2608
+ case kMODULE: {
2639
2609
  decl = parse_module_decl(state, annot_pos, annotations);
2640
2610
  break;
2641
- case kCLASS:
2611
+ }
2612
+ case kCLASS: {
2642
2613
  decl = parse_class_decl(state, annot_pos, annotations);
2643
2614
  break;
2615
+ }
2644
2616
  default:
2645
2617
  raise_syntax_error(
2646
2618
  state,
@@ -2663,18 +2635,24 @@ static VALUE parse_decl(parserstate *state) {
2663
2635
  parser_advance(state);
2664
2636
  switch (state->current_token.type) {
2665
2637
  case tUIDENT:
2666
- case pCOLON2:
2638
+ case pCOLON2: {
2667
2639
  return parse_const_decl(state);
2668
- case tGIDENT:
2640
+ }
2641
+ case tGIDENT: {
2669
2642
  return parse_global_decl(state);
2670
- case kTYPE:
2643
+ }
2644
+ case kTYPE: {
2671
2645
  return parse_type_decl(state, annot_pos, annotations);
2672
- case kINTERFACE:
2646
+ }
2647
+ case kINTERFACE: {
2673
2648
  return parse_interface_decl(state, annot_pos, annotations);
2674
- case kMODULE:
2649
+ }
2650
+ case kMODULE: {
2675
2651
  return parse_module_decl(state, annot_pos, annotations);
2676
- case kCLASS:
2652
+ }
2653
+ case kCLASS: {
2677
2654
  return parse_class_decl(state, annot_pos, annotations);
2655
+ }
2678
2656
  default:
2679
2657
  raise_syntax_error(
2680
2658
  state,
@@ -2692,8 +2670,10 @@ static VALUE parse_namespace(parserstate *state, range *rg) {
2692
2670
  bool is_absolute = false;
2693
2671
 
2694
2672
  if (state->next_token.type == pCOLON2) {
2695
- rg->start = state->next_token.range.start;
2696
- rg->end = state->next_token.range.end;
2673
+ *rg = (range) {
2674
+ .start = state->next_token.range.start,
2675
+ .end = state->next_token.range.end,
2676
+ };
2697
2677
  is_absolute = true;
2698
2678
 
2699
2679
  parser_advance(state);
@@ -2731,8 +2711,6 @@ static void parse_use_clauses(parserstate *state, VALUE clauses) {
2731
2711
  range namespace_range = NULL_RANGE;
2732
2712
  VALUE namespace = parse_namespace(state, &namespace_range);
2733
2713
 
2734
- range clause_range = namespace_range;
2735
-
2736
2714
  switch (state->next_token.type)
2737
2715
  {
2738
2716
  case tLIDENT:
@@ -2742,14 +2720,9 @@ static void parse_use_clauses(parserstate *state, VALUE clauses) {
2742
2720
 
2743
2721
  enum TokenType ident_type = state->current_token.type;
2744
2722
 
2745
- range type_name_range;
2746
- if (null_range_p(namespace_range)) {
2747
- type_name_range = state->current_token.range;
2748
- } else {
2749
- type_name_range.start = namespace_range.start;
2750
- type_name_range.end = state->current_token.range.end;
2751
- }
2752
- clause_range = type_name_range;
2723
+ range type_name_range = null_range_p(namespace_range)
2724
+ ? state->current_token.range
2725
+ : (range) { .start = namespace_range.start, .end = state->current_token.range.end };
2753
2726
 
2754
2727
  VALUE type_name = rbs_type_name(namespace, ID2SYM(INTERN_TOKEN(state, state->current_token)));
2755
2728
 
@@ -2757,6 +2730,7 @@ static void parse_use_clauses(parserstate *state, VALUE clauses) {
2757
2730
  range new_name_range = NULL_RANGE;
2758
2731
 
2759
2732
  VALUE new_name = Qnil;
2733
+ range clause_range = type_name_range;
2760
2734
  if (state->next_token.type == kAS) {
2761
2735
  parser_advance(state);
2762
2736
  keyword_range = state->current_token.range;
@@ -2783,6 +2757,7 @@ static void parse_use_clauses(parserstate *state, VALUE clauses) {
2783
2757
  }
2784
2758
  case pSTAR:
2785
2759
  {
2760
+ range clause_range = namespace_range;
2786
2761
  parser_advance(state);
2787
2762
 
2788
2763
  range star_range = state->current_token.range;