rbs 1.6.2 → 1.7.0.beta.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +18 -3
  3. data/.gitignore +10 -1
  4. data/CHANGELOG.md +21 -6
  5. data/Gemfile +1 -0
  6. data/Rakefile +22 -22
  7. data/core/kernel.rbs +4 -4
  8. data/core/trace_point.rbs +1 -1
  9. data/ext/rbs_extension/constants.c +139 -0
  10. data/ext/rbs_extension/constants.h +72 -0
  11. data/ext/rbs_extension/extconf.rb +3 -0
  12. data/ext/rbs_extension/lexer.c +2533 -0
  13. data/ext/rbs_extension/lexer.h +161 -0
  14. data/ext/rbs_extension/lexer.re +140 -0
  15. data/ext/rbs_extension/lexstate.c +139 -0
  16. data/ext/rbs_extension/location.c +295 -0
  17. data/ext/rbs_extension/location.h +59 -0
  18. data/ext/rbs_extension/main.c +9 -0
  19. data/ext/rbs_extension/parser.c +2390 -0
  20. data/ext/rbs_extension/parser.h +18 -0
  21. data/ext/rbs_extension/parserstate.c +313 -0
  22. data/ext/rbs_extension/parserstate.h +141 -0
  23. data/ext/rbs_extension/rbs_extension.h +40 -0
  24. data/ext/rbs_extension/ruby_objs.c +521 -0
  25. data/ext/rbs_extension/ruby_objs.h +46 -0
  26. data/ext/rbs_extension/unescape.c +65 -0
  27. data/goodcheck.yml +1 -1
  28. data/lib/rbs/ast/comment.rb +0 -12
  29. data/lib/rbs/buffer.rb +4 -0
  30. data/lib/rbs/cli.rb +5 -8
  31. data/lib/rbs/collection/installer.rb +1 -0
  32. data/lib/rbs/collection/sources/git.rb +18 -3
  33. data/lib/rbs/errors.rb +28 -1
  34. data/lib/rbs/location.rb +221 -217
  35. data/lib/rbs/location_aux.rb +121 -0
  36. data/lib/rbs/locator.rb +10 -7
  37. data/lib/rbs/parser_aux.rb +63 -0
  38. data/lib/rbs/parser_compat/lexer_error.rb +4 -0
  39. data/lib/rbs/parser_compat/located_value.rb +5 -0
  40. data/lib/rbs/parser_compat/semantics_error.rb +4 -0
  41. data/lib/rbs/parser_compat/syntax_error.rb +4 -0
  42. data/lib/rbs/types.rb +2 -3
  43. data/lib/rbs/version.rb +1 -1
  44. data/lib/rbs/writer.rb +4 -2
  45. data/lib/rbs.rb +14 -7
  46. data/rbs.gemspec +2 -1
  47. data/sig/ancestor_builder.rbs +2 -2
  48. data/sig/annotation.rbs +2 -2
  49. data/sig/comment.rbs +7 -7
  50. data/sig/constant_table.rbs +1 -1
  51. data/sig/declarations.rbs +9 -9
  52. data/sig/definition.rbs +1 -1
  53. data/sig/definition_builder.rbs +2 -2
  54. data/sig/errors.rbs +40 -25
  55. data/sig/location.rbs +46 -78
  56. data/sig/locator.rbs +2 -2
  57. data/sig/members.rbs +7 -7
  58. data/sig/method_types.rbs +3 -3
  59. data/sig/parser.rbs +15 -20
  60. data/sig/rbs.rbs +4 -0
  61. data/sig/types.rbs +45 -27
  62. data/sig/writer.rbs +1 -1
  63. data/stdlib/io-console/0/io-console.rbs +137 -0
  64. data/stdlib/json/0/json.rbs +3 -3
  65. data/stdlib/net-http/0/net-http.rbs +2 -1
  66. data/stdlib/tempfile/0/tempfile.rbs +4 -6
  67. metadata +31 -6
  68. data/lib/rbs/parser.rb +0 -3614
