rbs 3.9.2 → 4.0.0.dev.1

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 (115) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -1
  3. data/.github/workflows/windows.yml +1 -1
  4. data/CHANGELOG.md +0 -13
  5. data/Rakefile +28 -21
  6. data/Steepfile +1 -0
  7. data/config.yml +232 -62
  8. data/ext/rbs_extension/ast_translation.c +1149 -0
  9. data/ext/rbs_extension/ast_translation.h +30 -0
  10. data/{src/constants.c → ext/rbs_extension/class_constants.c} +15 -1
  11. data/{include/rbs/constants.h → ext/rbs_extension/class_constants.h} +10 -1
  12. data/ext/rbs_extension/extconf.rb +3 -1
  13. data/ext/rbs_extension/{location.c → legacy_location.c} +25 -34
  14. data/ext/rbs_extension/legacy_location.h +40 -0
  15. data/ext/rbs_extension/main.c +402 -8
  16. data/ext/rbs_extension/rbs_extension.h +3 -21
  17. data/ext/rbs_extension/rbs_string_bridging.c +9 -0
  18. data/ext/rbs_extension/rbs_string_bridging.h +20 -0
  19. data/include/rbs/ast.h +748 -0
  20. data/include/rbs/defines.h +60 -0
  21. data/{ext/rbs_extension → include/rbs}/lexer.h +40 -32
  22. data/include/rbs/location.h +59 -0
  23. data/include/rbs/parser.h +151 -0
  24. data/include/rbs/string.h +49 -0
  25. data/include/rbs/util/rbs_allocator.h +38 -0
  26. data/include/rbs/util/rbs_assert.h +9 -0
  27. data/include/rbs/util/rbs_buffer.h +83 -0
  28. data/include/rbs/util/rbs_constant_pool.h +3 -64
  29. data/include/rbs/util/rbs_encoding.h +280 -0
  30. data/include/rbs/util/rbs_unescape.h +23 -0
  31. data/include/rbs.h +1 -2
  32. data/lib/rbs/annotate/formatter.rb +3 -13
  33. data/lib/rbs/annotate/rdoc_annotator.rb +3 -1
  34. data/lib/rbs/annotate/rdoc_source.rb +1 -1
  35. data/lib/rbs/ast/ruby/annotations.rb +119 -0
  36. data/lib/rbs/ast/ruby/comment_block.rb +221 -0
  37. data/lib/rbs/ast/ruby/declarations.rb +86 -0
  38. data/lib/rbs/ast/ruby/helpers/constant_helper.rb +24 -0
  39. data/lib/rbs/ast/ruby/helpers/location_helper.rb +15 -0
  40. data/lib/rbs/ast/ruby/members.rb +213 -0
  41. data/lib/rbs/buffer.rb +104 -24
  42. data/lib/rbs/cli/validate.rb +39 -34
  43. data/lib/rbs/cli.rb +4 -5
  44. data/lib/rbs/definition.rb +6 -1
  45. data/lib/rbs/definition_builder/ancestor_builder.rb +63 -60
  46. data/lib/rbs/definition_builder/method_builder.rb +45 -30
  47. data/lib/rbs/definition_builder.rb +44 -9
  48. data/lib/rbs/environment/class_entry.rb +69 -0
  49. data/lib/rbs/environment/module_entry.rb +66 -0
  50. data/lib/rbs/environment.rb +185 -154
  51. data/lib/rbs/environment_loader.rb +2 -2
  52. data/lib/rbs/errors.rb +4 -3
  53. data/lib/rbs/inline_parser/comment_association.rb +117 -0
  54. data/lib/rbs/inline_parser.rb +206 -0
  55. data/lib/rbs/location_aux.rb +35 -3
  56. data/lib/rbs/parser_aux.rb +11 -1
  57. data/lib/rbs/prototype/runtime.rb +2 -2
  58. data/lib/rbs/source.rb +99 -0
  59. data/lib/rbs/subtractor.rb +4 -3
  60. data/lib/rbs/version.rb +1 -1
  61. data/lib/rbs.rb +12 -0
  62. data/lib/rdoc/discover.rb +1 -1
  63. data/lib/rdoc_plugin/parser.rb +2 -2
  64. data/rbs.gemspec +1 -0
  65. data/sig/ancestor_builder.rbs +1 -1
  66. data/sig/annotate/formatter.rbs +2 -2
  67. data/sig/annotate/rdoc_annotater.rbs +1 -1
  68. data/sig/ast/ruby/annotations.rbs +110 -0
  69. data/sig/ast/ruby/comment_block.rbs +119 -0
  70. data/sig/ast/ruby/declarations.rbs +60 -0
  71. data/sig/ast/ruby/helpers/constant_helper.rbs +11 -0
  72. data/sig/ast/ruby/helpers/location_helper.rbs +15 -0
  73. data/sig/ast/ruby/members.rbs +72 -0
  74. data/sig/buffer.rbs +63 -5
  75. data/sig/definition.rbs +1 -0
  76. data/sig/definition_builder.rbs +1 -1
  77. data/sig/environment/class_entry.rbs +50 -0
  78. data/sig/environment/module_entry.rbs +50 -0
  79. data/sig/environment.rbs +22 -76
  80. data/sig/errors.rbs +13 -6
  81. data/sig/inline_parser/comment_association.rbs +71 -0
  82. data/sig/inline_parser.rbs +87 -0
  83. data/sig/location.rbs +32 -7
  84. data/sig/method_builder.rbs +7 -4
  85. data/sig/parser.rbs +16 -0
  86. data/sig/source.rbs +48 -0
  87. data/src/ast.c +1345 -0
  88. data/src/lexer.c +2867 -0
  89. data/src/lexer.re +151 -0
  90. data/{ext/rbs_extension → src}/lexstate.c +58 -42
  91. data/src/location.c +71 -0
  92. data/src/parser.c +3739 -0
  93. data/src/string.c +89 -0
  94. data/src/util/rbs_allocator.c +149 -0
  95. data/src/util/rbs_assert.c +19 -0
  96. data/src/util/rbs_buffer.c +54 -0
  97. data/src/util/rbs_constant_pool.c +13 -81
  98. data/src/util/rbs_encoding.c +5273 -0
  99. data/src/util/rbs_unescape.c +130 -0
  100. data/stdlib/rdoc/0/code_object.rbs +2 -2
  101. data/stdlib/rdoc/0/comment.rbs +2 -0
  102. data/stdlib/rdoc/0/options.rbs +76 -0
  103. data/stdlib/rdoc/0/rdoc.rbs +6 -4
  104. data/stdlib/rdoc/0/store.rbs +1 -1
  105. metadata +70 -17
  106. data/ext/rbs_extension/lexer.c +0 -2728
  107. data/ext/rbs_extension/lexer.re +0 -147
  108. data/ext/rbs_extension/location.h +0 -85
  109. data/ext/rbs_extension/parser.c +0 -2982
  110. data/ext/rbs_extension/parser.h +0 -18
  111. data/ext/rbs_extension/parserstate.c +0 -411
  112. data/ext/rbs_extension/parserstate.h +0 -163
  113. data/ext/rbs_extension/unescape.c +0 -32
  114. data/include/rbs/ruby_objs.h +0 -72
  115. data/src/ruby_objs.c +0 -799