@@ -0,0 +1,521 @@
1
+ #include "rbs_extension.h"
2
+
3
+ #ifdef RB_PASS_KEYWORDS
4
+ // Ruby 2.7 or later
5
+ #define CLASS_NEW_INSTANCE(klass, argc, argv)\
6
+ rb_class_new_instance_kw(argc, argv, klass, RB_PASS_KEYWORDS)
7
+ #else
8
+ // Ruby 2.6
9
+ #define CLASS_NEW_INSTANCE(receiver, argc, argv)\
10
+ rb_class_new_instance(argc, argv, receiver)
11
+ #endif
12
+
13
+ VALUE rbs_base_type(VALUE klass, VALUE location) {
14
+ VALUE args = rb_hash_new();
15
+ rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
16
+
17
+ return CLASS_NEW_INSTANCE(
18
+ klass,
19
+ 1,
20
+ &args
21
+ );
22
+ }
23
+
24
+ VALUE rbs_namespace(VALUE path, VALUE absolute) {
25
+ VALUE args = rb_hash_new();
26
+ rb_hash_aset(args, ID2SYM(rb_intern("path")), path);
27
+ rb_hash_aset(args, ID2SYM(rb_intern("absolute")), absolute);
28
+
29
+ return CLASS_NEW_INSTANCE(
30
+ RBS_Namespace,
31
+ 1,
32
+ &args
33
+ );
34
+ }
35
+
36
+ VALUE rbs_type_name(VALUE namespace, VALUE name) {
37
+ VALUE args = rb_hash_new();
38
+ rb_hash_aset(args, ID2SYM(rb_intern("namespace")), namespace);
39
+ rb_hash_aset(args, ID2SYM(rb_intern("name")), name);
40
+
41
+ return CLASS_NEW_INSTANCE(
42
+ RBS_TypeName,
43
+ 1,
44
+ &args
45
+ );
46
+ }
47
+
48
+ VALUE rbs_class_instance(VALUE typename, VALUE type_args, VALUE location) {
49
+ VALUE args = rb_hash_new();
50
+ rb_hash_aset(args, ID2SYM(rb_intern("name")), typename);
51
+ rb_hash_aset(args, ID2SYM(rb_intern("args")), type_args);
52
+ rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
53
+
54
+ return CLASS_NEW_INSTANCE(
55
+ RBS_Types_ClassInstance,
56
+ 1,
57
+ &args
58
+ );
59
+ }
60
+
61
+ VALUE rbs_class_singleton(VALUE typename, VALUE location) {
62
+ VALUE args = rb_hash_new();
63
+ rb_hash_aset(args, ID2SYM(rb_intern("name")), typename);
64
+ rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
65
+
66
+ return CLASS_NEW_INSTANCE(
67
+ RBS_Types_ClassSingleton,
68
+ 1,
69
+ &args
70
+ );
71
+ }
72
+
73
+ VALUE rbs_alias(VALUE typename, VALUE location) {
74
+ VALUE args = rb_hash_new();
75
+ rb_hash_aset(args, ID2SYM(rb_intern("name")), typename);
76
+ rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
77
+
78
+ return CLASS_NEW_INSTANCE(
79
+ RBS_Types_Alias,
80
+ 1,
81
+ &args
82
+ );
83
+ }
84
+
85
+ VALUE rbs_interface(VALUE typename, VALUE type_args, VALUE location) {
86
+ VALUE args = rb_hash_new();
87
+ rb_hash_aset(args, ID2SYM(rb_intern("name")), typename);
88
+ rb_hash_aset(args, ID2SYM(rb_intern("args")), type_args);
89
+ rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
90
+
91
+ return CLASS_NEW_INSTANCE(
92
+ RBS_Types_Interface,
93
+ 1,
94
+ &args
95
+ );
96
+ }
97
+
98
+ VALUE rbs_union(VALUE types, VALUE location) {
99
+ VALUE args = rb_hash_new();
100
+ rb_hash_aset(args, ID2SYM(rb_intern("types")), types);
101
+ rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
102
+
103
+ return CLASS_NEW_INSTANCE(
104
+ RBS_Types_Union,
105
+ 1,
106
+ &args
107
+ );
108
+ }
109
+
110
+ VALUE rbs_intersection(VALUE types, VALUE location) {
111
+ VALUE args = rb_hash_new();
112
+ rb_hash_aset(args, ID2SYM(rb_intern("types")), types);
113
+ rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
114
+
115
+ return CLASS_NEW_INSTANCE(
116
+ RBS_Types_Intersection,
117
+ 1,
118
+ &args
119
+ );
120
+ }
121
+
122
+ VALUE rbs_tuple(VALUE types, VALUE location) {
123
+ VALUE args = rb_hash_new();
124
+ rb_hash_aset(args, ID2SYM(rb_intern("types")), types);
125
+ rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
126
+
127
+ return CLASS_NEW_INSTANCE(
128
+ RBS_Types_Tuple,
129
+ 1,
130
+ &args
131
+ );
132
+ }
133
+
134
+ VALUE rbs_optional(VALUE type, VALUE location) {
135
+ VALUE args = rb_hash_new();
136
+ rb_hash_aset(args, ID2SYM(rb_intern("type")), type);
137
+ rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
138
+
139
+ return CLASS_NEW_INSTANCE(
140
+ RBS_Types_Optional,
141
+ 1,
142
+ &args
143
+ );
144
+ }
145
+
146
+ VALUE rbs_block(VALUE type, VALUE required) {
147
+ VALUE args = rb_hash_new();
148
+ rb_hash_aset(args, ID2SYM(rb_intern("type")), type);
149
+ rb_hash_aset(args, ID2SYM(rb_intern("required")), required);
150
+
151
+ return CLASS_NEW_INSTANCE(
152
+ RBS_Types_Block,
153
+ 1,
154
+ &args
155
+ );
156
+ }
157
+
158
+ VALUE rbs_function_param(VALUE type, VALUE name, VALUE location) {
159
+ VALUE args = rb_hash_new();
160
+ rb_hash_aset(args, ID2SYM(rb_intern("type")), type);
161
+ rb_hash_aset(args, ID2SYM(rb_intern("name")), name);
162
+ rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
163
+
164
+ return CLASS_NEW_INSTANCE(
165
+ RBS_Types_Function_Param,
166
+ 1,
167
+ &args
168
+ );
169
+ }
170
+
171
+ VALUE rbs_function(
172
+ VALUE required_positional_params,
173
+ VALUE optional_positional_params,
174
+ VALUE rest_positional_param,
175
+ VALUE trailing_positional_params,
176
+ VALUE required_keyword_params,
177
+ VALUE optional_keyword_params,
178
+ VALUE rest_keyword_param,
179
+ VALUE return_type
180
+ ) {
181
+ VALUE args = rb_hash_new();
182
+ rb_hash_aset(args, ID2SYM(rb_intern("required_positionals")), required_positional_params);
183
+ rb_hash_aset(args, ID2SYM(rb_intern("optional_positionals")), optional_positional_params);
184
+ rb_hash_aset(args, ID2SYM(rb_intern("rest_positionals")), rest_positional_param);
185
+ rb_hash_aset(args, ID2SYM(rb_intern("trailing_positionals")), trailing_positional_params);
186
+ rb_hash_aset(args, ID2SYM(rb_intern("required_keywords")), required_keyword_params);
187
+ rb_hash_aset(args, ID2SYM(rb_intern("optional_keywords")), optional_keyword_params);
188
+ rb_hash_aset(args, ID2SYM(rb_intern("rest_keywords")), rest_keyword_param);
189
+ rb_hash_aset(args, ID2SYM(rb_intern("return_type")), return_type);
190
+
191
+ return CLASS_NEW_INSTANCE(
192
+ RBS_Types_Function,
193
+ 1,
194
+ &args
195
+ );
196
+ }
197
+
198
+ VALUE rbs_proc(VALUE function, VALUE block, VALUE location) {
199
+ VALUE args = rb_hash_new();
200
+ rb_hash_aset(args, ID2SYM(rb_intern("type")), function);
201
+ rb_hash_aset(args, ID2SYM(rb_intern("block")), block);
202
+ rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
203
+
204
+ return CLASS_NEW_INSTANCE(
205
+ RBS_Types_Proc,
206
+ 1,
207
+ &args
208
+ );
209
+ }
210
+
211
+ VALUE rbs_void(VALUE location) {
212
+ VALUE args = rb_hash_new();
213
+ rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
214
+
215
+ return CLASS_NEW_INSTANCE(
216
+ RBS_Types_Bases_Void,
217
+ 1,
218
+ &args
219
+ );
220
+ }
221
+
222
+ VALUE rbs_literal(VALUE literal, VALUE location) {
223
+ VALUE args = rb_hash_new();
224
+ rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
225
+ rb_hash_aset(args, ID2SYM(rb_intern("literal")), literal);
226
+
227
+ return CLASS_NEW_INSTANCE(
228
+ RBS_Types_Literal,
229
+ 1,
230
+ &args
231
+ );
232
+ }
233
+
234
+ VALUE rbs_record(VALUE fields, VALUE location) {
235
+ VALUE args = rb_hash_new();
236
+ rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
237
+ rb_hash_aset(args, ID2SYM(rb_intern("fields")), fields);
238
+
239
+ return CLASS_NEW_INSTANCE(
240
+ RBS_Types_Record,
241
+ 1,
242
+ &args
243
+ );
244
+ }
245
+
246
+ VALUE rbs_variable(VALUE name, VALUE location) {
247
+ VALUE args = rb_hash_new();
248
+ rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
249
+ rb_hash_aset(args, ID2SYM(rb_intern("name")), name);
250
+
251
+ return CLASS_NEW_INSTANCE(
252
+ RBS_Types_Variable,
253
+ 1,
254
+ &args
255
+ );
256
+ }
257
+
258
+ VALUE rbs_method_type(VALUE type_params, VALUE type, VALUE block, VALUE location) {
259
+ VALUE args = rb_hash_new();
260
+ rb_hash_aset(args, ID2SYM(rb_intern("type_params")), type_params);
261
+ rb_hash_aset(args, ID2SYM(rb_intern("type")), type);
262
+ rb_hash_aset(args, ID2SYM(rb_intern("block")), block);
263
+ rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
264
+
265
+ return CLASS_NEW_INSTANCE(
266
+ RBS_MethodType,
267
+ 1,
268
+ &args
269
+ );
270
+ }
271
+
272
+ VALUE rbs_ast_comment(VALUE string, VALUE location) {
273
+ VALUE args = rb_hash_new();
274
+ rb_hash_aset(args, ID2SYM(rb_intern("string")), string);
275
+ rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
276
+
277
+ return CLASS_NEW_INSTANCE(
278
+ RBS_AST_Comment,
279
+ 1,
280
+ &args
281
+ );
282
+ }
283
+
284
+ VALUE rbs_ast_annotation(VALUE string, VALUE location) {
285
+ VALUE args = rb_hash_new();
286
+ rb_hash_aset(args, ID2SYM(rb_intern("string")), string);
287
+ rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
288
+
289
+ return CLASS_NEW_INSTANCE(
290
+ RBS_AST_Annotation,
291
+ 1,
292
+ &args
293
+ );
294
+ }
295
+
296
+ VALUE rbs_ast_decl_module_type_params() {
297
+ return rb_funcall(RBS_AST_Declarations_ModuleTypeParams, rb_intern("new"), 0);
298
+ }
299
+
300
+ VALUE rbs_ast_decl_module_type_params_param(VALUE name, VALUE variance, VALUE skip_validation, VALUE location) {
301
+ VALUE args = rb_hash_new();
302
+ rb_hash_aset(args, ID2SYM(rb_intern("name")), name);
303
+ rb_hash_aset(args, ID2SYM(rb_intern("variance")), variance);
304
+ rb_hash_aset(args, ID2SYM(rb_intern("skip_validation")), skip_validation);
305
+ rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
306
+
307
+ return CLASS_NEW_INSTANCE(
308
+ RBS_AST_Declarations_ModuleTypeParams_TypeParam,
309
+ 1,
310
+ &args
311
+ );
312
+ }
313
+
314
+ VALUE rbs_ast_decl_constant(VALUE name, VALUE type, VALUE location, VALUE comment) {
315
+ VALUE args = rb_hash_new();
316
+ rb_hash_aset(args, ID2SYM(rb_intern("name")), name);
317
+ rb_hash_aset(args, ID2SYM(rb_intern("type")), type);
318
+ rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
319
+ rb_hash_aset(args, ID2SYM(rb_intern("comment")), comment);
320
+
321
+ return CLASS_NEW_INSTANCE(
322
+ RBS_AST_Declarations_Constant,
323
+ 1,
324
+ &args
325
+ );
326
+ }
327
+
328
+ VALUE rbs_ast_decl_global(VALUE name, VALUE type, VALUE location, VALUE comment) {
329
+ VALUE args = rb_hash_new();
330
+ rb_hash_aset(args, ID2SYM(rb_intern("name")), name);
331
+ rb_hash_aset(args, ID2SYM(rb_intern("type")), type);
332
+ rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
333
+ rb_hash_aset(args, ID2SYM(rb_intern("comment")), comment);
334
+
335
+ return CLASS_NEW_INSTANCE(
336
+ RBS_AST_Declarations_Global,
337
+ 1,
338
+ &args
339
+ );
340
+ }
341
+
342
+ VALUE rbs_ast_decl_alias(VALUE name, VALUE type, VALUE annotations, VALUE location, VALUE comment) {
343
+ VALUE args = rb_hash_new();
344
+ rb_hash_aset(args, ID2SYM(rb_intern("name")), name);
345
+ rb_hash_aset(args, ID2SYM(rb_intern("type")), type);
346
+ rb_hash_aset(args, ID2SYM(rb_intern("annotations")), annotations);
347
+ rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
348
+ rb_hash_aset(args, ID2SYM(rb_intern("comment")), comment);
349
+
350
+ return CLASS_NEW_INSTANCE(
351
+ RBS_AST_Declarations_Alias,
352
+ 1,
353
+ &args
354
+ );
355
+ }
356
+
357
+ VALUE rbs_ast_decl_interface(VALUE name, VALUE type_params, VALUE members, VALUE annotations, VALUE location, VALUE comment) {
358
+ VALUE args = rb_hash_new();
359
+ rb_hash_aset(args, ID2SYM(rb_intern("name")), name);
360
+ rb_hash_aset(args, ID2SYM(rb_intern("type_params")), type_params);
361
+ rb_hash_aset(args, ID2SYM(rb_intern("members")), members);
362
+ rb_hash_aset(args, ID2SYM(rb_intern("annotations")), annotations);
363
+ rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
364
+ rb_hash_aset(args, ID2SYM(rb_intern("comment")), comment);
365
+
366
+ return CLASS_NEW_INSTANCE(
367
+ RBS_AST_Declarations_Interface,
368
+ 1,
369
+ &args
370
+ );
371
+ }
372
+
373
+ VALUE rbs_ast_decl_module_self(VALUE name, VALUE args, VALUE location) {
374
+ VALUE kw_args = rb_hash_new();
375
+ rb_hash_aset(kw_args, ID2SYM(rb_intern("name")), name);
376
+ rb_hash_aset(kw_args, ID2SYM(rb_intern("args")), args);
377
+ rb_hash_aset(kw_args, ID2SYM(rb_intern("location")), location);
378
+
379
+ return CLASS_NEW_INSTANCE(
380
+ RBS_AST_Declarations_Module_Self,
381
+ 1,
382
+ &kw_args
383
+ );
384
+ }
385
+
386
+ VALUE rbs_ast_decl_module(VALUE name, VALUE type_params, VALUE self_types, VALUE members, VALUE annotations, VALUE location, VALUE comment) {
387
+ VALUE args = rb_hash_new();
388
+ rb_hash_aset(args, ID2SYM(rb_intern("name")), name);
389
+ rb_hash_aset(args, ID2SYM(rb_intern("type_params")), type_params);
390
+ rb_hash_aset(args, ID2SYM(rb_intern("self_types")), self_types);
391
+ rb_hash_aset(args, ID2SYM(rb_intern("members")), members);
392
+ rb_hash_aset(args, ID2SYM(rb_intern("annotations")), annotations);
393
+ rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
394
+ rb_hash_aset(args, ID2SYM(rb_intern("comment")), comment);
395
+
396
+ return CLASS_NEW_INSTANCE(
397
+ RBS_AST_Declarations_Module,
398
+ 1,
399
+ &args
400
+ );
401
+ }
402
+
403
+ VALUE rbs_ast_members_method_definition(VALUE name, VALUE kind, VALUE types, VALUE annotations, VALUE location, VALUE comment, VALUE overload) {
404
+ VALUE args = rb_hash_new();
405
+ rb_hash_aset(args, ID2SYM(rb_intern("name")), name);
406
+ rb_hash_aset(args, ID2SYM(rb_intern("kind")), kind);
407
+ rb_hash_aset(args, ID2SYM(rb_intern("types")), types);
408
+ rb_hash_aset(args, ID2SYM(rb_intern("annotations")), annotations);
409
+ rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
410
+ rb_hash_aset(args, ID2SYM(rb_intern("comment")), comment);
411
+ rb_hash_aset(args, ID2SYM(rb_intern("overload")), overload);
412
+
413
+ return CLASS_NEW_INSTANCE(
414
+ RBS_AST_Members_MethodDefinition,
415
+ 1,
416
+ &args
417
+ );
418
+ }
419
+
420
+ VALUE rbs_ast_members_variable(VALUE klass, VALUE name, VALUE type, VALUE location, VALUE comment) {
421
+ VALUE args = rb_hash_new();
422
+ rb_hash_aset(args, ID2SYM(rb_intern("name")), name);
423
+ rb_hash_aset(args, ID2SYM(rb_intern("type")), type);
424
+ rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
425
+ rb_hash_aset(args, ID2SYM(rb_intern("comment")), comment);
426
+
427
+ return CLASS_NEW_INSTANCE(
428
+ klass,
429
+ 1,
430
+ &args
431
+ );
432
+ }
433
+
434
+ VALUE rbs_ast_members_mixin(VALUE klass, VALUE name, VALUE module_args, VALUE annotations, VALUE location, VALUE comment) {
435
+ VALUE args = rb_hash_new();
436
+ rb_hash_aset(args, ID2SYM(rb_intern("name")), name);
437
+ rb_hash_aset(args, ID2SYM(rb_intern("args")), module_args);
438
+ rb_hash_aset(args, ID2SYM(rb_intern("annotations")), annotations);
439
+ rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
440
+ rb_hash_aset(args, ID2SYM(rb_intern("comment")), comment);
441
+
442
+ return CLASS_NEW_INSTANCE(
443
+ klass,
444
+ 1,
445
+ &args
446
+ );
447
+ }
448
+
449
+ VALUE rbs_ast_members_attribute(VALUE klass, VALUE name, VALUE type, VALUE ivar_name, VALUE kind, VALUE annotations, VALUE location, VALUE comment) {
450
+ VALUE args = rb_hash_new();
451
+ rb_hash_aset(args, ID2SYM(rb_intern("name")), name);
452
+ rb_hash_aset(args, ID2SYM(rb_intern("type")), type);
453
+ rb_hash_aset(args, ID2SYM(rb_intern("ivar_name")), ivar_name);
454
+ rb_hash_aset(args, ID2SYM(rb_intern("kind")), kind);
455
+ rb_hash_aset(args, ID2SYM(rb_intern("annotations")), annotations);
456
+ rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
457
+ rb_hash_aset(args, ID2SYM(rb_intern("comment")), comment);
458
+
459
+ return CLASS_NEW_INSTANCE(
460
+ klass,
461
+ 1,
462
+ &args
463
+ );
464
+ }
465
+
466
+ VALUE rbs_ast_members_visibility(VALUE klass, VALUE location) {
467
+ VALUE args = rb_hash_new();
468
+ rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
469
+
470
+ return CLASS_NEW_INSTANCE(
471
+ klass,
472
+ 1,
473
+ &args
474
+ );
475
+ }
476
+
477
+ VALUE rbs_ast_members_alias(VALUE new_name, VALUE old_name, VALUE kind, VALUE annotations, VALUE location, VALUE comment) {
478
+ VALUE args = rb_hash_new();
479
+ rb_hash_aset(args, ID2SYM(rb_intern("new_name")), new_name);
480
+ rb_hash_aset(args, ID2SYM(rb_intern("old_name")), old_name);
481
+ rb_hash_aset(args, ID2SYM(rb_intern("kind")), kind);
482
+ rb_hash_aset(args, ID2SYM(rb_intern("annotations")), annotations);
483
+ rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
484
+ rb_hash_aset(args, ID2SYM(rb_intern("comment")), comment);
485
+
486
+ return CLASS_NEW_INSTANCE(
487
+ RBS_AST_Members_Alias,
488
+ 1,
489
+ &args
490
+ );
491
+ }
492
+
493
+ VALUE rbs_ast_decl_class_super(VALUE name, VALUE args, VALUE location) {
494
+ VALUE kwargs = rb_hash_new();
495
+ rb_hash_aset(kwargs, ID2SYM(rb_intern("name")), name);
496
+ rb_hash_aset(kwargs, ID2SYM(rb_intern("args")), args);
497
+ rb_hash_aset(kwargs, ID2SYM(rb_intern("location")), location);
498
+
499
+ return CLASS_NEW_INSTANCE(
500
+ RBS_AST_Declarations_Class_Super,
501
+ 1,
502
+ &kwargs
503
+ );
504
+ }
505
+
506
+ VALUE rbs_ast_decl_class(VALUE name, VALUE type_params, VALUE super_class, VALUE members, VALUE annotations, VALUE location, VALUE comment) {
507
+ VALUE kwargs = rb_hash_new();
508
+ rb_hash_aset(kwargs, ID2SYM(rb_intern("name")), name);
509
+ rb_hash_aset(kwargs, ID2SYM(rb_intern("type_params")), type_params);
510
+ rb_hash_aset(kwargs, ID2SYM(rb_intern("super_class")), super_class);
511
+ rb_hash_aset(kwargs, ID2SYM(rb_intern("members")), members);
512
+ rb_hash_aset(kwargs, ID2SYM(rb_intern("annotations")), annotations);
513
+ rb_hash_aset(kwargs, ID2SYM(rb_intern("location")), location);
514
+ rb_hash_aset(kwargs, ID2SYM(rb_intern("comment")), comment);
515
+
516
+ return CLASS_NEW_INSTANCE(
517
+ RBS_AST_Declarations_Class,
518
+ 1,
519
+ &kwargs
520
+ );
521
+ }
@@ -0,0 +1,46 @@
1
+ #ifndef RBS__RUBY_OBJS_H
2
+ #define RBS__RUBY_OBJS_H
3
+
4
+ #include "ruby.h"
5
+
6
+ VALUE rbs_alias(VALUE typename, VALUE location);
7
+ VALUE rbs_ast_annotation(VALUE string, VALUE location);
8
+ VALUE rbs_ast_comment(VALUE string, VALUE location);
9
+ VALUE rbs_ast_decl_alias(VALUE name, VALUE type, VALUE annotations, VALUE location, VALUE comment);
10
+ VALUE rbs_ast_decl_class_super(VALUE name, VALUE args, VALUE location);
11
+ VALUE rbs_ast_decl_class(VALUE name, VALUE type_params, VALUE super_class, VALUE members, VALUE annotations, VALUE location, VALUE comment);
12
+ VALUE rbs_ast_decl_constant(VALUE name, VALUE type, VALUE location, VALUE comment);
13
+ VALUE rbs_ast_decl_global(VALUE name, VALUE type, VALUE location, VALUE comment);
14
+ VALUE rbs_ast_decl_interface(VALUE name, VALUE type_params, VALUE members, VALUE annotations, VALUE location, VALUE comment);
15
+ VALUE rbs_ast_decl_module_self(VALUE name, VALUE args, VALUE location);
16
+ VALUE rbs_ast_decl_module_type_params_param(VALUE name, VALUE variance, VALUE skip_validation, VALUE location);
17
+ VALUE rbs_ast_decl_module_type_params();
18
+ VALUE rbs_ast_decl_module(VALUE name, VALUE type_params, VALUE self_types, VALUE members, VALUE annotations, VALUE location, VALUE comment);
19
+ VALUE rbs_ast_members_alias(VALUE new_name, VALUE old_name, VALUE kind, VALUE annotations, VALUE location, VALUE comment);
20
+ VALUE rbs_ast_members_attribute(VALUE klass, VALUE name, VALUE type, VALUE ivar_name, VALUE kind, VALUE annotations, VALUE location, VALUE comment);
21
+ VALUE rbs_ast_members_method_definition(VALUE name, VALUE kind, VALUE types, VALUE annotations, VALUE location, VALUE comment, VALUE overload);
22
+ VALUE rbs_ast_members_mixin(VALUE klass, VALUE name, VALUE args, VALUE annotations, VALUE location, VALUE comment);
23
+ VALUE rbs_ast_members_variable(VALUE klass, VALUE name, VALUE type, VALUE location, VALUE comment);
24
+ VALUE rbs_ast_members_visibility(VALUE klass, VALUE location);
25
+ VALUE rbs_base_type(VALUE klass, VALUE location);
26
+ VALUE rbs_block(VALUE type, VALUE required);
27
+ VALUE rbs_class_instance(VALUE typename, VALUE type_args, VALUE location);
28
+ VALUE rbs_class_singleton(VALUE typename, VALUE location);
29
+ VALUE rbs_function_param(VALUE type, VALUE name, VALUE location);
30
+ VALUE rbs_function(VALUE required_positional_params, VALUE optional_positional_params, VALUE rest_positional_params, VALUE trailing_positional_params, VALUE required_keywords, VALUE optional_keywords, VALUE rest_keywords, VALUE return_type);
31
+ VALUE rbs_interface(VALUE typename, VALUE type_args, VALUE location);
32
+ VALUE rbs_intersection(VALUE types, VALUE location);
33
+ VALUE rbs_literal(VALUE literal, VALUE location);
34
+ VALUE rbs_method_type(VALUE type_params, VALUE type, VALUE block, VALUE location);
35
+ VALUE rbs_namespace(VALUE path, VALUE absolute);
36
+ VALUE rbs_optional(VALUE type, VALUE location);
37
+ VALUE rbs_proc(VALUE function, VALUE block, VALUE location);
38
+ VALUE rbs_record(VALUE fields, VALUE location);
39
+ VALUE rbs_tuple(VALUE types, VALUE location);
40
+ VALUE rbs_type_name(VALUE namespace, VALUE name);
41
+ VALUE rbs_union(VALUE types, VALUE location);
42
+ VALUE rbs_variable(VALUE name, VALUE location);
43
+
44
+ void pp(VALUE object);
45
+
46
+ #endif
@@ -0,0 +1,65 @@
1
+ #include "rbs_extension.h"
2
+
3
+ static VALUE REGEXP = 0;
4
+ static VALUE HASH = 0;
5
+
6
+ static const char *regexp_str = "\\\\[abefnrstv\"]";
7
+
8
+ static ID gsub = 0;
9
+
10
+ void rbs_unescape_string(VALUE string) {
11
+ if (!REGEXP) {
12
+ REGEXP = rb_reg_new(regexp_str, strlen(regexp_str), 0);
13
+ rb_global_variable(&REGEXP);
14
+ }
15
+
16
+ if (!gsub) {
17
+ gsub = rb_intern("gsub!");
18
+ }
19
+
20
+ if (!HASH) {
21
+ HASH = rb_hash_new();
22
+ rb_hash_aset(HASH, rb_str_new_literal("\\a"), rb_str_new_literal("\a"));
23
+ rb_hash_aset(HASH, rb_str_new_literal("\\b"), rb_str_new_literal("\b"));
24
+ rb_hash_aset(HASH, rb_str_new_literal("\\e"), rb_str_new_literal("\e"));
25
+ rb_hash_aset(HASH, rb_str_new_literal("\\f"), rb_str_new_literal("\f"));
26
+ rb_hash_aset(HASH, rb_str_new_literal("\\n"), rb_str_new_literal("\n"));
27
+ rb_hash_aset(HASH, rb_str_new_literal("\\r"), rb_str_new_literal("\r"));
28
+ rb_hash_aset(HASH, rb_str_new_literal("\\s"), rb_str_new_literal(" "));
29
+ rb_hash_aset(HASH, rb_str_new_literal("\\t"), rb_str_new_literal("\t"));
30
+ rb_hash_aset(HASH, rb_str_new_literal("\\v"), rb_str_new_literal("\v"));
31
+ rb_hash_aset(HASH, rb_str_new_literal("\\\""), rb_str_new_literal("\""));
32
+ rb_global_variable(&HASH);
33
+ }
34
+
35
+ rb_funcall(string, gsub, 2, REGEXP, HASH);
36
+ }
37
+
38
+ VALUE rbs_unquote_string(parserstate *state, range rg, int offset_bytes) {
39
+ VALUE string = state->lexstate->string;
40
+ rb_encoding *enc = rb_enc_get(string);
41
+
42
+ unsigned int first_char = rb_enc_mbc_to_codepoint(
43
+ RSTRING_PTR(string) + rg.start.byte_pos + offset_bytes,
44
+ RSTRING_END(string),
45
+ enc
46
+ );
47
+
48
+ int byte_length = rg.end.byte_pos - rg.start.byte_pos - offset_bytes;
49
+
50
+ if (first_char == '"' || first_char == '\'' || first_char == '`') {
51
+ int bs = rb_enc_codelen(first_char, enc);
52
+ offset_bytes += bs;
53
+ byte_length -= 2 * bs;
54
+ }
55
+
56
+ char *buffer = RSTRING_PTR(state->lexstate->string) + rg.start.byte_pos + offset_bytes;
57
+ VALUE str = rb_enc_str_new(buffer, byte_length, enc);
58
+
59
+ if (first_char == '\"') {
60
+ rbs_unescape_string(str);
61
+ }
62
+
63
+ return str;
64
+ }
65
+
data/goodcheck.yml CHANGED
@@ -40,7 +40,7 @@ rules:
40
40
  glob:
41
41
  - "**/*.rbs"
42
42
  justification:
43
- - When you strictly want `true | false`.
43
+ - When you strictly want `true | false`. Use `bool` in this case.
44
44
  pass:
45
45
  - "(arg: boolish)"
46
46
  - "{ () -> boolish }"
@@ -22,18 +22,6 @@ module RBS
22
22
  def to_json(state = _ = nil)
23
23
  { string: string, location: location }.to_json(state)
24
24
  end
25
-
26
- def concat(string:, location:)
27
- @string.concat string
28
-
29
- if loc = @location
30
- loc.concat location
31
- else
32
- @location = location
33
- end
34
-
35
- self
36
- end
37
25
  end
38
26
  end
39
27
  end
data/lib/rbs/buffer.rb CHANGED
@@ -46,5 +46,9 @@ module RBS
46
46
  def last_position
47
47
  content.size
48
48
  end
49
+
50
+ def inspect
51
+ "#<RBS::Buffer:#{__id__} @name=#{name}, @content=#{content.bytesize} bytes, @lines=#{lines.size} lines,>"
52
+ end
49
53
  end
50
54
  end
data/lib/rbs/cli.rb CHANGED
@@ -749,14 +749,11 @@ Examples:
749
749
  args.each do |path|
750
750
  path = Pathname(path)