@@ -1,18 +0,0 @@
1
- #ifndef RBS__PARSER_H
2
- #define RBS__PARSER_H
3
-
4
- #include "ruby.h"
5
- #include "parserstate.h"
6
-
7
- /**
8
- * RBS::Parser class
9
- * */
10
- extern VALUE RBS_Parser;
11
-
12
- VALUE parse_type(parserstate *state);
13
- VALUE parse_method_type(parserstate *state);
14
- VALUE parse_signature(parserstate *state);
15
-
16
- void rbs__init_parser();
17
-
18
- #endif
@@ -1,411 +0,0 @@
1
- #include "rbs_extension.h"
2
- #include "rbs/util/rbs_constant_pool.h"
3
-
4
- #define RESET_TABLE_P(table) (table->size == 0)
5
-
6
- id_table *alloc_empty_table(void) {
7
- id_table *table = malloc(sizeof(id_table));
8
-
9
- *table = (id_table) {
10
- .size = 10,
11
- .count = 0,
12
- .ids = calloc(10, sizeof(rbs_constant_id_t)),
13
- .next = NULL,
14
- };
15
-
16
- return table;
17
- }
18
-
19
- id_table *alloc_reset_table(void) {
20
- id_table *table = malloc(sizeof(id_table));
21
-
22
- *table = (id_table) {
23
- .size = 0,
24
- .count = 0,
25
- .ids = NULL,
26
- .next = NULL,
27
- };
28
-
29
- return table;
30
- }
31
-
32
- id_table *parser_push_typevar_table(parserstate *state, bool reset) {
33
- if (reset) {
34
- id_table *table = alloc_reset_table();
35
- table->next = state->vars;
36
- state->vars = table;
37
- }
38
-
39
- id_table *table = alloc_empty_table();
40
- table->next = state->vars;
41
- state->vars = table;
42
-
43
- return table;
44
- }
45
-
46
- void parser_pop_typevar_table(parserstate *state) {
47
- id_table *table;
48
-
49
- if (state->vars) {
50
- table = state->vars;
51
- state->vars = table->next;
52
- free(table->ids);
53
- free(table);
54
- } else {
55
- rb_raise(rb_eRuntimeError, "Cannot pop empty table");
56
- }
57
-
58
- if (state->vars && RESET_TABLE_P(state->vars)) {
59
- table = state->vars;
60
- state->vars = table->next;
61
- free(table);
62
- }
63
- }
64
-
65
- void parser_insert_typevar(parserstate *state, rbs_constant_id_t id) {
66
- id_table *table = state->vars;
67
-
68
- if (RESET_TABLE_P(table)) {
69
- rb_raise(rb_eRuntimeError, "Cannot insert to reset table");
70
- }
71
-
72
- if (table->size == table->count) {
73
- // expand
74
- rbs_constant_id_t *ptr = table->ids;
75
- table->size += 10;
76
- table->ids = calloc(table->size, sizeof(rbs_constant_id_t));
77
- memcpy(table->ids, ptr, sizeof(rbs_constant_id_t) * table->count);
78
- free(ptr);
79
- }
80
-
81
- table->ids[table->count++] = id;
82
- }
83
-
84
- bool parser_typevar_member(parserstate *state, rbs_constant_id_t id) {
85
- id_table *table = state->vars;
86
-
87
- while (table && !RESET_TABLE_P(table)) {
88
- for (size_t i = 0; i < table->count; i++) {
89
- if (table->ids[i] == id) {
90
- return true;
91
- }
92
- }
93
-
94
- table = table->next;
95
- }
96
-
97
- return false;
98
- }
99
-
100
- void print_parser(parserstate *state) {
101
- printf(" current_token = %s (%d...%d)\n", token_type_str(state->current_token.type), state->current_token.range.start.char_pos, state->current_token.range.end.char_pos);
102
- printf(" next_token = %s (%d...%d)\n", token_type_str(state->next_token.type), state->next_token.range.start.char_pos, state->next_token.range.end.char_pos);
103
- printf(" next_token2 = %s (%d...%d)\n", token_type_str(state->next_token2.type), state->next_token2.range.start.char_pos, state->next_token2.range.end.char_pos);
104
- printf(" next_token3 = %s (%d...%d)\n", token_type_str(state->next_token3.type), state->next_token3.range.start.char_pos, state->next_token3.range.end.char_pos);
105
- }
106
-
107
- void parser_advance(parserstate *state) {
108
- state->current_token = state->next_token;
109
- state->next_token = state->next_token2;
110
- state->next_token2 = state->next_token3;
111
-
112
- while (true) {
113
- if (state->next_token3.type == pEOF) {
114
- break;
115
- }
116
-
117
- state->next_token3 = rbsparser_next_token(state->lexstate);
118
-
119
- if (state->next_token3.type == tCOMMENT) {
120
- // skip
121
- } else if (state->next_token3.type == tLINECOMMENT) {
122
- insert_comment_line(state, state->next_token3);
123
- } else if (state->next_token3.type == tTRIVIA) {
124
- //skip
125
- } else {
126
- break;
127
- }
128
- }
129
- }
130
-
131
- /**
132
- * Advance token if _next_ token is `type`.
133
- * Ensures one token advance and `state->current_token.type == type`, or current token not changed.
134
- *
135
- * @returns true if token advances, false otherwise.
136
- **/
137
- bool parser_advance_if(parserstate *state, enum TokenType type) {
138
- if (state->next_token.type == type) {
139
- parser_advance(state);
140
- return true;
141
- } else {
142
- return false;
143
- }
144
- }
145
-
146
- void parser_assert(parserstate *state, enum TokenType type) {
147
- if (state->current_token.type != type) {
148
- raise_syntax_error(
149
- state,
150
- state->current_token,
151
- "expected a token `%s`",
152
- token_type_str(type)
153
- );
154
- }
155
- }
156
-
157
- void parser_advance_assert(parserstate *state, enum TokenType type) {
158
- parser_advance(state);
159
- parser_assert(state, type);
160
- }
161
-
162
- void print_token(token tok) {
163
- printf(
164
- "%s char=%d...%d\n",
165
- token_type_str(tok.type),
166
- tok.range.start.char_pos,
167
- tok.range.end.char_pos
168
- );
169
- }
170
-
171
- void insert_comment_line(parserstate *state, token tok) {
172
- int prev_line = tok.range.start.line - 1;
173
-
174
- comment *com = comment_get_comment(state->last_comment, prev_line);
175
-
176
- if (com) {
177
- comment_insert_new_line(com, tok);
178
- } else {
179
- state->last_comment = alloc_comment(tok, state->last_comment);
180
- }
181
- }
182
-
183
- VALUE get_comment(parserstate *state, int subject_line) {
184
- int comment_line = subject_line - 1;
185
-
186
- comment *com = comment_get_comment(state->last_comment, comment_line);
187
-
188
- if (com) {
189
- return comment_to_ruby(com, state->buffer);
190
- } else {
191
- return Qnil;
192
- }
193
- }
194
-
195
- comment *alloc_comment(token comment_token, comment *last_comment) {
196
- comment *new_comment = malloc(sizeof(comment));
197
-
198
- *new_comment = (comment) {
199
- .start = comment_token.range.start,
200
- .end = comment_token.range.end,
201
-
202
- .line_size = 0,
203
- .line_count = 0,
204
- .tokens = NULL,
205
-
206
- .next_comment = last_comment,
207
- };
208
-
209
- comment_insert_new_line(new_comment, comment_token);
210
-
211
- return new_comment;
212
- }
213
-
214
- void free_comment(comment *com) {
215
- if (com->next_comment) {
216
- free_comment(com->next_comment);
217
- }
218
-
219
- free(com->tokens);
220
- free(com);
221
- }
222
-
223
- void comment_insert_new_line(comment *com, token comment_token) {
224
- if (com->line_count == 0) {
225
- com->start = comment_token.range.start;
226
- }
227
-
228
- if (com->line_count == com->line_size) {
229
- com->line_size += 10;
230
-
231
- if (com->tokens) {
232
- token *p = com->tokens;
233
- com->tokens = calloc(com->line_size, sizeof(token));
234
- memcpy(com->tokens, p, sizeof(token) * com->line_count);
235
- free(p);
236
- } else {
237
- com->tokens = calloc(com->line_size, sizeof(token));
238
- }
239
- }
240
-
241
- com->tokens[com->line_count++] = comment_token;
242
- com->end = comment_token.range.end;
243
- }
244
-
245
- comment *comment_get_comment(comment *com, int line) {
246
- if (com == NULL) {
247
- return NULL;
248
- }
249
-
250
- if (com->end.line < line) {
251
- return NULL;
252
- }
253
-
254
- if (com->end.line == line) {
255
- return com;
256
- }
257
-
258
- return comment_get_comment(com->next_comment, line);
259
- }
260
-
261
- VALUE comment_to_ruby(comment *com, VALUE buffer) {
262
- VALUE content = rb_funcall(buffer, rb_intern("content"), 0);
263
- rb_encoding *enc = rb_enc_get(content);
264
- VALUE string = rb_enc_str_new_cstr("", enc);
265
-
266
- int hash_bytes = rb_enc_codelen('#', enc);
267
- int space_bytes = rb_enc_codelen(' ', enc);
268
-
269
- for (size_t i = 0; i < com->line_count; i++) {
270
- token tok = com->tokens[i];
271
-
272
- char *comment_start = RSTRING_PTR(content) + tok.range.start.byte_pos + hash_bytes;
273
- int comment_bytes = RANGE_BYTES(tok.range) - hash_bytes;
274
- unsigned char c = rb_enc_mbc_to_codepoint(comment_start, RSTRING_END(content), enc);
275
-
276
- if (c == ' ') {
277
- comment_start += space_bytes;
278
- comment_bytes -= space_bytes;
279
- }
280
-
281
- rb_str_cat(string, comment_start, comment_bytes);
282
- rb_str_cat_cstr(string, "\n");
283
- }
284
-
285
- return rbs_ast_comment(
286
- string,
287
- rbs_location_pp(buffer, &com->start, &com->end)
288
- );
289
- }
290
-
291
- lexstate *alloc_lexer(VALUE string, int start_pos, int end_pos) {
292
- if (start_pos < 0 || end_pos < 0) {
293
- rb_raise(rb_eArgError, "negative position range: %d...%d", start_pos, end_pos);
294
- }
295
-
296
- lexstate *lexer = malloc(sizeof(lexstate));
297
-
298
- position start_position = (position) {
299
- .byte_pos = 0,
300
- .char_pos = 0,
301
- .line = 1,
302
- .column = 0,
303
- };
304
-
305
- *lexer = (lexstate) {
306
- .string = string,
307
- .start_pos = start_pos,
308
- .end_pos = end_pos,
309
- .current = start_position,
310
- .start = { 0 },
311
- .first_token_of_line = false,
312
- .last_char = 0,
313
- };
314
-
315
- skipn(lexer, start_pos);
316
- lexer->start = lexer->current;
317
- lexer->first_token_of_line = lexer->current.column == 0;
318
-
319
- return lexer;
320
- }
321
-
322
- parserstate *alloc_parser(VALUE buffer, lexstate *lexer, int start_pos, int end_pos, VALUE variables) {
323
- parserstate *parser = malloc(sizeof(parserstate));
324
-
325
- *parser = (parserstate) {
326
- .lexstate = lexer,
327
-
328
- .current_token = NullToken,
329
- .next_token = NullToken,
330
- .next_token2 = NullToken,
331
- .next_token3 = NullToken,
332
- .buffer = buffer,
333
-
334
- .vars = NULL,
335
- .last_comment = NULL,
336
-
337
- .constant_pool = { 0 },
338
- };
339
-
340
- // The parser's constant pool is mainly used for storing the names of type variables, which usually aren't many.
341
- // Below are some statistics gathered from the current test suite. We can see that 56% of parsers never add to their
342
- // constant pool at all. The initial capacity needs to be a power of 2. Picking 2 means that we won't need to realloc
343
- // in 85% of cases.
344
- //
345
- // TODO: recalculate these statistics based on a real world codebase, rather than the test suite.
346
- //
347
- // | Size | Count | Cumulative | % Coverage |
348
- // |------|-------|------------|------------|
349
- // | 0 | 7,862 | 7,862 | 56% |
350
- // | 1 | 3,196 | 11,058 | 79% |
351
- // | 2 | 778 | 12,719 | 85% |
352
- // | 3 | 883 | 11,941 | 91% |
353
- // | 4 | 478 | 13,197 | 95% |
354
- // | 5 | 316 | 13,513 | 97% |
355
- // | 6 | 288 | 13,801 | 99% |
356
- // | 7 | 144 | 13,945 | 100% |
357
- const size_t initial_pool_capacity = 2;
358
- rbs_constant_pool_init(&parser->constant_pool, initial_pool_capacity);
359
-
360
- parser_advance(parser);
361
- parser_advance(parser);
362
- parser_advance(parser);
363
-
364
- if (!NIL_P(variables)) {
365
- if (!RB_TYPE_P(variables, T_ARRAY)) {
366
- free_parser(parser);
367
- rb_raise(rb_eTypeError,
368
- "wrong argument type %"PRIsVALUE" (must be array or nil)",
369
- rb_obj_class(variables));
370
- }
371
-
372
- parser_push_typevar_table(parser, true);
373
-
374
- for (long i = 0; i < rb_array_len(variables); i++) {
375
- VALUE symbol = rb_ary_entry(variables, i);
376
- VALUE name = rb_sym2str(symbol);
377
-
378
- rbs_constant_id_t id = rbs_constant_pool_insert_shared(
379
- &parser->constant_pool,
380
- (const uint8_t *) RSTRING_PTR(name),
381
- RSTRING_LEN(name)
382
- );
383
-
384
- parser_insert_typevar(parser, id);
385
- }
386
- }
387
-
388
- return parser;
389
- }
390
-
391
- void free_typevar_tables(id_table *table) {
392
- while (table != NULL) {
393
- id_table *next = table->next;
394
- if (table->ids != NULL) {
395
- free(table->ids);
396
- }
397
- free(table);
398
- table = next;
399
- }
400
- }
401
-
402
- void free_parser(parserstate *parser) {
403
- free(parser->lexstate);
404
- if (parser->last_comment) {
405
- free_comment(parser->last_comment);
406
- }
407
-
408
- free_typevar_tables(parser->vars);
409
- rbs_constant_pool_free(&parser->constant_pool);
410
- free(parser);
411
- }
@@ -1,163 +0,0 @@
1
- #ifndef RBS__PARSERSTATE_H
2
- #define RBS__PARSERSTATE_H
3
-
4
- #include <stdbool.h>
5
-
6
- #include "lexer.h"
7
- #include "location.h"
8
-
9
- /**
10
- * id_table represents a set of RBS constant IDs.
11
- * This is used to manage the set of bound variables.
12
- * */
13
- typedef struct id_table {
14
- size_t size;
15
- size_t count;
16
- rbs_constant_id_t *ids;
17
- struct id_table *next;
18
- } id_table;
19
-
20
- /**
21
- * comment represents a sequence of comment lines.
22
- *
23
- * # Comment for the method.
24
- * #
25
- * # ```rb
26
- * # object.foo() # Do something
27
- * # ```
28
- * #
29
- * def foo: () -> void
30
- *
31
- * A comment object represents the six lines of comments.
32
- * */
33
- typedef struct comment {
34
- position start;
35
- position end;
36
-
37
- size_t line_size;
38
- size_t line_count;
39
- token *tokens;
40
-
41
- struct comment *next_comment;
42
- } comment;
43
-
44
- /**
45
- * An RBS parser is a LL(3) parser.
46
- * */
47
- typedef struct {
48
- lexstate *lexstate;
49
-
50
- token current_token;
51
- token next_token; /* The first lookahead token */
52
- token next_token2; /* The second lookahead token */
53
- token next_token3; /* The third lookahead token */
54
- VALUE buffer;
55
-
56
- id_table *vars; /* Known type variables */
57
- comment *last_comment; /* Last read comment */
58
-
59
- rbs_constant_pool_t constant_pool;
60
- } parserstate;
61
-
62
- comment *alloc_comment(token comment_token, comment *last_comment);
63
- void free_comment(comment *com);
64
- void comment_insert_new_line(comment *com, token comment_token);
65
- comment *comment_get_comment(comment *com, int line);
66
- VALUE comment_to_ruby(comment *com, VALUE buffer);
67
-
68
- /**
69
- * Insert new table entry.
70
- * Setting `reset` inserts a _reset_ entry, which stops searching.
71
- *
72
- * ```
73
- * class Foo[A]
74
- * ^^^ <= push new table with reset
75
- * def foo: [B] () -> [A, B]
76
- * ^^^ <= push new table without reset
77
- *
78
- * class Baz[C]
79
- * ^^^ <= push new table with reset
80
- * end
81
- * end
82
- * ```
83
- * */
84
- id_table *parser_push_typevar_table(parserstate *state, bool reset);
85
- void parser_pop_typevar_table(parserstate *state);
86
- /**
87
- * Insert new type variable into the latest table.
88
- * */
89
- void parser_insert_typevar(parserstate *state, rbs_constant_id_t id);
90
-
91
- /**
92
- * Returns true if given type variable is recorded in the table.
93
- * If not found, it goes one table up, if it's not a reset table.
94
- * Or returns false, if it's a reset table.
95
- * */
96
- bool parser_typevar_member(parserstate *state, rbs_constant_id_t id);
97
-
98
- /**
99
- * Allocate new lexstate object.
100
- *
101
- * ```
102
- * VALUE string = rb_funcall(buffer, rb_intern("content"), 0);
103
- * alloc_lexer(string, 0, 31) // New lexstate with buffer content
104
- * ```
105
- * */
106
- lexstate *alloc_lexer(VALUE string, int start_pos, int end_pos);
107
-
108
- /**
109
- * Allocate new parserstate object.
110
- *
111
- * ```
112
- * alloc_parser(buffer, lexer, 0, 1, variables) // New parserstate with variables
113
- * alloc_parser(buffer, lexer, 3, 5, Qnil) // New parserstate without variables
114
- * ```
115
- * */
116
- parserstate *alloc_parser(VALUE buffer, lexstate *lexer, int start_pos, int end_pos, VALUE variables);
117
- void free_parser(parserstate *parser);
118
- /**
119
- * Advance one token.
120
- * */
121
- void parser_advance(parserstate *state);
122
-
123
- /**
124
- * @brief Raises an exception if `current_token->type != type`.
125
- *
126
- * @param state
127
- * @param type
128
- */
129
- void parser_assert(parserstate *state, enum TokenType type);
130
-
131
- /**
132
- * Advance one token, and assert the current token type.
133
- * Raises an exception if `current_token->type != type`.
134
- * */
135
- void parser_advance_assert(parserstate *state, enum TokenType type);
136
-
137
- /**
138
- * Advance one token if the next_token is a token of the type.
139
- * */
140
- bool parser_advance_if(parserstate *state, enum TokenType type);
141
- void print_parser(parserstate *state);
142
-
143
- /**
144
- * Insert new comment line token.
145
- * */
146
- void insert_comment_line(parserstate *state, token token);
147
-
148
- /**
149
- * Returns a RBS::Comment object associated with an subject at `subject_line`.
150
- *
151
- * ```rbs
152
- * # Comment1
153
- * class Foo # This is the subject line for Comment1
154
- *
155
- * # Comment2
156
- * %a{annotation} # This is the subject line for Comment2
157
- * def foo: () -> void
158
- * end
159
- * ```
160
- * */
161
- VALUE get_comment(parserstate *state, int subject_line);
162
-
163
- #endif
@@ -1,32 +0,0 @@
1
- #include "rbs_extension.h"
2
-
3
- VALUE rbs_unquote_string(parserstate *state, range rg, int offset_bytes) {
4
- VALUE string = state->lexstate->string;
5
- rb_encoding *enc = rb_enc_get(string);
6
-
7
- unsigned int first_char = rb_enc_mbc_to_codepoint(
8
- RSTRING_PTR(string) + rg.start.byte_pos + offset_bytes,
9
- RSTRING_END(string),
10
- enc
11
- );
12
-
13
- int byte_length = rg.end.byte_pos - rg.start.byte_pos - offset_bytes;
14
-
15
- if (first_char == '"' || first_char == '\'' || first_char == '`') {
16
- int bs = rb_enc_codelen(first_char, enc);
17
- offset_bytes += bs;
18
- byte_length -= 2 * bs;
19
- }
20
-
21
- char *buffer = RSTRING_PTR(state->lexstate->string) + rg.start.byte_pos + offset_bytes;
22
- VALUE str = rb_enc_str_new(buffer, byte_length, enc);
23
-
24
- return rb_funcall(
25
- RBS_Types_Literal,
26
- rb_intern("unescape_string"),
27
- 2,
28
- str,
29
- first_char == '\"' ? Qtrue : Qfalse
30
- );
31
- }
32
-
@@ -1,72 +0,0 @@
1
- /*----------------------------------------------------------------------------*/
2
- /* This file is generated by the templates/template.rb script and should not */
3
- /* be modified manually. */
4
- /* To change the template see */
5
- /* templates/include/rbs/ruby_objs.h.erb */
6
- /*----------------------------------------------------------------------------*/
7
-
8
- #ifndef RBS__RUBY_OBJS_H
9
- #define RBS__RUBY_OBJS_H
10
-
11
- #include "ruby.h"
12
-
13
- VALUE rbs_ast_annotation(VALUE string, VALUE location);
14
- VALUE rbs_ast_comment(VALUE string, VALUE location);
15
- VALUE rbs_ast_decl_class(VALUE name, VALUE type_params, VALUE super_class, VALUE members, VALUE annotations, VALUE location, VALUE comment);
16
- VALUE rbs_ast_decl_class_super(VALUE name, VALUE args, VALUE location);
17
- VALUE rbs_ast_decl_class_alias(VALUE new_name, VALUE old_name, VALUE location, VALUE comment, VALUE annotations);
18
- VALUE rbs_ast_decl_constant(VALUE name, VALUE type, VALUE location, VALUE comment, VALUE annotations);
19
- VALUE rbs_ast_decl_global(VALUE name, VALUE type, VALUE location, VALUE comment, VALUE annotations);
20
- VALUE rbs_ast_decl_interface(VALUE name, VALUE type_params, VALUE members, VALUE annotations, VALUE location, VALUE comment);
21
- VALUE rbs_ast_decl_module(VALUE name, VALUE type_params, VALUE self_types, VALUE members, VALUE annotations, VALUE location, VALUE comment);
22
- VALUE rbs_ast_decl_module_self(VALUE name, VALUE args, VALUE location);
23
- VALUE rbs_ast_decl_module_alias(VALUE new_name, VALUE old_name, VALUE location, VALUE comment, VALUE annotations);
24
- VALUE rbs_ast_decl_type_alias(VALUE name, VALUE type_params, VALUE type, VALUE annotations, VALUE location, VALUE comment);
25
- VALUE rbs_ast_directives_use(VALUE clauses, VALUE location);
26
- VALUE rbs_ast_directives_use_single_clause(VALUE type_name, VALUE new_name, VALUE location);
27
- VALUE rbs_ast_directives_use_wildcard_clause(VALUE namespace, VALUE location);
28
- VALUE rbs_ast_members_alias(VALUE new_name, VALUE old_name, VALUE kind, VALUE annotations, VALUE location, VALUE comment);
29
- VALUE rbs_ast_members_attr_accessor(VALUE name, VALUE type, VALUE ivar_name, VALUE kind, VALUE annotations, VALUE location, VALUE comment, VALUE visibility);
30
- VALUE rbs_ast_members_attr_reader(VALUE name, VALUE type, VALUE ivar_name, VALUE kind, VALUE annotations, VALUE location, VALUE comment, VALUE visibility);
31
- VALUE rbs_ast_members_attr_writer(VALUE name, VALUE type, VALUE ivar_name, VALUE kind, VALUE annotations, VALUE location, VALUE comment, VALUE visibility);
32
- VALUE rbs_ast_members_class_instance_variable(VALUE name, VALUE type, VALUE location, VALUE comment);
33
- VALUE rbs_ast_members_class_variable(VALUE name, VALUE type, VALUE location, VALUE comment);
34
- VALUE rbs_ast_members_extend(VALUE name, VALUE args, VALUE annotations, VALUE location, VALUE comment);
35
- VALUE rbs_ast_members_include(VALUE name, VALUE args, VALUE annotations, VALUE location, VALUE comment);
36
- VALUE rbs_ast_members_instance_variable(VALUE name, VALUE type, VALUE location, VALUE comment);
37
- VALUE rbs_ast_members_method_definition(VALUE name, VALUE kind, VALUE overloads, VALUE annotations, VALUE location, VALUE comment, VALUE overloading, VALUE visibility);
38
- VALUE rbs_ast_members_method_definition_overload(VALUE annotations, VALUE method_type);
39
- VALUE rbs_ast_members_prepend(VALUE name, VALUE args, VALUE annotations, VALUE location, VALUE comment);
40
- VALUE rbs_ast_members_private(VALUE location);
41
- VALUE rbs_ast_members_public(VALUE location);
42
- VALUE rbs_ast_type_param(VALUE name, VALUE variance, VALUE upper_bound, VALUE default_type, VALUE unchecked, VALUE location);
43
- VALUE rbs_method_type(VALUE type_params, VALUE type, VALUE block, VALUE location);
44
- VALUE rbs_namespace(VALUE path, VALUE absolute);
45
- VALUE rbs_type_name(VALUE namespace, VALUE name);
46
- VALUE rbs_alias(VALUE name, VALUE args, VALUE location);
47
- VALUE rbs_bases_any(VALUE todo, VALUE location);
48
- VALUE rbs_bases_bool(VALUE location);
49
- VALUE rbs_bases_bottom(VALUE location);
50
- VALUE rbs_bases_class(VALUE location);
51
- VALUE rbs_bases_instance(VALUE location);
52
- VALUE rbs_bases_nil(VALUE location);
53
- VALUE rbs_bases_self(VALUE location);
54
- VALUE rbs_bases_top(VALUE location);
55
- VALUE rbs_bases_void(VALUE location);
56
- VALUE rbs_block(VALUE type, VALUE required, VALUE self_type);
57
- VALUE rbs_class_instance(VALUE name, VALUE args, VALUE location);
58
- VALUE rbs_class_singleton(VALUE name, VALUE location);
59
- VALUE rbs_function(VALUE required_positionals, VALUE optional_positionals, VALUE rest_positionals, VALUE trailing_positionals, VALUE required_keywords, VALUE optional_keywords, VALUE rest_keywords, VALUE return_type);
60
- VALUE rbs_function_param(VALUE type, VALUE name, VALUE location);
61
- VALUE rbs_interface(VALUE name, VALUE args, VALUE location);
62
- VALUE rbs_intersection(VALUE types, VALUE location);
63
- VALUE rbs_literal(VALUE literal, VALUE location);
64
- VALUE rbs_optional(VALUE type, VALUE location);
65
- VALUE rbs_proc(VALUE type, VALUE block, VALUE location, VALUE self_type);
66
- VALUE rbs_record(VALUE all_fields, VALUE location);
67
- VALUE rbs_tuple(VALUE types, VALUE location);
68
- VALUE rbs_union(VALUE types, VALUE location);
69
- VALUE rbs_untyped_function(VALUE return_type);
70
- VALUE rbs_variable(VALUE name, VALUE location);
71
-
72
- #endif