751
751
  loader.each_file(path, skip_hidden: false, immediate: true) do |file_path|
752
- Parser.parse_signature(file_path.read)
753
- rescue RBS::Parser::SyntaxError => ex
754
- loc = ex.error_value.location
755
- stdout.puts "#{file_path}:#{loc.start_line}:#{loc.start_column}: parse error on value: (#{ex.token_str})"
756
- syntax_error = true
757
- rescue RBS::Parser::SemanticsError => ex
758
- loc = ex.location
759
- stdout.puts "#{file_path}:#{loc.start_line}:#{loc.start_column}: #{ex.original_message}"
752
+ RBS.logger.info "Parsing #{file_path}..."
753
+ buffer = Buffer.new(content: file_path.read, name: file_path)
754
+ Parser.parse_signature(buffer)
755
+ rescue RBS::ParsingError => ex
756
+ stdout.puts ex.message
760
757
  syntax_error = true
761
758
  end
762
759
  end
@@ -11,6 +11,7 @@ module RBS
11
11
 
12
12
  def install_from_lockfile
13
13
  install_to = lockfile.repo_path
14
+ install_to.mkpath
14
15
  lockfile.gems.each do |config_entry|
15
16
  source_for(config_entry).install(dest: install_to, config_entry: config_entry, stdout: stdout)
16
17
  end