rbs 4.0.0.dev.5 → 4.0.1.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.
- checksums.yaml +4 -4
- data/.clang-format +1 -0
- data/.github/workflows/c-check.yml +8 -4
- data/.github/workflows/comments.yml +3 -1
- data/.github/workflows/dependabot.yml +1 -1
- data/.github/workflows/ruby.yml +10 -0
- data/.github/workflows/rust.yml +95 -0
- data/CHANGELOG.md +323 -0
- data/Rakefile +12 -29
- data/Steepfile +1 -0
- data/config.yml +393 -37
- data/core/array.rbs +218 -188
- data/core/basic_object.rbs +9 -8
- data/core/class.rbs +6 -5
- data/core/comparable.rbs +45 -31
- data/core/complex.rbs +52 -40
- data/core/dir.rbs +57 -45
- data/core/encoding.rbs +5 -5
- data/core/enumerable.rbs +96 -91
- data/core/enumerator.rbs +4 -3
- data/core/errno.rbs +3 -2
- data/core/errors.rbs +31 -29
- data/core/exception.rbs +12 -12
- data/core/fiber.rbs +36 -36
- data/core/file.rbs +186 -113
- data/core/file_test.rbs +2 -2
- data/core/float.rbs +41 -32
- data/core/gc.rbs +78 -70
- data/core/hash.rbs +70 -60
- data/core/integer.rbs +32 -28
- data/core/io/buffer.rbs +36 -36
- data/core/io/wait.rbs +7 -7
- data/core/io.rbs +120 -135
- data/core/kernel.rbs +189 -139
- data/core/marshal.rbs +3 -3
- data/core/match_data.rbs +14 -12
- data/core/math.rbs +69 -67
- data/core/method.rbs +6 -6
- data/core/module.rbs +146 -85
- data/core/nil_class.rbs +4 -3
- data/core/numeric.rbs +35 -32
- data/core/object.rbs +6 -8
- data/core/object_space.rbs +11 -10
- data/core/pathname.rbs +131 -81
- data/core/proc.rbs +65 -33
- data/core/process.rbs +219 -201
- data/core/ractor.rbs +15 -11
- data/core/random.rbs +4 -3
- data/core/range.rbs +52 -47
- data/core/rational.rbs +5 -5
- data/core/rbs/unnamed/argf.rbs +58 -51
- data/core/rbs/unnamed/env_class.rbs +18 -13
- data/core/rbs/unnamed/main_class.rbs +123 -0
- data/core/rbs/unnamed/random.rbs +7 -5
- data/core/regexp.rbs +236 -197
- data/core/ruby.rbs +1 -1
- data/core/ruby_vm.rbs +32 -30
- data/core/rubygems/config_file.rbs +5 -5
- data/core/rubygems/errors.rbs +1 -1
- data/core/rubygems/requirement.rbs +5 -5
- data/core/rubygems/rubygems.rbs +5 -3
- data/core/set.rbs +17 -16
- data/core/signal.rbs +2 -2
- data/core/string.rbs +311 -292
- data/core/struct.rbs +26 -25
- data/core/symbol.rbs +25 -24
- data/core/thread.rbs +40 -34
- data/core/time.rbs +47 -42
- data/core/trace_point.rbs +34 -31
- data/core/true_class.rbs +2 -2
- data/core/unbound_method.rbs +10 -10
- data/core/warning.rbs +7 -7
- data/docs/collection.md +1 -1
- data/docs/config.md +171 -0
- data/docs/inline.md +110 -4
- data/docs/syntax.md +13 -12
- data/ext/rbs_extension/ast_translation.c +489 -135
- data/ext/rbs_extension/class_constants.c +8 -0
- data/ext/rbs_extension/class_constants.h +4 -0
- data/ext/rbs_extension/legacy_location.c +28 -51
- data/ext/rbs_extension/legacy_location.h +37 -0
- data/ext/rbs_extension/main.c +12 -20
- data/include/rbs/ast.h +423 -195
- data/include/rbs/lexer.h +2 -2
- data/include/rbs/location.h +25 -44
- data/include/rbs/parser.h +2 -2
- data/include/rbs/util/rbs_constant_pool.h +0 -3
- data/include/rbs.h +8 -0
- data/lib/rbs/ast/ruby/annotations.rb +157 -4
- data/lib/rbs/ast/ruby/members.rb +374 -22
- data/lib/rbs/cli/validate.rb +5 -60
- data/lib/rbs/collection/config/lockfile_generator.rb +6 -2
- data/lib/rbs/definition_builder.rb +60 -27
- data/lib/rbs/errors.rb +0 -11
- data/lib/rbs/inline_parser.rb +1 -1
- data/lib/rbs/parser_aux.rb +20 -7
- data/lib/rbs/prototype/helpers.rb +57 -0
- data/lib/rbs/prototype/rb.rb +1 -26
- data/lib/rbs/prototype/rbi.rb +1 -20
- data/lib/rbs/test/type_check.rb +3 -0
- data/lib/rbs/types.rb +62 -52
- data/lib/rbs/unit_test/type_assertions.rb +35 -8
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs.rb +0 -1
- data/rbs.gemspec +1 -1
- data/rust/.gitignore +1 -0
- data/rust/Cargo.lock +378 -0
- data/rust/Cargo.toml +7 -0
- data/rust/ruby-rbs/Cargo.toml +22 -0
- data/rust/ruby-rbs/build.rs +764 -0
- data/rust/ruby-rbs/examples/locations.rs +60 -0
- data/rust/ruby-rbs/src/lib.rs +1 -0
- data/rust/ruby-rbs/src/node/mod.rs +742 -0
- data/rust/ruby-rbs/tests/sanity.rs +47 -0
- data/rust/ruby-rbs/vendor/rbs/config.yml +1 -0
- data/rust/ruby-rbs-sys/Cargo.toml +23 -0
- data/rust/ruby-rbs-sys/build.rs +204 -0
- data/rust/ruby-rbs-sys/src/lib.rs +50 -0
- data/rust/ruby-rbs-sys/vendor/rbs/include +1 -0
- data/rust/ruby-rbs-sys/vendor/rbs/src +1 -0
- data/rust/ruby-rbs-sys/wrapper.h +1 -0
- data/sig/ast/ruby/annotations.rbs +191 -4
- data/sig/ast/ruby/members.rbs +21 -1
- data/sig/cli/validate.rbs +1 -6
- data/sig/definition_builder.rbs +2 -0
- data/sig/errors.rbs +0 -8
- data/sig/method_types.rbs +1 -1
- data/sig/parser.rbs +17 -13
- data/sig/prototype/helpers.rbs +2 -0
- data/sig/types.rbs +10 -11
- data/sig/unit_test/spy.rbs +0 -8
- data/sig/unit_test/type_assertions.rbs +11 -0
- data/src/ast.c +339 -161
- data/src/lexstate.c +1 -1
- data/src/location.c +7 -47
- data/src/parser.c +674 -480
- data/src/util/rbs_constant_pool.c +0 -4
- data/stdlib/bigdecimal/0/big_decimal.rbs +16 -16
- data/stdlib/cgi-escape/0/escape.rbs +4 -4
- data/stdlib/coverage/0/coverage.rbs +4 -3
- data/stdlib/date/0/date.rbs +33 -28
- data/stdlib/date/0/date_time.rbs +24 -23
- data/stdlib/did_you_mean/0/did_you_mean.rbs +17 -16
- data/stdlib/erb/0/erb.rbs +64 -53
- data/stdlib/etc/0/etc.rbs +55 -50
- data/stdlib/fileutils/0/fileutils.rbs +138 -125
- data/stdlib/forwardable/0/forwardable.rbs +10 -10
- data/stdlib/io-console/0/io-console.rbs +2 -2
- data/stdlib/json/0/json.rbs +135 -108
- data/stdlib/monitor/0/monitor.rbs +3 -3
- data/stdlib/net-http/0/net-http.rbs +159 -134
- data/stdlib/objspace/0/objspace.rbs +8 -7
- data/stdlib/open-uri/0/open-uri.rbs +8 -8
- data/stdlib/open3/0/open3.rbs +36 -35
- data/stdlib/openssl/0/openssl.rbs +144 -129
- data/stdlib/optparse/0/optparse.rbs +18 -14
- data/stdlib/pathname/0/pathname.rbs +2 -2
- data/stdlib/pp/0/pp.rbs +9 -8
- data/stdlib/prettyprint/0/prettyprint.rbs +7 -7
- data/stdlib/pstore/0/pstore.rbs +35 -30
- data/stdlib/psych/0/psych.rbs +61 -8
- data/stdlib/psych/0/store.rbs +2 -4
- data/stdlib/pty/0/pty.rbs +9 -6
- data/stdlib/random-formatter/0/random-formatter.rbs +2 -2
- data/stdlib/ripper/0/ripper.rbs +20 -17
- data/stdlib/securerandom/0/securerandom.rbs +1 -1
- data/stdlib/shellwords/0/shellwords.rbs +2 -2
- data/stdlib/socket/0/addrinfo.rbs +7 -7
- data/stdlib/socket/0/basic_socket.rbs +3 -3
- data/stdlib/socket/0/ip_socket.rbs +10 -8
- data/stdlib/socket/0/socket.rbs +10 -9
- data/stdlib/socket/0/tcp_server.rbs +1 -1
- data/stdlib/socket/0/tcp_socket.rbs +1 -1
- data/stdlib/socket/0/udp_socket.rbs +1 -1
- data/stdlib/socket/0/unix_server.rbs +1 -1
- data/stdlib/stringio/0/stringio.rbs +55 -54
- data/stdlib/strscan/0/string_scanner.rbs +46 -44
- data/stdlib/tempfile/0/tempfile.rbs +24 -20
- data/stdlib/time/0/time.rbs +7 -5
- data/stdlib/tsort/0/tsort.rbs +7 -6
- data/stdlib/uri/0/common.rbs +26 -18
- data/stdlib/uri/0/file.rbs +2 -2
- data/stdlib/uri/0/generic.rbs +2 -2
- data/stdlib/uri/0/http.rbs +2 -2
- data/stdlib/uri/0/ldap.rbs +2 -2
- data/stdlib/uri/0/mailto.rbs +3 -3
- data/stdlib/uri/0/rfc2396_parser.rbs +6 -5
- data/stdlib/zlib/0/deflate.rbs +4 -3
- data/stdlib/zlib/0/gzip_reader.rbs +4 -4
- data/stdlib/zlib/0/gzip_writer.rbs +14 -12
- data/stdlib/zlib/0/inflate.rbs +1 -1
- data/stdlib/zlib/0/need_dict.rbs +1 -1
- metadata +23 -5
- data/.github/workflows/valgrind.yml +0 -42
data/src/parser.c
CHANGED
|
@@ -6,20 +6,15 @@
|
|
|
6
6
|
#include <ctype.h>
|
|
7
7
|
#include <string.h>
|
|
8
8
|
|
|
9
|
+
#include "rbs/ast.h"
|
|
9
10
|
#include "rbs/defines.h"
|
|
10
11
|
#include "rbs/lexer.h"
|
|
12
|
+
#include "rbs/location.h"
|
|
11
13
|
#include "rbs/string.h"
|
|
12
14
|
#include "rbs/util/rbs_unescape.h"
|
|
13
15
|
#include "rbs/util/rbs_buffer.h"
|
|
14
16
|
#include "rbs/util/rbs_assert.h"
|
|
15
17
|
|
|
16
|
-
#define INTERN(str) \
|
|
17
|
-
rbs_constant_pool_insert_constant( \
|
|
18
|
-
RBS_GLOBAL_CONSTANT_POOL, \
|
|
19
|
-
(const uint8_t *) str, \
|
|
20
|
-
strlen(str) \
|
|
21
|
-
)
|
|
22
|
-
|
|
23
18
|
#define INTERN_TOKEN(parser, tok) \
|
|
24
19
|
rbs_constant_pool_insert_shared_with_encoding( \
|
|
25
20
|
&parser->constant_pool, \
|
|
@@ -65,6 +60,41 @@
|
|
|
65
60
|
case kRETURN: \
|
|
66
61
|
/* nop */
|
|
67
62
|
|
|
63
|
+
#define PARAM_NAME_CASES \
|
|
64
|
+
case kBOOL: \
|
|
65
|
+
case kBOT: \
|
|
66
|
+
case kCLASS: \
|
|
67
|
+
case kFALSE: \
|
|
68
|
+
case kINSTANCE: \
|
|
69
|
+
case kINTERFACE: \
|
|
70
|
+
case kNIL: \
|
|
71
|
+
case kSELF: \
|
|
72
|
+
case kSINGLETON: \
|
|
73
|
+
case kTOP: \
|
|
74
|
+
case kTRUE: \
|
|
75
|
+
case kVOID: \
|
|
76
|
+
case kTYPE: \
|
|
77
|
+
case kUNCHECKED: \
|
|
78
|
+
case kIN: \
|
|
79
|
+
case kOUT: \
|
|
80
|
+
case kEND: \
|
|
81
|
+
case kDEF: \
|
|
82
|
+
case kINCLUDE: \
|
|
83
|
+
case kEXTEND: \
|
|
84
|
+
case kPREPEND: \
|
|
85
|
+
case kALIAS: \
|
|
86
|
+
case kMODULE: \
|
|
87
|
+
case kATTRREADER: \
|
|
88
|
+
case kATTRWRITER: \
|
|
89
|
+
case kATTRACCESSOR: \
|
|
90
|
+
case kPUBLIC: \
|
|
91
|
+
case kPRIVATE: \
|
|
92
|
+
case kUNTYPED: \
|
|
93
|
+
case kUSE: \
|
|
94
|
+
case kAS: \
|
|
95
|
+
case k__TODO__: \
|
|
96
|
+
/* nop */
|
|
97
|
+
|
|
68
98
|
#define CHECK_PARSE(call) \
|
|
69
99
|
if (!call) { \
|
|
70
100
|
return false; \
|
|
@@ -111,18 +141,12 @@ static bool rbs_is_untyped_params(method_params *params) {
|
|
|
111
141
|
return params->required_positionals == NULL;
|
|
112
142
|
}
|
|
113
143
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
*
|
|
117
|
-
* @param parser
|
|
118
|
-
* @return New RBS::Location object.
|
|
119
|
-
* */
|
|
120
|
-
static rbs_location_t *rbs_location_current_token(rbs_parser_t *parser) {
|
|
121
|
-
return rbs_location_new(ALLOCATOR(), parser->current_token.range);
|
|
144
|
+
static rbs_location_range rbs_location_range_current_token(rbs_parser_t *parser) {
|
|
145
|
+
return RBS_RANGE_LEX2AST(parser->current_token.range);
|
|
122
146
|
}
|
|
123
147
|
|
|
124
|
-
static bool parse_optional(rbs_parser_t *parser, rbs_node_t **optional, bool void_allowed, bool self_allowed);
|
|
125
|
-
static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type, bool void_allowed, bool self_allowed);
|
|
148
|
+
static bool parse_optional(rbs_parser_t *parser, rbs_node_t **optional, bool void_allowed, bool self_allowed, bool classish_allowed);
|
|
149
|
+
static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type, bool void_allowed, bool self_allowed, bool classish_allowed);
|
|
126
150
|
|
|
127
151
|
/**
|
|
128
152
|
* @returns A borrowed copy of the current token, which does *not* need to be freed.
|
|
@@ -178,8 +202,8 @@ static bool parse_type_name(rbs_parser_t *parser, TypeNameKind kind, rbs_range_t
|
|
|
178
202
|
parser->current_token.type == tUIDENT && parser->next_token.type == pCOLON2 && parser->current_token.range.end.byte_pos == parser->next_token.range.start.byte_pos && parser->next_token.range.end.byte_pos == parser->next_token2.range.start.byte_pos
|
|
179
203
|
) {
|
|
180
204
|
rbs_constant_id_t symbol_value = INTERN_TOKEN(parser, parser->current_token);
|
|
181
|
-
|
|
182
|
-
rbs_ast_symbol_t *symbol = rbs_ast_symbol_new(ALLOCATOR(),
|
|
205
|
+
rbs_location_range symbol_range = RBS_RANGE_LEX2AST(parser->next_token.range);
|
|
206
|
+
rbs_ast_symbol_t *symbol = rbs_ast_symbol_new(ALLOCATOR(), symbol_range, &parser->constant_pool, symbol_value);
|
|
183
207
|
rbs_node_list_append(path, (rbs_node_t *) symbol);
|
|
184
208
|
|
|
185
209
|
rbs_parser_advance(parser);
|
|
@@ -190,8 +214,7 @@ static bool parse_type_name(rbs_parser_t *parser, TypeNameKind kind, rbs_range_t
|
|
|
190
214
|
.start = rg->start,
|
|
191
215
|
.end = parser->current_token.range.end
|
|
192
216
|
};
|
|
193
|
-
|
|
194
|
-
rbs_namespace_t *ns = rbs_namespace_new(ALLOCATOR(), loc, path, absolute);
|
|
217
|
+
rbs_namespace_t *ns = rbs_namespace_new(ALLOCATOR(), RBS_RANGE_LEX2AST(namespace_range), path, absolute);
|
|
195
218
|
|
|
196
219
|
switch (parser->current_token.type) {
|
|
197
220
|
case tLIDENT:
|
|
@@ -214,10 +237,10 @@ success: {
|
|
|
214
237
|
rg->end = parser->current_token.range.end;
|
|
215
238
|
}
|
|
216
239
|
|
|
217
|
-
|
|
240
|
+
rbs_location_range symbol_range = rbs_location_range_current_token(parser);
|
|
218
241
|
rbs_constant_id_t name = INTERN_TOKEN(parser, parser->current_token);
|
|
219
|
-
rbs_ast_symbol_t *symbol = rbs_ast_symbol_new(ALLOCATOR(),
|
|
220
|
-
*type_name = rbs_type_name_new(ALLOCATOR(),
|
|
242
|
+
rbs_ast_symbol_t *symbol = rbs_ast_symbol_new(ALLOCATOR(), symbol_range, &parser->constant_pool, name);
|
|
243
|
+
*type_name = rbs_type_name_new(ALLOCATOR(), RBS_RANGE_LEX2AST(*rg), ns, symbol);
|
|
221
244
|
return true;
|
|
222
245
|
}
|
|
223
246
|
|
|
@@ -245,10 +268,10 @@ error_handling: {
|
|
|
245
268
|
| {} type `,` ... `,` <type> eol
|
|
246
269
|
*/
|
|
247
270
|
NODISCARD
|
|
248
|
-
static bool parse_type_list(rbs_parser_t *parser, enum RBSTokenType eol, rbs_node_list_t *types, bool void_allowed, bool self_allowed) {
|
|
271
|
+
static bool parse_type_list(rbs_parser_t *parser, enum RBSTokenType eol, rbs_node_list_t *types, bool void_allowed, bool self_allowed, bool classish_allowed) {
|
|
249
272
|
while (true) {
|
|
250
273
|
rbs_node_t *type;
|
|
251
|
-
CHECK_PARSE(rbs_parse_type(parser, &type, void_allowed, self_allowed));
|
|
274
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, void_allowed, self_allowed, classish_allowed));
|
|
252
275
|
rbs_node_list_append(types, type);
|
|
253
276
|
|
|
254
277
|
if (parser->next_token.type == pCOMMA) {
|
|
@@ -275,15 +298,15 @@ static bool parse_type_list(rbs_parser_t *parser, enum RBSTokenType eol, rbs_nod
|
|
|
275
298
|
| {} type `,` ... `,` <type> eol
|
|
276
299
|
*/
|
|
277
300
|
NODISCARD
|
|
278
|
-
static bool parse_type_list_with_commas(rbs_parser_t *parser, enum RBSTokenType eol, rbs_node_list_t *types,
|
|
301
|
+
static bool parse_type_list_with_commas(rbs_parser_t *parser, enum RBSTokenType eol, rbs_node_list_t *types, rbs_location_range_list_t *comma_locations, bool void_allowed, bool self_allowed, bool classish_allowed) {
|
|
279
302
|
while (true) {
|
|
280
303
|
rbs_node_t *type;
|
|
281
|
-
CHECK_PARSE(rbs_parse_type(parser, &type, void_allowed, self_allowed));
|
|
304
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, void_allowed, self_allowed, classish_allowed));
|
|
282
305
|
rbs_node_list_append(types, type);
|
|
283
306
|
|
|
284
307
|
if (parser->next_token.type == pCOMMA) {
|
|
285
|
-
|
|
286
|
-
|
|
308
|
+
rbs_location_range comma_loc = RBS_RANGE_LEX2AST(parser->next_token.range);
|
|
309
|
+
rbs_location_range_list_append(comma_locations, comma_loc);
|
|
287
310
|
rbs_parser_advance(parser);
|
|
288
311
|
|
|
289
312
|
if (parser->next_token.type == eol) {
|
|
@@ -327,21 +350,17 @@ static bool is_keyword_token(enum RBSTokenType type) {
|
|
|
327
350
|
| {} type <param>
|
|
328
351
|
*/
|
|
329
352
|
NODISCARD
|
|
330
|
-
static bool parse_function_param(rbs_parser_t *parser, rbs_types_function_param_t **function_param, bool self_allowed) {
|
|
353
|
+
static bool parse_function_param(rbs_parser_t *parser, rbs_types_function_param_t **function_param, bool self_allowed, bool classish_allowed) {
|
|
331
354
|
rbs_range_t type_range;
|
|
332
355
|
type_range.start = parser->next_token.range.start;
|
|
333
356
|
rbs_node_t *type;
|
|
334
|
-
CHECK_PARSE(rbs_parse_type(parser, &type, false, self_allowed));
|
|
357
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, false, self_allowed, classish_allowed));
|
|
335
358
|
type_range.end = parser->current_token.range.end;
|
|
336
359
|
|
|
337
360
|
if (parser->next_token.type == pCOMMA || parser->next_token.type == pRPAREN) {
|
|
338
361
|
rbs_range_t param_range = type_range;
|
|
339
362
|
|
|
340
|
-
|
|
341
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 1);
|
|
342
|
-
rbs_loc_add_optional_child(loc, INTERN("name"), NULL_RANGE);
|
|
343
|
-
|
|
344
|
-
*function_param = rbs_types_function_param_new(ALLOCATOR(), loc, type, NULL);
|
|
363
|
+
*function_param = rbs_types_function_param_new(ALLOCATOR(), RBS_RANGE_LEX2AST(param_range), type, NULL);
|
|
345
364
|
return true;
|
|
346
365
|
} else {
|
|
347
366
|
rbs_range_t name_range = parser->next_token.range;
|
|
@@ -359,15 +378,12 @@ static bool parse_function_param(rbs_parser_t *parser, rbs_types_function_param_
|
|
|
359
378
|
}
|
|
360
379
|
|
|
361
380
|
rbs_string_t unquoted_str = rbs_unquote_string(ALLOCATOR(), rbs_parser_peek_current_token(parser), parser->lexer->encoding);
|
|
362
|
-
|
|
381
|
+
rbs_location_range symbol_range = rbs_location_range_current_token(parser);
|
|
363
382
|
rbs_constant_id_t constant_id = rbs_constant_pool_insert_string(&parser->constant_pool, unquoted_str);
|
|
364
|
-
rbs_ast_symbol_t *name = rbs_ast_symbol_new(ALLOCATOR(),
|
|
365
|
-
|
|
366
|
-
rbs_location_t *loc = rbs_location_new(ALLOCATOR(), param_range);
|
|
367
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 1);
|
|
368
|
-
rbs_loc_add_optional_child(loc, INTERN("name"), name_range);
|
|
383
|
+
rbs_ast_symbol_t *name = rbs_ast_symbol_new(ALLOCATOR(), symbol_range, &parser->constant_pool, constant_id);
|
|
369
384
|
|
|
370
|
-
*function_param = rbs_types_function_param_new(ALLOCATOR(),
|
|
385
|
+
*function_param = rbs_types_function_param_new(ALLOCATOR(), RBS_RANGE_LEX2AST(param_range), type, name);
|
|
386
|
+
(*function_param)->name_range = RBS_RANGE_LEX2AST(name_range);
|
|
371
387
|
return true;
|
|
372
388
|
}
|
|
373
389
|
}
|
|
@@ -389,18 +405,18 @@ NODISCARD
|
|
|
389
405
|
static bool parse_keyword_key(rbs_parser_t *parser, rbs_ast_symbol_t **key) {
|
|
390
406
|
rbs_parser_advance(parser);
|
|
391
407
|
|
|
392
|
-
|
|
408
|
+
rbs_location_range symbol_range = rbs_location_range_current_token(parser);
|
|
393
409
|
|
|
394
410
|
if (parser->next_token.type == pQUESTION) {
|
|
395
411
|
*key = rbs_ast_symbol_new(
|
|
396
412
|
ALLOCATOR(),
|
|
397
|
-
|
|
413
|
+
symbol_range,
|
|
398
414
|
&parser->constant_pool,
|
|
399
415
|
intern_token_start_end(parser, parser->current_token, parser->next_token)
|
|
400
416
|
);
|
|
401
417
|
rbs_parser_advance(parser);
|
|
402
418
|
} else {
|
|
403
|
-
*key = rbs_ast_symbol_new(ALLOCATOR(),
|
|
419
|
+
*key = rbs_ast_symbol_new(ALLOCATOR(), symbol_range, &parser->constant_pool, INTERN_TOKEN(parser, parser->current_token));
|
|
404
420
|
}
|
|
405
421
|
|
|
406
422
|
return true;
|
|
@@ -410,7 +426,7 @@ static bool parse_keyword_key(rbs_parser_t *parser, rbs_ast_symbol_t **key) {
|
|
|
410
426
|
keyword ::= {} keyword `:` <function_param>
|
|
411
427
|
*/
|
|
412
428
|
NODISCARD
|
|
413
|
-
static bool parse_keyword(rbs_parser_t *parser, rbs_hash_t *keywords, rbs_hash_t *memo, bool self_allowed) {
|
|
429
|
+
static bool parse_keyword(rbs_parser_t *parser, rbs_hash_t *keywords, rbs_hash_t *memo, bool self_allowed, bool classish_allowed) {
|
|
414
430
|
rbs_ast_symbol_t *key = NULL;
|
|
415
431
|
CHECK_PARSE(parse_keyword_key(parser, &key));
|
|
416
432
|
|
|
@@ -418,13 +434,13 @@ static bool parse_keyword(rbs_parser_t *parser, rbs_hash_t *keywords, rbs_hash_t
|
|
|
418
434
|
rbs_parser_set_error(parser, parser->current_token, true, "duplicated keyword argument");
|
|
419
435
|
return false;
|
|
420
436
|
} else {
|
|
421
|
-
|
|
422
|
-
rbs_hash_set(memo, (rbs_node_t *) key, (rbs_node_t *) rbs_ast_bool_new(ALLOCATOR(),
|
|
437
|
+
rbs_location_range symbol_range = rbs_location_range_current_token(parser);
|
|
438
|
+
rbs_hash_set(memo, (rbs_node_t *) key, (rbs_node_t *) rbs_ast_bool_new(ALLOCATOR(), symbol_range, true));
|
|
423
439
|
}
|
|
424
440
|
|
|
425
441
|
ADVANCE_ASSERT(parser, pCOLON);
|
|
426
442
|
rbs_types_function_param_t *param = NULL;
|
|
427
|
-
CHECK_PARSE(parse_function_param(parser, ¶m, self_allowed));
|
|
443
|
+
CHECK_PARSE(parse_function_param(parser, ¶m, self_allowed, classish_allowed));
|
|
428
444
|
|
|
429
445
|
rbs_hash_set(keywords, (rbs_node_t *) key, (rbs_node_t *) param);
|
|
430
446
|
|
|
@@ -495,7 +511,7 @@ static bool parser_advance_if(rbs_parser_t *parser, enum RBSTokenType type) {
|
|
|
495
511
|
| {} `**` <function_param>
|
|
496
512
|
*/
|
|
497
513
|
NODISCARD
|
|
498
|
-
static bool parse_params(rbs_parser_t *parser, method_params *params, bool self_allowed) {
|
|
514
|
+
static bool parse_params(rbs_parser_t *parser, method_params *params, bool self_allowed, bool classish_allowed) {
|
|
499
515
|
if (parser->next_token.type == pQUESTION && parser->next_token2.type == pRPAREN) {
|
|
500
516
|
params->required_positionals = NULL;
|
|
501
517
|
rbs_parser_advance(parser);
|
|
@@ -524,7 +540,7 @@ static bool parse_params(rbs_parser_t *parser, method_params *params, bool self_
|
|
|
524
540
|
}
|
|
525
541
|
|
|
526
542
|
rbs_types_function_param_t *param = NULL;
|
|
527
|
-
CHECK_PARSE(parse_function_param(parser, ¶m, self_allowed));
|
|
543
|
+
CHECK_PARSE(parse_function_param(parser, ¶m, self_allowed, classish_allowed));
|
|
528
544
|
rbs_node_list_append(params->required_positionals, (rbs_node_t *) param);
|
|
529
545
|
|
|
530
546
|
break;
|
|
@@ -538,20 +554,21 @@ static bool parse_params(rbs_parser_t *parser, method_params *params, bool self_
|
|
|
538
554
|
PARSE_OPTIONAL_PARAMS:
|
|
539
555
|
while (true) {
|
|
540
556
|
switch (parser->next_token.type) {
|
|
541
|
-
case pQUESTION:
|
|
557
|
+
case pQUESTION: {
|
|
542
558
|
rbs_parser_advance(parser);
|
|
543
559
|
|
|
544
560
|
if (is_keyword(parser)) {
|
|
545
|
-
CHECK_PARSE(parse_keyword(parser, params->optional_keywords, memo, self_allowed));
|
|
561
|
+
CHECK_PARSE(parse_keyword(parser, params->optional_keywords, memo, self_allowed, classish_allowed));
|
|
546
562
|
parser_advance_if(parser, pCOMMA);
|
|
547
563
|
goto PARSE_KEYWORDS;
|
|
548
564
|
}
|
|
549
565
|
|
|
550
566
|
rbs_types_function_param_t *param = NULL;
|
|
551
|
-
CHECK_PARSE(parse_function_param(parser, ¶m, self_allowed));
|
|
567
|
+
CHECK_PARSE(parse_function_param(parser, ¶m, self_allowed, classish_allowed));
|
|
552
568
|
rbs_node_list_append(params->optional_positionals, (rbs_node_t *) param);
|
|
553
569
|
|
|
554
570
|
break;
|
|
571
|
+
}
|
|
555
572
|
default:
|
|
556
573
|
goto PARSE_REST_PARAM;
|
|
557
574
|
}
|
|
@@ -565,7 +582,7 @@ PARSE_REST_PARAM:
|
|
|
565
582
|
if (parser->next_token.type == pSTAR) {
|
|
566
583
|
rbs_parser_advance(parser);
|
|
567
584
|
rbs_types_function_param_t *param = NULL;
|
|
568
|
-
CHECK_PARSE(parse_function_param(parser, ¶m, self_allowed));
|
|
585
|
+
CHECK_PARSE(parse_function_param(parser, ¶m, self_allowed, classish_allowed));
|
|
569
586
|
params->rest_positionals = (rbs_node_t *) param;
|
|
570
587
|
|
|
571
588
|
if (!parser_advance_if(parser, pCOMMA)) {
|
|
@@ -592,7 +609,7 @@ PARSE_TRAILING_PARAMS:
|
|
|
592
609
|
}
|
|
593
610
|
|
|
594
611
|
rbs_types_function_param_t *param = NULL;
|
|
595
|
-
CHECK_PARSE(parse_function_param(parser, ¶m, self_allowed));
|
|
612
|
+
CHECK_PARSE(parse_function_param(parser, ¶m, self_allowed, classish_allowed));
|
|
596
613
|
rbs_node_list_append(params->trailing_positionals, (rbs_node_t *) param);
|
|
597
614
|
|
|
598
615
|
break;
|
|
@@ -609,20 +626,20 @@ PARSE_KEYWORDS:
|
|
|
609
626
|
case pQUESTION:
|
|
610
627
|
rbs_parser_advance(parser);
|
|
611
628
|
if (is_keyword(parser)) {
|
|
612
|
-
CHECK_PARSE(parse_keyword(parser, params->optional_keywords, memo, self_allowed));
|
|
629
|
+
CHECK_PARSE(parse_keyword(parser, params->optional_keywords, memo, self_allowed, classish_allowed));
|
|
613
630
|
} else {
|
|
614
631
|
rbs_parser_set_error(parser, parser->next_token, true, "optional keyword argument type is expected");
|
|
615
632
|
return false;
|
|
616
633
|
}
|
|
617
634
|
break;
|
|
618
635
|
|
|
619
|
-
case pSTAR2:
|
|
636
|
+
case pSTAR2: {
|
|
620
637
|
rbs_parser_advance(parser);
|
|
621
638
|
rbs_types_function_param_t *param = NULL;
|
|
622
|
-
CHECK_PARSE(parse_function_param(parser, ¶m, self_allowed));
|
|
639
|
+
CHECK_PARSE(parse_function_param(parser, ¶m, self_allowed, classish_allowed));
|
|
623
640
|
params->rest_keywords = (rbs_node_t *) param;
|
|
624
641
|
break;
|
|
625
|
-
|
|
642
|
+
}
|
|
626
643
|
case tUIDENT:
|
|
627
644
|
case tLIDENT:
|
|
628
645
|
case tQIDENT:
|
|
@@ -631,7 +648,7 @@ PARSE_KEYWORDS:
|
|
|
631
648
|
case tBANGIDENT:
|
|
632
649
|
KEYWORD_CASES
|
|
633
650
|
if (is_keyword(parser)) {
|
|
634
|
-
CHECK_PARSE(parse_keyword(parser, params->required_keywords, memo, self_allowed));
|
|
651
|
+
CHECK_PARSE(parse_keyword(parser, params->required_keywords, memo, self_allowed, classish_allowed));
|
|
635
652
|
} else {
|
|
636
653
|
rbs_parser_set_error(parser, parser->next_token, true, "required keyword argument type is expected");
|
|
637
654
|
return false;
|
|
@@ -661,12 +678,12 @@ EOP:
|
|
|
661
678
|
| {} simple_type <`?`>
|
|
662
679
|
*/
|
|
663
680
|
NODISCARD
|
|
664
|
-
static bool parse_optional(rbs_parser_t *parser, rbs_node_t **optional, bool void_allowed, bool self_allowed) {
|
|
681
|
+
static bool parse_optional(rbs_parser_t *parser, rbs_node_t **optional, bool void_allowed, bool self_allowed, bool classish_allowed) {
|
|
665
682
|
rbs_range_t rg;
|
|
666
683
|
rg.start = parser->next_token.range.start;
|
|
667
684
|
|
|
668
685
|
rbs_node_t *type = NULL;
|
|
669
|
-
CHECK_PARSE(parse_simple(parser, &type, void_allowed, self_allowed));
|
|
686
|
+
CHECK_PARSE(parse_simple(parser, &type, void_allowed, self_allowed, classish_allowed));
|
|
670
687
|
|
|
671
688
|
if (parser->next_token.type == pQUESTION) {
|
|
672
689
|
if (void_allowed && type->type == RBS_TYPES_BASES_VOID) {
|
|
@@ -676,8 +693,7 @@ static bool parse_optional(rbs_parser_t *parser, rbs_node_t **optional, bool voi
|
|
|
676
693
|
|
|
677
694
|
rbs_parser_advance(parser);
|
|
678
695
|
rg.end = parser->current_token.range.end;
|
|
679
|
-
|
|
680
|
-
*optional = (rbs_node_t *) rbs_types_optional_new(ALLOCATOR(), location, type);
|
|
696
|
+
*optional = (rbs_node_t *) rbs_types_optional_new(ALLOCATOR(), RBS_RANGE_LEX2AST(rg), type);
|
|
681
697
|
} else {
|
|
682
698
|
*optional = type;
|
|
683
699
|
}
|
|
@@ -702,13 +718,13 @@ static void initialize_method_params(method_params *params, rbs_allocator_t *all
|
|
|
702
718
|
| {} `[` `self` `:` type <`]`>
|
|
703
719
|
*/
|
|
704
720
|
NODISCARD
|
|
705
|
-
static bool parse_self_type_binding(rbs_parser_t *parser, rbs_node_t **self_type, bool self_allowed) {
|
|
721
|
+
static bool parse_self_type_binding(rbs_parser_t *parser, rbs_node_t **self_type, bool self_allowed, bool classish_allowed) {
|
|
706
722
|
if (parser->next_token.type == pLBRACKET) {
|
|
707
723
|
rbs_parser_advance(parser);
|
|
708
724
|
ADVANCE_ASSERT(parser, kSELF);
|
|
709
725
|
ADVANCE_ASSERT(parser, pCOLON);
|
|
710
726
|
rbs_node_t *type;
|
|
711
|
-
CHECK_PARSE(rbs_parse_type(parser, &type, false, self_allowed));
|
|
727
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, false, self_allowed, classish_allowed));
|
|
712
728
|
ADVANCE_ASSERT(parser, pRBRACKET);
|
|
713
729
|
*self_type = type;
|
|
714
730
|
}
|
|
@@ -730,7 +746,7 @@ typedef struct {
|
|
|
730
746
|
| {} self_type_binding? `->` <optional>
|
|
731
747
|
*/
|
|
732
748
|
NODISCARD
|
|
733
|
-
static bool parse_function(rbs_parser_t *parser, bool accept_type_binding, parse_function_result **result, bool self_allowed) {
|
|
749
|
+
static bool parse_function(rbs_parser_t *parser, bool accept_type_binding, bool block_allowed, parse_function_result **result, bool self_allowed, bool classish_allowed) {
|
|
734
750
|
rbs_node_t *function = NULL;
|
|
735
751
|
rbs_types_block_t *block = NULL;
|
|
736
752
|
rbs_node_t *function_self_type = NULL;
|
|
@@ -742,13 +758,13 @@ static bool parse_function(rbs_parser_t *parser, bool accept_type_binding, parse
|
|
|
742
758
|
|
|
743
759
|
if (parser->next_token.type == pLPAREN) {
|
|
744
760
|
rbs_parser_advance(parser);
|
|
745
|
-
CHECK_PARSE(parse_params(parser, ¶ms, self_allowed));
|
|
761
|
+
CHECK_PARSE(parse_params(parser, ¶ms, self_allowed, classish_allowed));
|
|
746
762
|
ADVANCE_ASSERT(parser, pRPAREN);
|
|
747
763
|
}
|
|
748
764
|
|
|
749
765
|
// Passing NULL to function_self_type means the function itself doesn't accept self type binding. (== method type)
|
|
750
766
|
if (accept_type_binding) {
|
|
751
|
-
CHECK_PARSE(parse_self_type_binding(parser, &function_self_type, self_allowed));
|
|
767
|
+
CHECK_PARSE(parse_self_type_binding(parser, &function_self_type, self_allowed, classish_allowed));
|
|
752
768
|
} else {
|
|
753
769
|
if (rbs_is_untyped_params(¶ms)) {
|
|
754
770
|
if (parser->next_token.type != pARROW) {
|
|
@@ -761,6 +777,11 @@ static bool parse_function(rbs_parser_t *parser, bool accept_type_binding, parse
|
|
|
761
777
|
bool required = true;
|
|
762
778
|
rbs_range_t block_range;
|
|
763
779
|
|
|
780
|
+
if (!block_allowed && (parser->next_token.type == pLBRACE || (parser->next_token.type == pQUESTION && parser->next_token2.type == pLBRACE))) {
|
|
781
|
+
rbs_parser_set_error(parser, parser->next_token, true, "block is not allowed in this context");
|
|
782
|
+
return false;
|
|
783
|
+
}
|
|
784
|
+
|
|
764
785
|
if (parser->next_token.type == pQUESTION && parser->next_token2.type == pLBRACE) {
|
|
765
786
|
// Optional block
|
|
766
787
|
block_range.start = parser->next_token.range.start;
|
|
@@ -778,29 +799,28 @@ static bool parse_function(rbs_parser_t *parser, bool accept_type_binding, parse
|
|
|
778
799
|
|
|
779
800
|
if (parser->next_token.type == pLPAREN) {
|
|
780
801
|
rbs_parser_advance(parser);
|
|
781
|
-
CHECK_PARSE(parse_params(parser, &block_params, self_allowed));
|
|
802
|
+
CHECK_PARSE(parse_params(parser, &block_params, self_allowed, classish_allowed));
|
|
782
803
|
ADVANCE_ASSERT(parser, pRPAREN);
|
|
783
804
|
}
|
|
784
805
|
|
|
785
806
|
rbs_node_t *self_type = NULL;
|
|
786
|
-
CHECK_PARSE(parse_self_type_binding(parser, &self_type, self_allowed));
|
|
807
|
+
CHECK_PARSE(parse_self_type_binding(parser, &self_type, self_allowed, classish_allowed));
|
|
787
808
|
|
|
788
809
|
ADVANCE_ASSERT(parser, pARROW);
|
|
789
810
|
rbs_node_t *block_return_type = NULL;
|
|
790
|
-
CHECK_PARSE(parse_optional(parser, &block_return_type, true, self_allowed));
|
|
811
|
+
CHECK_PARSE(parse_optional(parser, &block_return_type, true, self_allowed, classish_allowed));
|
|
791
812
|
|
|
792
813
|
ADVANCE_ASSERT(parser, pRBRACE);
|
|
793
814
|
|
|
794
815
|
block_range.end = parser->current_token.range.end;
|
|
795
|
-
rbs_location_t *loc = rbs_location_new(ALLOCATOR(), block_range);
|
|
796
816
|
|
|
797
817
|
rbs_node_t *block_function = NULL;
|
|
798
818
|
if (rbs_is_untyped_params(&block_params)) {
|
|
799
|
-
block_function = (rbs_node_t *) rbs_types_untyped_function_new(ALLOCATOR(),
|
|
819
|
+
block_function = (rbs_node_t *) rbs_types_untyped_function_new(ALLOCATOR(), RBS_RANGE_LEX2AST(block_range), block_return_type);
|
|
800
820
|
} else {
|
|
801
821
|
block_function = (rbs_node_t *) rbs_types_function_new(
|
|
802
822
|
ALLOCATOR(),
|
|
803
|
-
|
|
823
|
+
RBS_RANGE_LEX2AST(block_range),
|
|
804
824
|
block_params.required_positionals,
|
|
805
825
|
block_params.optional_positionals,
|
|
806
826
|
block_params.rest_positionals,
|
|
@@ -812,21 +832,20 @@ static bool parse_function(rbs_parser_t *parser, bool accept_type_binding, parse
|
|
|
812
832
|
);
|
|
813
833
|
}
|
|
814
834
|
|
|
815
|
-
block = rbs_types_block_new(ALLOCATOR(),
|
|
835
|
+
block = rbs_types_block_new(ALLOCATOR(), RBS_RANGE_LEX2AST(block_range), block_function, required, self_type);
|
|
816
836
|
}
|
|
817
837
|
|
|
818
838
|
ADVANCE_ASSERT(parser, pARROW);
|
|
819
839
|
rbs_node_t *type = NULL;
|
|
820
|
-
CHECK_PARSE(parse_optional(parser, &type, true, self_allowed));
|
|
840
|
+
CHECK_PARSE(parse_optional(parser, &type, true, self_allowed, classish_allowed));
|
|
821
841
|
|
|
822
842
|
function_range.end = parser->current_token.range.end;
|
|
823
|
-
rbs_location_t *loc = rbs_location_new(ALLOCATOR(), function_range);
|
|
824
843
|
if (rbs_is_untyped_params(¶ms)) {
|
|
825
|
-
function = (rbs_node_t *) rbs_types_untyped_function_new(ALLOCATOR(),
|
|
844
|
+
function = (rbs_node_t *) rbs_types_untyped_function_new(ALLOCATOR(), RBS_RANGE_LEX2AST(function_range), type);
|
|
826
845
|
} else {
|
|
827
846
|
function = (rbs_node_t *) rbs_types_function_new(
|
|
828
847
|
ALLOCATOR(),
|
|
829
|
-
|
|
848
|
+
RBS_RANGE_LEX2AST(function_range),
|
|
830
849
|
params.required_positionals,
|
|
831
850
|
params.optional_positionals,
|
|
832
851
|
params.rest_positionals,
|
|
@@ -848,14 +867,14 @@ static bool parse_function(rbs_parser_t *parser, bool accept_type_binding, parse
|
|
|
848
867
|
proc_type ::= {`^`} <function>
|
|
849
868
|
*/
|
|
850
869
|
NODISCARD
|
|
851
|
-
static bool parse_proc_type(rbs_parser_t *parser, rbs_types_proc_t **proc, bool self_allowed) {
|
|
870
|
+
static bool parse_proc_type(rbs_parser_t *parser, rbs_types_proc_t **proc, bool self_allowed, bool classish_allowed) {
|
|
852
871
|
rbs_position_t start = parser->current_token.range.start;
|
|
853
872
|
parse_function_result *result = rbs_allocator_alloc(ALLOCATOR(), parse_function_result);
|
|
854
|
-
CHECK_PARSE(parse_function(parser, true, &result, self_allowed));
|
|
873
|
+
CHECK_PARSE(parse_function(parser, true, true, &result, self_allowed, classish_allowed));
|
|
855
874
|
|
|
856
875
|
rbs_position_t end = parser->current_token.range.end;
|
|
857
|
-
|
|
858
|
-
*proc = rbs_types_proc_new(ALLOCATOR(),
|
|
876
|
+
rbs_location_range range = { .start_char = start.char_pos, .start_byte = start.byte_pos, .end_char = end.char_pos, .end_byte = end.byte_pos };
|
|
877
|
+
*proc = rbs_types_proc_new(ALLOCATOR(), range, result->function, result->block, result->function_self_type);
|
|
859
878
|
return true;
|
|
860
879
|
}
|
|
861
880
|
|
|
@@ -876,7 +895,7 @@ static void check_key_duplication(rbs_parser_t *parser, rbs_hash_t *fields, rbs_
|
|
|
876
895
|
| {} literal_type `=>` <type>
|
|
877
896
|
*/
|
|
878
897
|
NODISCARD
|
|
879
|
-
static bool parse_record_attributes(rbs_parser_t *parser, rbs_hash_t **fields, bool self_allowed) {
|
|
898
|
+
static bool parse_record_attributes(rbs_parser_t *parser, rbs_hash_t **fields, bool self_allowed, bool classish_allowed) {
|
|
880
899
|
*fields = rbs_hash_new(ALLOCATOR());
|
|
881
900
|
|
|
882
901
|
if (parser->next_token.type == pRBRACE) return true;
|
|
@@ -909,7 +928,7 @@ static bool parse_record_attributes(rbs_parser_t *parser, rbs_hash_t **fields, b
|
|
|
909
928
|
case kTRUE:
|
|
910
929
|
case kFALSE: {
|
|
911
930
|
rbs_node_t *type = NULL;
|
|
912
|
-
CHECK_PARSE(parse_simple(parser, &type, false, self_allowed));
|
|
931
|
+
CHECK_PARSE(parse_simple(parser, &type, false, self_allowed, classish_allowed));
|
|
913
932
|
|
|
914
933
|
key = (rbs_ast_symbol_t *) ((rbs_types_literal_t *) type)->literal;
|
|
915
934
|
break;
|
|
@@ -926,11 +945,10 @@ static bool parse_record_attributes(rbs_parser_t *parser, rbs_hash_t **fields, b
|
|
|
926
945
|
field_range.start = parser->current_token.range.end;
|
|
927
946
|
|
|
928
947
|
rbs_node_t *type;
|
|
929
|
-
CHECK_PARSE(rbs_parse_type(parser, &type, false, self_allowed));
|
|
948
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, false, self_allowed, classish_allowed));
|
|
930
949
|
|
|
931
950
|
field_range.end = parser->current_token.range.end;
|
|
932
|
-
|
|
933
|
-
rbs_hash_set(*fields, (rbs_node_t *) key, (rbs_node_t *) rbs_types_record_field_type_new(ALLOCATOR(), loc, type, required));
|
|
951
|
+
rbs_hash_set(*fields, (rbs_node_t *) key, (rbs_node_t *) rbs_types_record_field_type_new(ALLOCATOR(), RBS_RANGE_LEX2AST(field_range), type, required));
|
|
934
952
|
|
|
935
953
|
if (parser_advance_if(parser, pCOMMA)) {
|
|
936
954
|
if (parser->next_token.type == pRBRACE) {
|
|
@@ -947,7 +965,7 @@ static bool parse_record_attributes(rbs_parser_t *parser, rbs_hash_t **fields, b
|
|
|
947
965
|
symbol ::= {<tSYMBOL>}
|
|
948
966
|
*/
|
|
949
967
|
NODISCARD
|
|
950
|
-
static bool parse_symbol(rbs_parser_t *parser,
|
|
968
|
+
static bool parse_symbol(rbs_parser_t *parser, rbs_location_range location, rbs_types_literal_t **symbol) {
|
|
951
969
|
size_t offset_bytes = parser->lexer->encoding->char_width((const uint8_t *) ":", (size_t) 1);
|
|
952
970
|
size_t bytes = rbs_token_bytes(parser->current_token) - offset_bytes;
|
|
953
971
|
|
|
@@ -955,7 +973,7 @@ static bool parse_symbol(rbs_parser_t *parser, rbs_location_t *location, rbs_typ
|
|
|
955
973
|
|
|
956
974
|
switch (parser->current_token.type) {
|
|
957
975
|
case tSYMBOL: {
|
|
958
|
-
|
|
976
|
+
rbs_location_range symbol_range = rbs_location_range_current_token(parser);
|
|
959
977
|
|
|
960
978
|
char *buffer = rbs_peek_token(parser->lexer, parser->current_token);
|
|
961
979
|
rbs_constant_id_t constant_id = rbs_constant_pool_insert_shared(
|
|
@@ -963,12 +981,12 @@ static bool parse_symbol(rbs_parser_t *parser, rbs_location_t *location, rbs_typ
|
|
|
963
981
|
(const uint8_t *) buffer + offset_bytes,
|
|
964
982
|
bytes
|
|
965
983
|
);
|
|
966
|
-
literal = rbs_ast_symbol_new(ALLOCATOR(),
|
|
984
|
+
literal = rbs_ast_symbol_new(ALLOCATOR(), symbol_range, &parser->constant_pool, constant_id);
|
|
967
985
|
break;
|
|
968
986
|
}
|
|
969
987
|
case tDQSYMBOL:
|
|
970
988
|
case tSQSYMBOL: {
|
|
971
|
-
|
|
989
|
+
rbs_location_range symbol_range = rbs_location_range_current_token(parser);
|
|
972
990
|
rbs_string_t current_token = rbs_parser_peek_current_token(parser);
|
|
973
991
|
|
|
974
992
|
rbs_string_t symbol = rbs_string_new(current_token.start + offset_bytes, current_token.end);
|
|
@@ -977,7 +995,7 @@ static bool parse_symbol(rbs_parser_t *parser, rbs_location_t *location, rbs_typ
|
|
|
977
995
|
|
|
978
996
|
rbs_constant_id_t constant_id = rbs_constant_pool_insert_string(&parser->constant_pool, unquoted_symbol);
|
|
979
997
|
|
|
980
|
-
literal = rbs_ast_symbol_new(ALLOCATOR(),
|
|
998
|
+
literal = rbs_ast_symbol_new(ALLOCATOR(), symbol_range, &parser->constant_pool, constant_id);
|
|
981
999
|
break;
|
|
982
1000
|
}
|
|
983
1001
|
default:
|
|
@@ -1033,7 +1051,7 @@ static bool parse_instance_type(rbs_parser_t *parser, bool parse_alias, rbs_node
|
|
|
1033
1051
|
if (parser->next_token.type == pLBRACKET) {
|
|
1034
1052
|
rbs_parser_advance(parser);
|
|
1035
1053
|
args_range.start = parser->current_token.range.start;
|
|
1036
|
-
CHECK_PARSE(parse_type_list(parser, pRBRACKET, types, true, true));
|
|
1054
|
+
CHECK_PARSE(parse_type_list(parser, pRBRACKET, types, true, true, true));
|
|
1037
1055
|
ADVANCE_ASSERT(parser, pRBRACKET);
|
|
1038
1056
|
args_range.end = parser->current_token.range.end;
|
|
1039
1057
|
} else {
|
|
@@ -1045,27 +1063,30 @@ static bool parse_instance_type(rbs_parser_t *parser, bool parse_alias, rbs_node
|
|
|
1045
1063
|
.end = rbs_nonnull_pos_or(args_range.end, name_range.end),
|
|
1046
1064
|
};
|
|
1047
1065
|
|
|
1048
|
-
|
|
1049
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 2);
|
|
1050
|
-
rbs_loc_add_required_child(loc, INTERN("name"), name_range);
|
|
1051
|
-
rbs_loc_add_optional_child(loc, INTERN("args"), args_range);
|
|
1066
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(type_range);
|
|
1052
1067
|
|
|
1053
1068
|
if (kind == CLASS_NAME) {
|
|
1054
|
-
*
|
|
1069
|
+
rbs_types_class_instance_t *instance_type = rbs_types_class_instance_new(ALLOCATOR(), loc, type_name, types, RBS_RANGE_LEX2AST(name_range));
|
|
1070
|
+
instance_type->args_range = RBS_RANGE_LEX2AST(args_range);
|
|
1071
|
+
*type = (rbs_node_t *) instance_type;
|
|
1055
1072
|
} else if (kind == INTERFACE_NAME) {
|
|
1056
|
-
*
|
|
1073
|
+
rbs_types_interface_t *interface_type = rbs_types_interface_new(ALLOCATOR(), loc, type_name, types, RBS_RANGE_LEX2AST(name_range));
|
|
1074
|
+
interface_type->args_range = RBS_RANGE_LEX2AST(args_range);
|
|
1075
|
+
*type = (rbs_node_t *) interface_type;
|
|
1057
1076
|
} else if (kind == ALIAS_NAME) {
|
|
1058
|
-
*
|
|
1077
|
+
rbs_types_alias_t *type_alias = rbs_types_alias_new(ALLOCATOR(), loc, type_name, types, RBS_RANGE_LEX2AST(name_range));
|
|
1078
|
+
type_alias->args_range = RBS_RANGE_LEX2AST(args_range);
|
|
1079
|
+
*type = (rbs_node_t *) type_alias;
|
|
1059
1080
|
}
|
|
1060
1081
|
|
|
1061
1082
|
return true;
|
|
1062
1083
|
}
|
|
1063
1084
|
|
|
1064
1085
|
/*
|
|
1065
|
-
singleton_type ::= {`singleton`} `(` type_name <`)`>
|
|
1086
|
+
singleton_type ::= {`singleton`} `(` type_name <`)`> type_args?
|
|
1066
1087
|
*/
|
|
1067
1088
|
NODISCARD
|
|
1068
|
-
static bool parse_singleton_type(rbs_parser_t *parser, rbs_types_class_singleton_t **singleton) {
|
|
1089
|
+
static bool parse_singleton_type(rbs_parser_t *parser, rbs_types_class_singleton_t **singleton, bool self_allowed, bool classish_allowed) {
|
|
1069
1090
|
ASSERT_TOKEN(parser, kSINGLETON);
|
|
1070
1091
|
|
|
1071
1092
|
rbs_range_t type_range;
|
|
@@ -1078,13 +1099,26 @@ static bool parse_singleton_type(rbs_parser_t *parser, rbs_types_class_singleton
|
|
|
1078
1099
|
CHECK_PARSE(parse_type_name(parser, CLASS_NAME, &name_range, &type_name));
|
|
1079
1100
|
|
|
1080
1101
|
ADVANCE_ASSERT(parser, pRPAREN);
|
|
1102
|
+
|
|
1103
|
+
rbs_node_list_t *types = rbs_node_list_new(ALLOCATOR());
|
|
1104
|
+
|
|
1105
|
+
rbs_location_range args_range = RBS_LOCATION_NULL_RANGE;
|
|
1106
|
+
if (parser->next_token.type == pLBRACKET) {
|
|
1107
|
+
rbs_parser_advance(parser);
|
|
1108
|
+
args_range.start_byte = parser->current_token.range.start.byte_pos;
|
|
1109
|
+
args_range.start_char = parser->current_token.range.start.char_pos;
|
|
1110
|
+
CHECK_PARSE(parse_type_list(parser, pRBRACKET, types, true, self_allowed, classish_allowed));
|
|
1111
|
+
ADVANCE_ASSERT(parser, pRBRACKET);
|
|
1112
|
+
args_range.end_byte = parser->current_token.range.end.byte_pos;
|
|
1113
|
+
args_range.end_char = parser->current_token.range.end.char_pos;
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1081
1116
|
type_range.end = parser->current_token.range.end;
|
|
1117
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(type_range);
|
|
1082
1118
|
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
rbs_loc_add_required_child(loc, INTERN("name"), name_range);
|
|
1119
|
+
*singleton = rbs_types_class_singleton_new(ALLOCATOR(), loc, type_name, types, RBS_RANGE_LEX2AST(name_range));
|
|
1120
|
+
(*singleton)->args_range = args_range;
|
|
1086
1121
|
|
|
1087
|
-
*singleton = rbs_types_class_singleton_new(ALLOCATOR(), loc, type_name);
|
|
1088
1122
|
return true;
|
|
1089
1123
|
}
|
|
1090
1124
|
|
|
@@ -1120,39 +1154,49 @@ static bool parser_typevar_member(rbs_parser_t *parser, rbs_constant_id_t id) {
|
|
|
1120
1154
|
| {} `^` <function>
|
|
1121
1155
|
*/
|
|
1122
1156
|
NODISCARD
|
|
1123
|
-
static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type, bool void_allowed, bool self_allowed) {
|
|
1157
|
+
static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type, bool void_allowed, bool self_allowed, bool classish_allowed) {
|
|
1124
1158
|
rbs_parser_advance(parser);
|
|
1125
1159
|
|
|
1126
1160
|
switch (parser->current_token.type) {
|
|
1127
1161
|
case pLPAREN: {
|
|
1128
1162
|
rbs_node_t *lparen_type;
|
|
1129
|
-
CHECK_PARSE(rbs_parse_type(parser, &lparen_type,
|
|
1163
|
+
CHECK_PARSE(rbs_parse_type(parser, &lparen_type, void_allowed, self_allowed, classish_allowed));
|
|
1130
1164
|
ADVANCE_ASSERT(parser, pRPAREN);
|
|
1131
1165
|
*type = lparen_type;
|
|
1132
1166
|
return true;
|
|
1133
1167
|
}
|
|
1134
1168
|
case kBOOL: {
|
|
1135
|
-
|
|
1169
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1136
1170
|
*type = (rbs_node_t *) rbs_types_bases_bool_new(ALLOCATOR(), loc);
|
|
1137
1171
|
return true;
|
|
1138
1172
|
}
|
|
1139
1173
|
case kBOT: {
|
|
1140
|
-
|
|
1174
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1141
1175
|
*type = (rbs_node_t *) rbs_types_bases_bottom_new(ALLOCATOR(), loc);
|
|
1142
1176
|
return true;
|
|
1143
1177
|
}
|
|
1144
1178
|
case kCLASS: {
|
|
1145
|
-
|
|
1179
|
+
if (!classish_allowed) {
|
|
1180
|
+
rbs_parser_set_error(parser, parser->current_token, true, "class type is not allowed here");
|
|
1181
|
+
return false;
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1146
1185
|
*type = (rbs_node_t *) rbs_types_bases_class_new(ALLOCATOR(), loc);
|
|
1147
1186
|
return true;
|
|
1148
1187
|
}
|
|
1149
1188
|
case kINSTANCE: {
|
|
1150
|
-
|
|
1189
|
+
if (!classish_allowed) {
|
|
1190
|
+
rbs_parser_set_error(parser, parser->current_token, true, "instance type is not allowed here");
|
|
1191
|
+
return false;
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1151
1195
|
*type = (rbs_node_t *) rbs_types_bases_instance_new(ALLOCATOR(), loc);
|
|
1152
1196
|
return true;
|
|
1153
1197
|
}
|
|
1154
1198
|
case kNIL: {
|
|
1155
|
-
|
|
1199
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1156
1200
|
*type = (rbs_node_t *) rbs_types_bases_nil_new(ALLOCATOR(), loc);
|
|
1157
1201
|
return true;
|
|
1158
1202
|
}
|
|
@@ -1162,12 +1206,12 @@ static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type, bool void_allo
|
|
|
1162
1206
|
return false;
|
|
1163
1207
|
}
|
|
1164
1208
|
|
|
1165
|
-
|
|
1209
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1166
1210
|
*type = (rbs_node_t *) rbs_types_bases_self_new(ALLOCATOR(), loc);
|
|
1167
1211
|
return true;
|
|
1168
1212
|
}
|
|
1169
1213
|
case kTOP: {
|
|
1170
|
-
|
|
1214
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1171
1215
|
*type = (rbs_node_t *) rbs_types_bases_top_new(ALLOCATOR(), loc);
|
|
1172
1216
|
return true;
|
|
1173
1217
|
}
|
|
@@ -1177,22 +1221,22 @@ static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type, bool void_allo
|
|
|
1177
1221
|
return false;
|
|
1178
1222
|
}
|
|
1179
1223
|
|
|
1180
|
-
|
|
1224
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1181
1225
|
*type = (rbs_node_t *) rbs_types_bases_void_new(ALLOCATOR(), loc);
|
|
1182
1226
|
return true;
|
|
1183
1227
|
}
|
|
1184
1228
|
case kUNTYPED: {
|
|
1185
|
-
|
|
1229
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1186
1230
|
*type = (rbs_node_t *) rbs_types_bases_any_new(ALLOCATOR(), loc, false);
|
|
1187
1231
|
return true;
|
|
1188
1232
|
}
|
|
1189
1233
|
case k__TODO__: {
|
|
1190
|
-
|
|
1234
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1191
1235
|
*type = (rbs_node_t *) rbs_types_bases_any_new(ALLOCATOR(), loc, true);
|
|
1192
1236
|
return true;
|
|
1193
1237
|
}
|
|
1194
1238
|
case tINTEGER: {
|
|
1195
|
-
|
|
1239
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1196
1240
|
|
|
1197
1241
|
rbs_string_t string = rbs_parser_peek_current_token(parser);
|
|
1198
1242
|
rbs_string_t stripped_string = rbs_string_strip_whitespace(&string);
|
|
@@ -1202,18 +1246,18 @@ static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type, bool void_allo
|
|
|
1202
1246
|
return true;
|
|
1203
1247
|
}
|
|
1204
1248
|
case kTRUE: {
|
|
1205
|
-
|
|
1249
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1206
1250
|
*type = (rbs_node_t *) rbs_types_literal_new(ALLOCATOR(), loc, (rbs_node_t *) rbs_ast_bool_new(ALLOCATOR(), loc, true));
|
|
1207
1251
|
return true;
|
|
1208
1252
|
}
|
|
1209
1253
|
case kFALSE: {
|
|
1210
|
-
|
|
1254
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1211
1255
|
*type = (rbs_node_t *) rbs_types_literal_new(ALLOCATOR(), loc, (rbs_node_t *) rbs_ast_bool_new(ALLOCATOR(), loc, false));
|
|
1212
1256
|
return true;
|
|
1213
1257
|
}
|
|
1214
1258
|
case tSQSTRING:
|
|
1215
1259
|
case tDQSTRING: {
|
|
1216
|
-
|
|
1260
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1217
1261
|
|
|
1218
1262
|
rbs_string_t unquoted_str = rbs_unquote_string(ALLOCATOR(), rbs_parser_peek_current_token(parser), parser->lexer->encoding);
|
|
1219
1263
|
rbs_node_t *literal = (rbs_node_t *) rbs_ast_string_new(ALLOCATOR(), loc, unquoted_str);
|
|
@@ -1223,7 +1267,7 @@ static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type, bool void_allo
|
|
|
1223
1267
|
case tSYMBOL:
|
|
1224
1268
|
case tSQSYMBOL:
|
|
1225
1269
|
case tDQSYMBOL: {
|
|
1226
|
-
|
|
1270
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1227
1271
|
rbs_types_literal_t *literal = NULL;
|
|
1228
1272
|
CHECK_PARSE(parse_symbol(parser, loc, &literal));
|
|
1229
1273
|
*type = (rbs_node_t *) literal;
|
|
@@ -1236,7 +1280,7 @@ static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type, bool void_allo
|
|
|
1236
1280
|
rbs_constant_id_t name = rbs_constant_pool_find(&parser->constant_pool, (const uint8_t *) name_str, name_len);
|
|
1237
1281
|
|
|
1238
1282
|
if (parser_typevar_member(parser, name)) {
|
|
1239
|
-
|
|
1283
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1240
1284
|
rbs_ast_symbol_t *symbol = rbs_ast_symbol_new(ALLOCATOR(), loc, &parser->constant_pool, name);
|
|
1241
1285
|
*type = (rbs_node_t *) rbs_types_variable_new(ALLOCATOR(), loc, symbol);
|
|
1242
1286
|
return true;
|
|
@@ -1256,7 +1300,7 @@ static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type, bool void_allo
|
|
|
1256
1300
|
}
|
|
1257
1301
|
case kSINGLETON: {
|
|
1258
1302
|
rbs_types_class_singleton_t *singleton = NULL;
|
|
1259
|
-
CHECK_PARSE(parse_singleton_type(parser, &singleton));
|
|
1303
|
+
CHECK_PARSE(parse_singleton_type(parser, &singleton, self_allowed, classish_allowed));
|
|
1260
1304
|
*type = (rbs_node_t *) singleton;
|
|
1261
1305
|
return true;
|
|
1262
1306
|
}
|
|
@@ -1265,17 +1309,16 @@ static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type, bool void_allo
|
|
|
1265
1309
|
rg.start = parser->current_token.range.start;
|
|
1266
1310
|
rbs_node_list_t *types = rbs_node_list_new(ALLOCATOR());
|
|
1267
1311
|
if (parser->next_token.type != pRBRACKET) {
|
|
1268
|
-
CHECK_PARSE(parse_type_list(parser, pRBRACKET, types, false, self_allowed));
|
|
1312
|
+
CHECK_PARSE(parse_type_list(parser, pRBRACKET, types, false, self_allowed, classish_allowed));
|
|
1269
1313
|
}
|
|
1270
1314
|
ADVANCE_ASSERT(parser, pRBRACKET);
|
|
1271
1315
|
rg.end = parser->current_token.range.end;
|
|
1272
1316
|
|
|
1273
|
-
|
|
1274
|
-
*type = (rbs_node_t *) rbs_types_tuple_new(ALLOCATOR(), loc, types);
|
|
1317
|
+
*type = (rbs_node_t *) rbs_types_tuple_new(ALLOCATOR(), RBS_RANGE_LEX2AST(rg), types);
|
|
1275
1318
|
return true;
|
|
1276
1319
|
}
|
|
1277
1320
|
case pAREF_OPR: {
|
|
1278
|
-
|
|
1321
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1279
1322
|
rbs_node_list_t *types = rbs_node_list_new(ALLOCATOR());
|
|
1280
1323
|
*type = (rbs_node_t *) rbs_types_tuple_new(ALLOCATOR(), loc, types);
|
|
1281
1324
|
return true;
|
|
@@ -1283,16 +1326,16 @@ static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type, bool void_allo
|
|
|
1283
1326
|
case pLBRACE: {
|
|
1284
1327
|
rbs_position_t start = parser->current_token.range.start;
|
|
1285
1328
|
rbs_hash_t *fields = NULL;
|
|
1286
|
-
CHECK_PARSE(parse_record_attributes(parser, &fields, self_allowed));
|
|
1329
|
+
CHECK_PARSE(parse_record_attributes(parser, &fields, self_allowed, classish_allowed));
|
|
1287
1330
|
ADVANCE_ASSERT(parser, pRBRACE);
|
|
1288
1331
|
rbs_position_t end = parser->current_token.range.end;
|
|
1289
|
-
|
|
1332
|
+
rbs_location_range loc = { .start_char = start.char_pos, .start_byte = start.byte_pos, .end_char = end.char_pos, .end_byte = end.byte_pos };
|
|
1290
1333
|
*type = (rbs_node_t *) rbs_types_record_new(ALLOCATOR(), loc, fields);
|
|
1291
1334
|
return true;
|
|
1292
1335
|
}
|
|
1293
1336
|
case pHAT: {
|
|
1294
1337
|
rbs_types_proc_t *value = NULL;
|
|
1295
|
-
CHECK_PARSE(parse_proc_type(parser, &value, self_allowed));
|
|
1338
|
+
CHECK_PARSE(parse_proc_type(parser, &value, self_allowed, classish_allowed));
|
|
1296
1339
|
*type = (rbs_node_t *) value;
|
|
1297
1340
|
return true;
|
|
1298
1341
|
}
|
|
@@ -1307,12 +1350,12 @@ static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type, bool void_allo
|
|
|
1307
1350
|
| {} <optional>
|
|
1308
1351
|
*/
|
|
1309
1352
|
NODISCARD
|
|
1310
|
-
static bool parse_intersection(rbs_parser_t *parser, rbs_node_t **type, bool void_allowed, bool self_allowed) {
|
|
1353
|
+
static bool parse_intersection(rbs_parser_t *parser, rbs_node_t **type, bool void_allowed, bool self_allowed, bool classish_allowed) {
|
|
1311
1354
|
rbs_range_t rg;
|
|
1312
1355
|
rg.start = parser->next_token.range.start;
|
|
1313
1356
|
|
|
1314
1357
|
rbs_node_t *optional = NULL;
|
|
1315
|
-
CHECK_PARSE(parse_optional(parser, &optional, void_allowed, self_allowed));
|
|
1358
|
+
CHECK_PARSE(parse_optional(parser, &optional, void_allowed, self_allowed, classish_allowed));
|
|
1316
1359
|
*type = optional;
|
|
1317
1360
|
|
|
1318
1361
|
rbs_node_list_t *intersection_types = rbs_node_list_new(ALLOCATOR());
|
|
@@ -1326,15 +1369,14 @@ static bool parse_intersection(rbs_parser_t *parser, rbs_node_t **type, bool voi
|
|
|
1326
1369
|
|
|
1327
1370
|
rbs_parser_advance(parser);
|
|
1328
1371
|
rbs_node_t *type = NULL;
|
|
1329
|
-
CHECK_PARSE(parse_optional(parser, &type, false, self_allowed));
|
|
1372
|
+
CHECK_PARSE(parse_optional(parser, &type, false, self_allowed, classish_allowed));
|
|
1330
1373
|
rbs_node_list_append(intersection_types, type);
|
|
1331
1374
|
}
|
|
1332
1375
|
|
|
1333
1376
|
rg.end = parser->current_token.range.end;
|
|
1334
1377
|
|
|
1335
1378
|
if (intersection_types->length > 1) {
|
|
1336
|
-
|
|
1337
|
-
*type = (rbs_node_t *) rbs_types_intersection_new(ALLOCATOR(), location, intersection_types);
|
|
1379
|
+
*type = (rbs_node_t *) rbs_types_intersection_new(ALLOCATOR(), RBS_RANGE_LEX2AST(rg), intersection_types);
|
|
1338
1380
|
}
|
|
1339
1381
|
|
|
1340
1382
|
return true;
|
|
@@ -1344,12 +1386,12 @@ static bool parse_intersection(rbs_parser_t *parser, rbs_node_t **type, bool voi
|
|
|
1344
1386
|
union ::= {} intersection '|' ... '|' <intersection>
|
|
1345
1387
|
| {} <intersection>
|
|
1346
1388
|
*/
|
|
1347
|
-
bool rbs_parse_type(rbs_parser_t *parser, rbs_node_t **type, bool void_allowed, bool self_allowed) {
|
|
1389
|
+
bool rbs_parse_type(rbs_parser_t *parser, rbs_node_t **type, bool void_allowed, bool self_allowed, bool classish_allowed) {
|
|
1348
1390
|
rbs_range_t rg;
|
|
1349
1391
|
rg.start = parser->next_token.range.start;
|
|
1350
1392
|
rbs_node_list_t *union_types = rbs_node_list_new(ALLOCATOR());
|
|
1351
1393
|
|
|
1352
|
-
CHECK_PARSE(parse_intersection(parser, type, void_allowed, self_allowed));
|
|
1394
|
+
CHECK_PARSE(parse_intersection(parser, type, void_allowed, self_allowed, classish_allowed));
|
|
1353
1395
|
|
|
1354
1396
|
rbs_node_list_append(union_types, *type);
|
|
1355
1397
|
|
|
@@ -1361,15 +1403,14 @@ bool rbs_parse_type(rbs_parser_t *parser, rbs_node_t **type, bool void_allowed,
|
|
|
1361
1403
|
|
|
1362
1404
|
rbs_parser_advance(parser);
|
|
1363
1405
|
rbs_node_t *intersection = NULL;
|
|
1364
|
-
CHECK_PARSE(parse_intersection(parser, &intersection, false, self_allowed));
|
|
1406
|
+
CHECK_PARSE(parse_intersection(parser, &intersection, false, self_allowed, classish_allowed));
|
|
1365
1407
|
rbs_node_list_append(union_types, intersection);
|
|
1366
1408
|
}
|
|
1367
1409
|
|
|
1368
1410
|
rg.end = parser->current_token.range.end;
|
|
1369
1411
|
|
|
1370
1412
|
if (union_types->length > 1) {
|
|
1371
|
-
|
|
1372
|
-
*type = (rbs_node_t *) rbs_types_union_new(ALLOCATOR(), location, union_types);
|
|
1413
|
+
*type = (rbs_node_t *) rbs_types_union_new(ALLOCATOR(), RBS_RANGE_LEX2AST(rg), union_types);
|
|
1373
1414
|
}
|
|
1374
1415
|
|
|
1375
1416
|
return true;
|
|
@@ -1396,7 +1437,7 @@ static bool parse_type_params(rbs_parser_t *parser, rbs_range_t *rg, bool module
|
|
|
1396
1437
|
|
|
1397
1438
|
while (true) {
|
|
1398
1439
|
bool unchecked = false;
|
|
1399
|
-
|
|
1440
|
+
enum rbs_type_param_variance variance = RBS_TYPE_PARAM_VARIANCE_INVARIANT;
|
|
1400
1441
|
rbs_node_t *upper_bound = NULL;
|
|
1401
1442
|
rbs_node_t *lower_bound = NULL;
|
|
1402
1443
|
rbs_node_t *default_type = NULL;
|
|
@@ -1416,10 +1457,10 @@ static bool parse_type_params(rbs_parser_t *parser, rbs_range_t *rg, bool module
|
|
|
1416
1457
|
if (parser->next_token.type == kIN || parser->next_token.type == kOUT) {
|
|
1417
1458
|
switch (parser->next_token.type) {
|
|
1418
1459
|
case kIN:
|
|
1419
|
-
variance =
|
|
1460
|
+
variance = RBS_TYPE_PARAM_VARIANCE_CONTRAVARIANT;
|
|
1420
1461
|
break;
|
|
1421
1462
|
case kOUT:
|
|
1422
|
-
variance =
|
|
1463
|
+
variance = RBS_TYPE_PARAM_VARIANCE_COVARIANT;
|
|
1423
1464
|
break;
|
|
1424
1465
|
default:
|
|
1425
1466
|
rbs_parser_set_error(parser, parser->current_token, false, "Unexpected error");
|
|
@@ -1435,9 +1476,9 @@ static bool parse_type_params(rbs_parser_t *parser, rbs_range_t *rg, bool module
|
|
|
1435
1476
|
rbs_range_t name_range = parser->current_token.range;
|
|
1436
1477
|
|
|
1437
1478
|
rbs_string_t string = rbs_parser_peek_current_token(parser);
|
|
1438
|
-
|
|
1479
|
+
rbs_location_range name_symbol_range = rbs_location_range_current_token(parser);
|
|
1439
1480
|
rbs_constant_id_t id = rbs_constant_pool_insert_string(&parser->constant_pool, string);
|
|
1440
|
-
rbs_ast_symbol_t *name = rbs_ast_symbol_new(ALLOCATOR(),
|
|
1481
|
+
rbs_ast_symbol_t *name = rbs_ast_symbol_new(ALLOCATOR(), name_symbol_range, &parser->constant_pool, id);
|
|
1441
1482
|
|
|
1442
1483
|
CHECK_PARSE(rbs_parser_insert_typevar(parser, id));
|
|
1443
1484
|
|
|
@@ -1454,7 +1495,7 @@ static bool parse_type_params(rbs_parser_t *parser, rbs_range_t *rg, bool module
|
|
|
1454
1495
|
|
|
1455
1496
|
rbs_parser_advance(parser);
|
|
1456
1497
|
upper_bound_range.start = parser->current_token.range.start;
|
|
1457
|
-
CHECK_PARSE(rbs_parse_type(parser, &upper_bound, false, false));
|
|
1498
|
+
CHECK_PARSE(rbs_parse_type(parser, &upper_bound, false, false, false));
|
|
1458
1499
|
upper_bound_range.end = parser->current_token.range.end;
|
|
1459
1500
|
break;
|
|
1460
1501
|
|
|
@@ -1466,7 +1507,7 @@ static bool parse_type_params(rbs_parser_t *parser, rbs_range_t *rg, bool module
|
|
|
1466
1507
|
|
|
1467
1508
|
rbs_parser_advance(parser);
|
|
1468
1509
|
lower_bound_range.start = parser->current_token.range.start;
|
|
1469
|
-
CHECK_PARSE(rbs_parse_type(parser, &lower_bound, false, false));
|
|
1510
|
+
CHECK_PARSE(rbs_parse_type(parser, &lower_bound, false, false, false));
|
|
1470
1511
|
lower_bound_range.end = parser->current_token.range.end;
|
|
1471
1512
|
break;
|
|
1472
1513
|
|
|
@@ -1481,7 +1522,7 @@ static bool parse_type_params(rbs_parser_t *parser, rbs_range_t *rg, bool module
|
|
|
1481
1522
|
rbs_parser_advance(parser);
|
|
1482
1523
|
|
|
1483
1524
|
default_type_range.start = parser->current_token.range.start;
|
|
1484
|
-
CHECK_PARSE(rbs_parse_type(parser, &default_type, true, false));
|
|
1525
|
+
CHECK_PARSE(rbs_parse_type(parser, &default_type, true, false, false));
|
|
1485
1526
|
default_type_range.end = parser->current_token.range.end;
|
|
1486
1527
|
|
|
1487
1528
|
required_param_allowed = false;
|
|
@@ -1495,16 +1536,12 @@ static bool parse_type_params(rbs_parser_t *parser, rbs_range_t *rg, bool module
|
|
|
1495
1536
|
|
|
1496
1537
|
param_range.end = parser->current_token.range.end;
|
|
1497
1538
|
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
rbs_loc_add_optional_child(loc, INTERN("lower_bound"), lower_bound_range);
|
|
1505
|
-
rbs_loc_add_optional_child(loc, INTERN("default"), default_type_range);
|
|
1506
|
-
|
|
1507
|
-
rbs_ast_type_param_t *param = rbs_ast_type_param_new(ALLOCATOR(), loc, name, variance, upper_bound, lower_bound, default_type, unchecked);
|
|
1539
|
+
rbs_ast_type_param_t *param = rbs_ast_type_param_new(ALLOCATOR(), RBS_RANGE_LEX2AST(param_range), name, variance, upper_bound, lower_bound, default_type, unchecked, RBS_RANGE_LEX2AST(name_range));
|
|
1540
|
+
param->variance_range = RBS_RANGE_LEX2AST(variance_range);
|
|
1541
|
+
param->unchecked_range = RBS_RANGE_LEX2AST(unchecked_range);
|
|
1542
|
+
param->upper_bound_range = RBS_RANGE_LEX2AST(upper_bound_range);
|
|
1543
|
+
param->lower_bound_range = RBS_RANGE_LEX2AST(lower_bound_range);
|
|
1544
|
+
param->default_range = RBS_RANGE_LEX2AST(default_type_range);
|
|
1508
1545
|
|
|
1509
1546
|
rbs_node_list_append(*params, (rbs_node_t *) param);
|
|
1510
1547
|
|
|
@@ -1551,7 +1588,7 @@ static bool parser_pop_typevar_table(rbs_parser_t *parser) {
|
|
|
1551
1588
|
method_type ::= {} type_params <function>
|
|
1552
1589
|
*/
|
|
1553
1590
|
// TODO: Should this be NODISCARD?
|
|
1554
|
-
bool rbs_parse_method_type(rbs_parser_t *parser, rbs_method_type_t **method_type, bool require_eof) {
|
|
1591
|
+
bool rbs_parse_method_type(rbs_parser_t *parser, rbs_method_type_t **method_type, bool require_eof, bool classish_allowed) {
|
|
1555
1592
|
rbs_parser_push_typevar_table(parser, false);
|
|
1556
1593
|
|
|
1557
1594
|
rbs_range_t rg;
|
|
@@ -1565,7 +1602,7 @@ bool rbs_parse_method_type(rbs_parser_t *parser, rbs_method_type_t **method_type
|
|
|
1565
1602
|
type_range.start = parser->next_token.range.start;
|
|
1566
1603
|
|
|
1567
1604
|
parse_function_result *result = rbs_allocator_alloc(ALLOCATOR(), parse_function_result);
|
|
1568
|
-
CHECK_PARSE(parse_function(parser, false, &result, true));
|
|
1605
|
+
CHECK_PARSE(parse_function(parser, false, true, &result, true, classish_allowed));
|
|
1569
1606
|
|
|
1570
1607
|
CHECK_PARSE(parser_pop_typevar_table(parser));
|
|
1571
1608
|
|
|
@@ -1580,12 +1617,9 @@ bool rbs_parse_method_type(rbs_parser_t *parser, rbs_method_type_t **method_type
|
|
|
1580
1617
|
}
|
|
1581
1618
|
}
|
|
1582
1619
|
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
rbs_loc_add_required_child(loc, INTERN("type"), type_range);
|
|
1586
|
-
rbs_loc_add_optional_child(loc, INTERN("type_params"), params_range);
|
|
1620
|
+
*method_type = rbs_method_type_new(ALLOCATOR(), RBS_RANGE_LEX2AST(rg), type_params, result->function, result->block, RBS_RANGE_LEX2AST(type_range));
|
|
1621
|
+
(*method_type)->type_params_range = RBS_RANGE_LEX2AST(params_range);
|
|
1587
1622
|
|
|
1588
|
-
*method_type = rbs_method_type_new(ALLOCATOR(), loc, type_params, result->function, result->block);
|
|
1589
1623
|
return true;
|
|
1590
1624
|
}
|
|
1591
1625
|
|
|
@@ -1600,23 +1634,17 @@ static bool parse_global_decl(rbs_parser_t *parser, rbs_node_list_t *annotations
|
|
|
1600
1634
|
rbs_ast_comment_t *comment = rbs_parser_get_comment(parser, decl_range.start.line);
|
|
1601
1635
|
|
|
1602
1636
|
rbs_range_t name_range = parser->current_token.range;
|
|
1603
|
-
rbs_location_t *symbolLoc = rbs_location_new(ALLOCATOR(), name_range);
|
|
1604
1637
|
|
|
1605
|
-
rbs_ast_symbol_t *type_name = rbs_ast_symbol_new(ALLOCATOR(),
|
|
1638
|
+
rbs_ast_symbol_t *type_name = rbs_ast_symbol_new(ALLOCATOR(), RBS_RANGE_LEX2AST(name_range), &parser->constant_pool, INTERN_TOKEN(parser, parser->current_token));
|
|
1606
1639
|
|
|
1607
1640
|
ADVANCE_ASSERT(parser, pCOLON);
|
|
1608
1641
|
rbs_range_t colon_range = parser->current_token.range;
|
|
1609
1642
|
|
|
1610
1643
|
rbs_node_t *type;
|
|
1611
|
-
CHECK_PARSE(rbs_parse_type(parser, &type, false, false));
|
|
1644
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, false, false, false));
|
|
1612
1645
|
decl_range.end = parser->current_token.range.end;
|
|
1613
1646
|
|
|
1614
|
-
|
|
1615
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 2);
|
|
1616
|
-
rbs_loc_add_required_child(loc, INTERN("name"), name_range);
|
|
1617
|
-
rbs_loc_add_required_child(loc, INTERN("colon"), colon_range);
|
|
1618
|
-
|
|
1619
|
-
*global = rbs_ast_declarations_global_new(ALLOCATOR(), loc, type_name, type, comment, annotations);
|
|
1647
|
+
*global = rbs_ast_declarations_global_new(ALLOCATOR(), RBS_RANGE_LEX2AST(decl_range), type_name, type, comment, annotations, RBS_RANGE_LEX2AST(name_range), RBS_RANGE_LEX2AST(colon_range));
|
|
1620
1648
|
return true;
|
|
1621
1649
|
}
|
|
1622
1650
|
|
|
@@ -1638,16 +1666,11 @@ static bool parse_const_decl(rbs_parser_t *parser, rbs_node_list_t *annotations,
|
|
|
1638
1666
|
rbs_range_t colon_range = parser->current_token.range;
|
|
1639
1667
|
|
|
1640
1668
|
rbs_node_t *type;
|
|
1641
|
-
CHECK_PARSE(rbs_parse_type(parser, &type, false, false));
|
|
1669
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, false, false, false));
|
|
1642
1670
|
|
|
1643
1671
|
decl_range.end = parser->current_token.range.end;
|
|
1644
1672
|
|
|
1645
|
-
|
|
1646
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 2);
|
|
1647
|
-
rbs_loc_add_required_child(loc, INTERN("name"), name_range);
|
|
1648
|
-
rbs_loc_add_required_child(loc, INTERN("colon"), colon_range);
|
|
1649
|
-
|
|
1650
|
-
*constant = rbs_ast_declarations_constant_new(ALLOCATOR(), loc, type_name, type, comment, annotations);
|
|
1673
|
+
*constant = rbs_ast_declarations_constant_new(ALLOCATOR(), RBS_RANGE_LEX2AST(decl_range), type_name, type, comment, annotations, RBS_RANGE_LEX2AST(name_range), RBS_RANGE_LEX2AST(colon_range));
|
|
1651
1674
|
return true;
|
|
1652
1675
|
}
|
|
1653
1676
|
|
|
@@ -1678,22 +1701,16 @@ static bool parse_type_decl(rbs_parser_t *parser, rbs_position_t comment_pos, rb
|
|
|
1678
1701
|
rbs_range_t eq_range = parser->current_token.range;
|
|
1679
1702
|
|
|
1680
1703
|
rbs_node_t *type;
|
|
1681
|
-
CHECK_PARSE(rbs_parse_type(parser, &type, false, false));
|
|
1704
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, false, false, false));
|
|
1682
1705
|
|
|
1683
1706
|
decl_range.end = parser->current_token.range.end;
|
|
1684
1707
|
|
|
1685
|
-
rbs_location_t *loc = rbs_location_new(ALLOCATOR(), decl_range);
|
|
1686
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 4);
|
|
1687
|
-
rbs_loc_add_required_child(loc, INTERN("keyword"), keyword_range);
|
|
1688
|
-
rbs_loc_add_required_child(loc, INTERN("name"), name_range);
|
|
1689
|
-
rbs_loc_add_optional_child(loc, INTERN("type_params"), params_range);
|
|
1690
|
-
rbs_loc_add_required_child(loc, INTERN("eq"), eq_range);
|
|
1691
|
-
|
|
1692
1708
|
CHECK_PARSE(parser_pop_typevar_table(parser));
|
|
1693
1709
|
|
|
1694
1710
|
rbs_ast_comment_t *comment = rbs_parser_get_comment(parser, comment_pos.line);
|
|
1695
1711
|
|
|
1696
|
-
*typealias = rbs_ast_declarations_type_alias_new(ALLOCATOR(),
|
|
1712
|
+
*typealias = rbs_ast_declarations_type_alias_new(ALLOCATOR(), RBS_RANGE_LEX2AST(decl_range), type_name, type_params, type, annotations, comment, RBS_RANGE_LEX2AST(keyword_range), RBS_RANGE_LEX2AST(name_range), RBS_RANGE_LEX2AST(eq_range));
|
|
1713
|
+
(*typealias)->type_params_range = RBS_RANGE_LEX2AST(params_range);
|
|
1697
1714
|
return true;
|
|
1698
1715
|
}
|
|
1699
1716
|
|
|
@@ -1752,7 +1769,7 @@ static bool parse_annotation(rbs_parser_t *parser, rbs_ast_annotation_t **annota
|
|
|
1752
1769
|
|
|
1753
1770
|
rbs_string_t stripped_annotation_str = rbs_string_strip_whitespace(&annotation_str);
|
|
1754
1771
|
|
|
1755
|
-
*annotation = rbs_ast_annotation_new(ALLOCATOR(),
|
|
1772
|
+
*annotation = rbs_ast_annotation_new(ALLOCATOR(), RBS_RANGE_LEX2AST(rg), stripped_annotation_str);
|
|
1756
1773
|
return true;
|
|
1757
1774
|
}
|
|
1758
1775
|
|
|
@@ -1809,28 +1826,24 @@ static bool parse_method_name(rbs_parser_t *parser, rbs_range_t *range, rbs_ast_
|
|
|
1809
1826
|
parser->lexer->encoding
|
|
1810
1827
|
);
|
|
1811
1828
|
|
|
1812
|
-
|
|
1813
|
-
*symbol = rbs_ast_symbol_new(ALLOCATOR(), symbolLoc, &parser->constant_pool, constant_id);
|
|
1829
|
+
*symbol = rbs_ast_symbol_new(ALLOCATOR(), RBS_RANGE_LEX2AST(*range), &parser->constant_pool, constant_id);
|
|
1814
1830
|
} else {
|
|
1815
1831
|
*range = parser->current_token.range;
|
|
1816
|
-
|
|
1817
|
-
*symbol = rbs_ast_symbol_new(ALLOCATOR(), symbolLoc, &parser->constant_pool, INTERN_TOKEN(parser, parser->current_token));
|
|
1832
|
+
*symbol = rbs_ast_symbol_new(ALLOCATOR(), RBS_RANGE_LEX2AST(*range), &parser->constant_pool, INTERN_TOKEN(parser, parser->current_token));
|
|
1818
1833
|
}
|
|
1819
1834
|
return true;
|
|
1820
1835
|
|
|
1821
1836
|
case tBANGIDENT:
|
|
1822
1837
|
case tEQIDENT: {
|
|
1823
1838
|
*range = parser->current_token.range;
|
|
1824
|
-
|
|
1825
|
-
*symbol = rbs_ast_symbol_new(ALLOCATOR(), symbolLoc, &parser->constant_pool, INTERN_TOKEN(parser, parser->current_token));
|
|
1839
|
+
*symbol = rbs_ast_symbol_new(ALLOCATOR(), RBS_RANGE_LEX2AST(*range), &parser->constant_pool, INTERN_TOKEN(parser, parser->current_token));
|
|
1826
1840
|
return true;
|
|
1827
1841
|
}
|
|
1828
1842
|
case tQIDENT: {
|
|
1829
1843
|
rbs_string_t string = rbs_parser_peek_current_token(parser);
|
|
1830
1844
|
rbs_string_t unquoted_str = rbs_unquote_string(ALLOCATOR(), string, parser->lexer->encoding);
|
|
1831
1845
|
rbs_constant_id_t constant_id = rbs_constant_pool_insert_string(&parser->constant_pool, unquoted_str);
|
|
1832
|
-
|
|
1833
|
-
*symbol = rbs_ast_symbol_new(ALLOCATOR(), symbolLoc, &parser->constant_pool, constant_id);
|
|
1846
|
+
*symbol = rbs_ast_symbol_new(ALLOCATOR(), rbs_location_range_current_token(parser), &parser->constant_pool, constant_id);
|
|
1834
1847
|
return true;
|
|
1835
1848
|
}
|
|
1836
1849
|
|
|
@@ -1844,8 +1857,7 @@ static bool parse_method_name(rbs_parser_t *parser, rbs_range_t *range, rbs_ast_
|
|
|
1844
1857
|
case pAREF_OPR:
|
|
1845
1858
|
case tOPERATOR: {
|
|
1846
1859
|
*range = parser->current_token.range;
|
|
1847
|
-
|
|
1848
|
-
*symbol = rbs_ast_symbol_new(ALLOCATOR(), symbolLoc, &parser->constant_pool, INTERN_TOKEN(parser, parser->current_token));
|
|
1860
|
+
*symbol = rbs_ast_symbol_new(ALLOCATOR(), RBS_RANGE_LEX2AST(*range), &parser->constant_pool, INTERN_TOKEN(parser, parser->current_token));
|
|
1849
1861
|
return true;
|
|
1850
1862
|
}
|
|
1851
1863
|
|
|
@@ -1919,25 +1931,25 @@ static bool parse_member_def(rbs_parser_t *parser, bool instance_only, bool acce
|
|
|
1919
1931
|
rbs_ast_comment_t *comment = rbs_parser_get_comment(parser, comment_pos.line);
|
|
1920
1932
|
|
|
1921
1933
|
rbs_range_t visibility_range;
|
|
1922
|
-
|
|
1934
|
+
enum rbs_method_definition_visibility visibility;
|
|
1923
1935
|
switch (parser->current_token.type) {
|
|
1924
1936
|
case kPRIVATE: {
|
|
1925
1937
|
visibility_range = parser->current_token.range;
|
|
1926
|
-
visibility =
|
|
1938
|
+
visibility = RBS_METHOD_DEFINITION_VISIBILITY_PRIVATE;
|
|
1927
1939
|
member_range.start = visibility_range.start;
|
|
1928
1940
|
rbs_parser_advance(parser);
|
|
1929
1941
|
break;
|
|
1930
1942
|
}
|
|
1931
1943
|
case kPUBLIC: {
|
|
1932
1944
|
visibility_range = parser->current_token.range;
|
|
1933
|
-
visibility =
|
|
1945
|
+
visibility = RBS_METHOD_DEFINITION_VISIBILITY_PUBLIC;
|
|
1934
1946
|
member_range.start = visibility_range.start;
|
|
1935
1947
|
rbs_parser_advance(parser);
|
|
1936
1948
|
break;
|
|
1937
1949
|
}
|
|
1938
1950
|
default:
|
|
1939
1951
|
visibility_range = NULL_RANGE;
|
|
1940
|
-
visibility =
|
|
1952
|
+
visibility = RBS_METHOD_DEFINITION_VISIBILITY_UNSPECIFIED;
|
|
1941
1953
|
break;
|
|
1942
1954
|
}
|
|
1943
1955
|
|
|
@@ -1949,7 +1961,7 @@ static bool parse_member_def(rbs_parser_t *parser, bool instance_only, bool acce
|
|
|
1949
1961
|
kind_range = NULL_RANGE;
|
|
1950
1962
|
kind = INSTANCE_KIND;
|
|
1951
1963
|
} else {
|
|
1952
|
-
kind = parse_instance_singleton_kind(parser, visibility ==
|
|
1964
|
+
kind = parse_instance_singleton_kind(parser, visibility == RBS_METHOD_DEFINITION_VISIBILITY_UNSPECIFIED, &kind_range);
|
|
1953
1965
|
}
|
|
1954
1966
|
|
|
1955
1967
|
rbs_range_t name_range;
|
|
@@ -1989,11 +2001,10 @@ static bool parse_member_def(rbs_parser_t *parser, bool instance_only, bool acce
|
|
|
1989
2001
|
case pLBRACKET:
|
|
1990
2002
|
case pQUESTION: {
|
|
1991
2003
|
rbs_method_type_t *method_type = NULL;
|
|
1992
|
-
CHECK_PARSE(rbs_parse_method_type(parser, &method_type, false));
|
|
2004
|
+
CHECK_PARSE(rbs_parse_method_type(parser, &method_type, false, !instance_only));
|
|
1993
2005
|
|
|
1994
2006
|
overload_range.end = parser->current_token.range.end;
|
|
1995
|
-
|
|
1996
|
-
rbs_node_t *overload = (rbs_node_t *) rbs_ast_members_method_definition_overload_new(ALLOCATOR(), loc, annotations, (rbs_node_t *) method_type);
|
|
2007
|
+
rbs_node_t *overload = (rbs_node_t *) rbs_ast_members_method_definition_overload_new(ALLOCATOR(), RBS_RANGE_LEX2AST(overload_range), annotations, (rbs_node_t *) method_type);
|
|
1997
2008
|
rbs_node_list_append(overloads, overload);
|
|
1998
2009
|
member_range.end = parser->current_token.range.end;
|
|
1999
2010
|
break;
|
|
@@ -2026,18 +2037,18 @@ static bool parse_member_def(rbs_parser_t *parser, bool instance_only, bool acce
|
|
|
2026
2037
|
|
|
2027
2038
|
CHECK_PARSE(parser_pop_typevar_table(parser));
|
|
2028
2039
|
|
|
2029
|
-
|
|
2040
|
+
enum rbs_method_definition_kind k;
|
|
2030
2041
|
switch (kind) {
|
|
2031
2042
|
case INSTANCE_KIND: {
|
|
2032
|
-
k =
|
|
2043
|
+
k = RBS_METHOD_DEFINITION_KIND_INSTANCE;
|
|
2033
2044
|
break;
|
|
2034
2045
|
}
|
|
2035
2046
|
case SINGLETON_KIND: {
|
|
2036
|
-
k =
|
|
2047
|
+
k = RBS_METHOD_DEFINITION_KIND_SINGLETON;
|
|
2037
2048
|
break;
|
|
2038
2049
|
}
|
|
2039
2050
|
case INSTANCE_SINGLETON_KIND: {
|
|
2040
|
-
k =
|
|
2051
|
+
k = RBS_METHOD_DEFINITION_KIND_SINGLETON_INSTANCE;
|
|
2041
2052
|
break;
|
|
2042
2053
|
}
|
|
2043
2054
|
default:
|
|
@@ -2045,15 +2056,11 @@ static bool parse_member_def(rbs_parser_t *parser, bool instance_only, bool acce
|
|
|
2045
2056
|
return false;
|
|
2046
2057
|
}
|
|
2047
2058
|
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
rbs_loc_add_optional_child(loc, INTERN("kind"), kind_range);
|
|
2053
|
-
rbs_loc_add_optional_child(loc, INTERN("overloading"), overloading_range);
|
|
2054
|
-
rbs_loc_add_optional_child(loc, INTERN("visibility"), visibility_range);
|
|
2059
|
+
*method_definition = rbs_ast_members_method_definition_new(ALLOCATOR(), RBS_RANGE_LEX2AST(member_range), name, k, overloads, annotations, comment, overloading, visibility, RBS_RANGE_LEX2AST(keyword_range), RBS_RANGE_LEX2AST(name_range));
|
|
2060
|
+
(*method_definition)->kind_range = RBS_RANGE_LEX2AST(kind_range);
|
|
2061
|
+
(*method_definition)->overloading_range = RBS_RANGE_LEX2AST(overloading_range);
|
|
2062
|
+
(*method_definition)->visibility_range = RBS_RANGE_LEX2AST(visibility_range);
|
|
2055
2063
|
|
|
2056
|
-
*method_definition = rbs_ast_members_method_definition_new(ALLOCATOR(), loc, name, k, overloads, annotations, comment, overloading, visibility);
|
|
2057
2064
|
return true;
|
|
2058
2065
|
}
|
|
2059
2066
|
|
|
@@ -2064,7 +2071,7 @@ static bool parse_member_def(rbs_parser_t *parser, bool instance_only, bool acce
|
|
|
2064
2071
|
* @param kind
|
|
2065
2072
|
* */
|
|
2066
2073
|
NODISCARD
|
|
2067
|
-
static bool class_instance_name(rbs_parser_t *parser, TypeNameKind kind, rbs_node_list_t *args, rbs_range_t *name_range, rbs_range_t *args_range, rbs_type_name_t **name) {
|
|
2074
|
+
static bool class_instance_name(rbs_parser_t *parser, TypeNameKind kind, rbs_node_list_t *args, rbs_range_t *name_range, rbs_range_t *args_range, rbs_type_name_t **name, bool classish_allowed) {
|
|
2068
2075
|
rbs_parser_advance(parser);
|
|
2069
2076
|
|
|
2070
2077
|
rbs_type_name_t *type_name = NULL;
|
|
@@ -2074,7 +2081,7 @@ static bool class_instance_name(rbs_parser_t *parser, TypeNameKind kind, rbs_nod
|
|
|
2074
2081
|
if (parser->next_token.type == pLBRACKET) {
|
|
2075
2082
|
rbs_parser_advance(parser);
|
|
2076
2083
|
args_range->start = parser->current_token.range.start;
|
|
2077
|
-
CHECK_PARSE(parse_type_list(parser, pRBRACKET, args, true, false));
|
|
2084
|
+
CHECK_PARSE(parse_type_list(parser, pRBRACKET, args, true, false, classish_allowed));
|
|
2078
2085
|
ADVANCE_ASSERT(parser, pRBRACKET);
|
|
2079
2086
|
args_range->end = parser->current_token.range.end;
|
|
2080
2087
|
} else {
|
|
@@ -2135,30 +2142,39 @@ static bool parse_mixin_member(rbs_parser_t *parser, bool from_interface, rbs_po
|
|
|
2135
2142
|
args,
|
|
2136
2143
|
&name_range,
|
|
2137
2144
|
&args_range,
|
|
2138
|
-
&name
|
|
2145
|
+
&name,
|
|
2146
|
+
!from_interface
|
|
2139
2147
|
));
|
|
2140
2148
|
|
|
2141
2149
|
CHECK_PARSE(parser_pop_typevar_table(parser));
|
|
2142
2150
|
|
|
2143
2151
|
member_range.end = parser->current_token.range.end;
|
|
2144
2152
|
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
rbs_loc_add_optional_child(loc, INTERN("args"), args_range);
|
|
2153
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(member_range);
|
|
2154
|
+
rbs_location_range name_rg = RBS_RANGE_LEX2AST(name_range);
|
|
2155
|
+
rbs_location_range keyword_rg = RBS_RANGE_LEX2AST(keyword_range);
|
|
2156
|
+
rbs_location_range args_rg = RBS_RANGE_LEX2AST(args_range);
|
|
2150
2157
|
|
|
2151
2158
|
rbs_ast_comment_t *comment = rbs_parser_get_comment(parser, comment_pos.line);
|
|
2152
2159
|
switch (type) {
|
|
2153
|
-
case kINCLUDE:
|
|
2154
|
-
*
|
|
2160
|
+
case kINCLUDE: {
|
|
2161
|
+
rbs_ast_members_include_t *include_member = rbs_ast_members_include_new(ALLOCATOR(), loc, name, args, annotations, comment, name_rg, keyword_rg);
|
|
2162
|
+
include_member->args_range = args_rg;
|
|
2163
|
+
*mixin_member = (rbs_node_t *) include_member;
|
|
2155
2164
|
return true;
|
|
2156
|
-
|
|
2157
|
-
|
|
2165
|
+
}
|
|
2166
|
+
case kEXTEND: {
|
|
2167
|
+
rbs_ast_members_extend_t *extend_member = rbs_ast_members_extend_new(ALLOCATOR(), loc, name, args, annotations, comment, name_rg, keyword_rg);
|
|
2168
|
+
extend_member->args_range = args_rg;
|
|
2169
|
+
*mixin_member = (rbs_node_t *) extend_member;
|
|
2158
2170
|
return true;
|
|
2159
|
-
|
|
2160
|
-
|
|
2171
|
+
}
|
|
2172
|
+
case kPREPEND: {
|
|
2173
|
+
rbs_ast_members_prepend_t *prepend_member = rbs_ast_members_prepend_new(ALLOCATOR(), loc, name, args, annotations, comment, name_rg, keyword_rg);
|
|
2174
|
+
prepend_member->args_range = args_rg;
|
|
2175
|
+
*mixin_member = (rbs_node_t *) prepend_member;
|
|
2161
2176
|
return true;
|
|
2177
|
+
}
|
|
2162
2178
|
default:
|
|
2163
2179
|
rbs_parser_set_error(parser, parser->current_token, false, "Unexpected error");
|
|
2164
2180
|
return false;
|
|
@@ -2182,12 +2198,12 @@ static bool parse_alias_member(rbs_parser_t *parser, bool instance_only, rbs_pos
|
|
|
2182
2198
|
comment_pos = rbs_nonnull_pos_or(comment_pos, member_range.start);
|
|
2183
2199
|
rbs_ast_comment_t *comment = rbs_parser_get_comment(parser, comment_pos.line);
|
|
2184
2200
|
|
|
2185
|
-
|
|
2201
|
+
enum rbs_alias_kind kind;
|
|
2186
2202
|
rbs_ast_symbol_t *new_name, *old_name;
|
|
2187
2203
|
rbs_range_t new_kind_range, old_kind_range, new_name_range, old_name_range;
|
|
2188
2204
|
|
|
2189
2205
|
if (!instance_only && parser->next_token.type == kSELF) {
|
|
2190
|
-
kind =
|
|
2206
|
+
kind = RBS_ALIAS_KIND_SINGLETON;
|
|
2191
2207
|
|
|
2192
2208
|
new_kind_range.start = parser->next_token.range.start;
|
|
2193
2209
|
new_kind_range.end = parser->next_token2.range.end;
|
|
@@ -2201,7 +2217,7 @@ static bool parse_alias_member(rbs_parser_t *parser, bool instance_only, rbs_pos
|
|
|
2201
2217
|
ADVANCE_ASSERT(parser, pDOT);
|
|
2202
2218
|
CHECK_PARSE(parse_method_name(parser, &old_name_range, &old_name));
|
|
2203
2219
|
} else {
|
|
2204
|
-
kind =
|
|
2220
|
+
kind = RBS_ALIAS_KIND_INSTANCE;
|
|
2205
2221
|
CHECK_PARSE(parse_method_name(parser, &new_name_range, &new_name));
|
|
2206
2222
|
CHECK_PARSE(parse_method_name(parser, &old_name_range, &old_name));
|
|
2207
2223
|
new_kind_range = NULL_RANGE;
|
|
@@ -2209,15 +2225,13 @@ static bool parse_alias_member(rbs_parser_t *parser, bool instance_only, rbs_pos
|
|
|
2209
2225
|
}
|
|
2210
2226
|
|
|
2211
2227
|
member_range.end = parser->current_token.range.end;
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
*alias_member = rbs_ast_members_alias_new(ALLOCATOR(), loc, new_name, old_name, kind, annotations, comment);
|
|
2228
|
+
|
|
2229
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(member_range);
|
|
2230
|
+
|
|
2231
|
+
*alias_member = rbs_ast_members_alias_new(ALLOCATOR(), loc, new_name, old_name, kind, annotations, comment, RBS_RANGE_LEX2AST(keyword_range), RBS_RANGE_LEX2AST(new_name_range), RBS_RANGE_LEX2AST(old_name_range));
|
|
2232
|
+
(*alias_member)->new_kind_range = RBS_RANGE_LEX2AST(new_kind_range);
|
|
2233
|
+
(*alias_member)->old_kind_range = RBS_RANGE_LEX2AST(old_kind_range);
|
|
2234
|
+
|
|
2221
2235
|
return true;
|
|
2222
2236
|
}
|
|
2223
2237
|
|
|
@@ -2242,29 +2256,26 @@ static bool parse_variable_member(rbs_parser_t *parser, rbs_position_t comment_p
|
|
|
2242
2256
|
case tAIDENT:
|
|
2243
2257
|
case kATRBS: {
|
|
2244
2258
|
rbs_range_t name_range = parser->current_token.range;
|
|
2245
|
-
|
|
2259
|
+
rbs_location_range symbolLoc = RBS_RANGE_LEX2AST(name_range);
|
|
2246
2260
|
rbs_ast_symbol_t *name = rbs_ast_symbol_new(ALLOCATOR(), symbolLoc, &parser->constant_pool, INTERN_TOKEN(parser, parser->current_token));
|
|
2247
2261
|
|
|
2248
2262
|
ADVANCE_ASSERT(parser, pCOLON);
|
|
2249
2263
|
rbs_range_t colon_range = parser->current_token.range;
|
|
2250
2264
|
|
|
2251
2265
|
rbs_node_t *type;
|
|
2252
|
-
CHECK_PARSE(rbs_parse_type(parser, &type, false, true));
|
|
2266
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, false, true, true));
|
|
2253
2267
|
member_range.end = parser->current_token.range.end;
|
|
2254
2268
|
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
rbs_loc_add_required_child(loc, INTERN("colon"), colon_range);
|
|
2259
|
-
rbs_loc_add_optional_child(loc, INTERN("kind"), NULL_RANGE);
|
|
2269
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(member_range);
|
|
2270
|
+
|
|
2271
|
+
*variable_member = (rbs_node_t *) rbs_ast_members_instance_variable_new(ALLOCATOR(), loc, name, type, comment, RBS_RANGE_LEX2AST(name_range), RBS_RANGE_LEX2AST(colon_range));
|
|
2260
2272
|
|
|
2261
|
-
*variable_member = (rbs_node_t *) rbs_ast_members_instance_variable_new(ALLOCATOR(), loc, name, type, comment);
|
|
2262
2273
|
return true;
|
|
2263
2274
|
}
|
|
2264
2275
|
case tA2IDENT: {
|
|
2265
2276
|
rbs_range_t name_range = parser->current_token.range;
|
|
2266
|
-
|
|
2267
|
-
rbs_ast_symbol_t *name = rbs_ast_symbol_new(ALLOCATOR(),
|
|
2277
|
+
rbs_location_range symbol_loc = RBS_RANGE_LEX2AST(name_range);
|
|
2278
|
+
rbs_ast_symbol_t *name = rbs_ast_symbol_new(ALLOCATOR(), symbol_loc, &parser->constant_pool, INTERN_TOKEN(parser, parser->current_token));
|
|
2268
2279
|
|
|
2269
2280
|
ADVANCE_ASSERT(parser, pCOLON);
|
|
2270
2281
|
rbs_range_t colon_range = parser->current_token.range;
|
|
@@ -2272,19 +2283,16 @@ static bool parse_variable_member(rbs_parser_t *parser, rbs_position_t comment_p
|
|
|
2272
2283
|
rbs_parser_push_typevar_table(parser, true);
|
|
2273
2284
|
|
|
2274
2285
|
rbs_node_t *type;
|
|
2275
|
-
CHECK_PARSE(rbs_parse_type(parser, &type, false, false));
|
|
2286
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, false, false, true));
|
|
2276
2287
|
|
|
2277
2288
|
CHECK_PARSE(parser_pop_typevar_table(parser));
|
|
2278
2289
|
|
|
2279
2290
|
member_range.end = parser->current_token.range.end;
|
|
2280
2291
|
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
rbs_loc_add_required_child(loc, INTERN("colon"), colon_range);
|
|
2285
|
-
rbs_loc_add_optional_child(loc, INTERN("kind"), NULL_RANGE);
|
|
2292
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(member_range);
|
|
2293
|
+
|
|
2294
|
+
*variable_member = (rbs_node_t *) rbs_ast_members_class_variable_new(ALLOCATOR(), loc, name, type, comment, RBS_RANGE_LEX2AST(name_range), RBS_RANGE_LEX2AST(colon_range));
|
|
2286
2295
|
|
|
2287
|
-
*variable_member = (rbs_node_t *) rbs_ast_members_class_variable_new(ALLOCATOR(), loc, name, type, comment);
|
|
2288
2296
|
return true;
|
|
2289
2297
|
}
|
|
2290
2298
|
case kSELF: {
|
|
@@ -2302,8 +2310,8 @@ static bool parse_variable_member(rbs_parser_t *parser, rbs_position_t comment_p
|
|
|
2302
2310
|
}
|
|
2303
2311
|
|
|
2304
2312
|
rbs_range_t name_range = parser->current_token.range;
|
|
2305
|
-
|
|
2306
|
-
rbs_ast_symbol_t *name = rbs_ast_symbol_new(ALLOCATOR(),
|
|
2313
|
+
rbs_location_range symbol_loc = RBS_RANGE_LEX2AST(name_range);
|
|
2314
|
+
rbs_ast_symbol_t *name = rbs_ast_symbol_new(ALLOCATOR(), symbol_loc, &parser->constant_pool, INTERN_TOKEN(parser, parser->current_token));
|
|
2307
2315
|
|
|
2308
2316
|
ADVANCE_ASSERT(parser, pCOLON);
|
|
2309
2317
|
rbs_range_t colon_range = parser->current_token.range;
|
|
@@ -2311,19 +2319,19 @@ static bool parse_variable_member(rbs_parser_t *parser, rbs_position_t comment_p
|
|
|
2311
2319
|
rbs_parser_push_typevar_table(parser, true);
|
|
2312
2320
|
|
|
2313
2321
|
rbs_node_t *type;
|
|
2314
|
-
CHECK_PARSE(rbs_parse_type(parser, &type, false, true));
|
|
2322
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, false, true, true));
|
|
2315
2323
|
|
|
2316
2324
|
CHECK_PARSE(parser_pop_typevar_table(parser));
|
|
2317
2325
|
|
|
2318
2326
|
member_range.end = parser->current_token.range.end;
|
|
2319
2327
|
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2328
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(member_range);
|
|
2329
|
+
|
|
2330
|
+
rbs_ast_members_class_instance_variable_t *class_ivar_member = rbs_ast_members_class_instance_variable_new(ALLOCATOR(), loc, name, type, comment, RBS_RANGE_LEX2AST(name_range), RBS_RANGE_LEX2AST(colon_range));
|
|
2331
|
+
class_ivar_member->kind_range = RBS_RANGE_LEX2AST(kind_range);
|
|
2332
|
+
|
|
2333
|
+
*variable_member = (rbs_node_t *) class_ivar_member;
|
|
2325
2334
|
|
|
2326
|
-
*variable_member = (rbs_node_t *) rbs_ast_members_class_instance_variable_new(ALLOCATOR(), loc, name, type, comment);
|
|
2327
2335
|
return true;
|
|
2328
2336
|
}
|
|
2329
2337
|
default:
|
|
@@ -2343,7 +2351,7 @@ static bool parse_visibility_member(rbs_parser_t *parser, rbs_node_list_t *annot
|
|
|
2343
2351
|
return false;
|
|
2344
2352
|
}
|
|
2345
2353
|
|
|
2346
|
-
|
|
2354
|
+
rbs_location_range location = rbs_location_range_current_token(parser);
|
|
2347
2355
|
|
|
2348
2356
|
switch (parser->current_token.type) {
|
|
2349
2357
|
case kPUBLIC: {
|
|
@@ -2383,22 +2391,23 @@ static bool parse_attribute_member(rbs_parser_t *parser, rbs_position_t comment_
|
|
|
2383
2391
|
rbs_ast_comment_t *comment = rbs_parser_get_comment(parser, comment_pos.line);
|
|
2384
2392
|
|
|
2385
2393
|
rbs_range_t visibility_range;
|
|
2386
|
-
|
|
2394
|
+
enum rbs_attribute_visibility visibility;
|
|
2395
|
+
|
|
2387
2396
|
switch (parser->current_token.type) {
|
|
2388
2397
|
case kPRIVATE: {
|
|
2389
2398
|
visibility_range = parser->current_token.range;
|
|
2390
|
-
visibility =
|
|
2399
|
+
visibility = RBS_ATTRIBUTE_VISIBILITY_PRIVATE;
|
|
2391
2400
|
rbs_parser_advance(parser);
|
|
2392
2401
|
break;
|
|
2393
2402
|
}
|
|
2394
2403
|
case kPUBLIC: {
|
|
2395
2404
|
visibility_range = parser->current_token.range;
|
|
2396
|
-
visibility =
|
|
2405
|
+
visibility = RBS_ATTRIBUTE_VISIBILITY_PUBLIC;
|
|
2397
2406
|
rbs_parser_advance(parser);
|
|
2398
2407
|
break;
|
|
2399
2408
|
}
|
|
2400
2409
|
default:
|
|
2401
|
-
visibility =
|
|
2410
|
+
visibility = RBS_ATTRIBUTE_VISIBILITY_UNSPECIFIED;
|
|
2402
2411
|
visibility_range = NULL_RANGE;
|
|
2403
2412
|
break;
|
|
2404
2413
|
}
|
|
@@ -2409,41 +2418,31 @@ static bool parse_attribute_member(rbs_parser_t *parser, rbs_position_t comment_
|
|
|
2409
2418
|
rbs_range_t kind_range;
|
|
2410
2419
|
InstanceSingletonKind is_kind = parse_instance_singleton_kind(parser, false, &kind_range);
|
|
2411
2420
|
|
|
2412
|
-
|
|
2413
|
-
ALLOCATOR(),
|
|
2414
|
-
rbs_location_new(ALLOCATOR(), keyword_range),
|
|
2415
|
-
INTERN(((is_kind == INSTANCE_KIND) ? "instance" : "singleton"))
|
|
2416
|
-
);
|
|
2421
|
+
enum rbs_attribute_kind kind = (is_kind == INSTANCE_KIND) ? RBS_ATTRIBUTE_KIND_INSTANCE : RBS_ATTRIBUTE_KIND_SINGLETON;
|
|
2417
2422
|
|
|
2418
2423
|
rbs_range_t name_range;
|
|
2419
2424
|
rbs_ast_symbol_t *attr_name;
|
|
2420
2425
|
CHECK_PARSE(parse_method_name(parser, &name_range, &attr_name));
|
|
2421
2426
|
|
|
2422
|
-
|
|
2423
|
-
|
|
2427
|
+
rbs_attr_ivar_name_t ivar_name = { .tag = RBS_ATTR_IVAR_NAME_TAG_UNSPECIFIED };
|
|
2428
|
+
rbs_location_range ivar_range = RBS_LOCATION_NULL_RANGE;
|
|
2429
|
+
rbs_location_range ivar_name_range = RBS_LOCATION_NULL_RANGE;
|
|
2424
2430
|
if (parser->next_token.type == pLPAREN) {
|
|
2425
2431
|
ADVANCE_ASSERT(parser, pLPAREN);
|
|
2426
|
-
ivar_range.
|
|
2432
|
+
ivar_range.start_char = parser->current_token.range.start.char_pos;
|
|
2433
|
+
ivar_range.start_byte = parser->current_token.range.start.byte_pos;
|
|
2434
|
+
|
|
2435
|
+
ivar_name.tag = RBS_ATTR_IVAR_NAME_TAG_EMPTY;
|
|
2427
2436
|
|
|
2428
2437
|
if (parser_advance_if(parser, tAIDENT) || parser_advance_if(parser, kATRBS)) {
|
|
2429
|
-
|
|
2430
|
-
ivar_name =
|
|
2431
|
-
ivar_name_range = parser
|
|
2432
|
-
} else {
|
|
2433
|
-
rbs_range_t false_range = {
|
|
2434
|
-
.start = parser->current_token.range.start,
|
|
2435
|
-
.end = parser->current_token.range.end
|
|
2436
|
-
};
|
|
2437
|
-
ivar_name = (rbs_node_t *) rbs_ast_bool_new(ALLOCATOR(), rbs_location_new(ALLOCATOR(), false_range), false);
|
|
2438
|
-
ivar_name_range = NULL_RANGE;
|
|
2438
|
+
ivar_name.tag = RBS_ATTR_IVAR_NAME_TAG_NAME;
|
|
2439
|
+
ivar_name.name = INTERN_TOKEN(parser, parser->current_token);
|
|
2440
|
+
ivar_name_range = rbs_location_range_current_token(parser);
|
|
2439
2441
|
}
|
|
2440
2442
|
|
|
2441
2443
|
ADVANCE_ASSERT(parser, pRPAREN);
|
|
2442
|
-
ivar_range.
|
|
2443
|
-
|
|
2444
|
-
ivar_range = NULL_RANGE;
|
|
2445
|
-
ivar_name = NULL;
|
|
2446
|
-
ivar_name_range = NULL_RANGE;
|
|
2444
|
+
ivar_range.end_char = parser->current_token.range.end.char_pos;
|
|
2445
|
+
ivar_range.end_byte = parser->current_token.range.end.byte_pos;
|
|
2447
2446
|
}
|
|
2448
2447
|
|
|
2449
2448
|
ADVANCE_ASSERT(parser, pCOLON);
|
|
@@ -2452,32 +2451,53 @@ static bool parse_attribute_member(rbs_parser_t *parser, rbs_position_t comment_
|
|
|
2452
2451
|
rbs_parser_push_typevar_table(parser, is_kind == SINGLETON_KIND);
|
|
2453
2452
|
|
|
2454
2453
|
rbs_node_t *type;
|
|
2455
|
-
CHECK_PARSE(rbs_parse_type(parser, &type, false, true));
|
|
2454
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, false, true, true));
|
|
2456
2455
|
|
|
2457
2456
|
CHECK_PARSE(parser_pop_typevar_table(parser));
|
|
2458
2457
|
|
|
2459
2458
|
member_range.end = parser->current_token.range.end;
|
|
2460
2459
|
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
rbs_loc_add_optional_child(loc, INTERN("ivar"), ivar_range);
|
|
2468
|
-
rbs_loc_add_optional_child(loc, INTERN("ivar_name"), ivar_name_range);
|
|
2469
|
-
rbs_loc_add_optional_child(loc, INTERN("visibility"), visibility_range);
|
|
2460
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(member_range);
|
|
2461
|
+
rbs_location_range keyword_rg = RBS_RANGE_LEX2AST(keyword_range);
|
|
2462
|
+
rbs_location_range name_rg = RBS_RANGE_LEX2AST(name_range);
|
|
2463
|
+
rbs_location_range colon_rg = RBS_RANGE_LEX2AST(colon_range);
|
|
2464
|
+
rbs_location_range kind_rg = RBS_RANGE_LEX2AST(kind_range);
|
|
2465
|
+
rbs_location_range visibility_rg = RBS_RANGE_LEX2AST(visibility_range);
|
|
2470
2466
|
|
|
2471
2467
|
switch (attr_type) {
|
|
2472
|
-
case kATTRREADER:
|
|
2473
|
-
*
|
|
2468
|
+
case kATTRREADER: {
|
|
2469
|
+
rbs_ast_members_attr_reader_t *attr_reader = rbs_ast_members_attr_reader_new(ALLOCATOR(), loc, attr_name, type, ivar_name, kind, annotations, comment, visibility, keyword_rg, name_rg, colon_rg);
|
|
2470
|
+
attr_reader->kind_range = kind_rg;
|
|
2471
|
+
attr_reader->ivar_range = ivar_range;
|
|
2472
|
+
attr_reader->ivar_name_range = ivar_name_range;
|
|
2473
|
+
attr_reader->visibility_range = visibility_rg;
|
|
2474
|
+
|
|
2475
|
+
*attribute_member = (rbs_node_t *) attr_reader;
|
|
2476
|
+
|
|
2474
2477
|
return true;
|
|
2475
|
-
|
|
2476
|
-
|
|
2478
|
+
}
|
|
2479
|
+
case kATTRWRITER: {
|
|
2480
|
+
rbs_ast_members_attr_writer_t *attr_writer = rbs_ast_members_attr_writer_new(ALLOCATOR(), loc, attr_name, type, ivar_name, kind, annotations, comment, visibility, keyword_rg, name_rg, colon_rg);
|
|
2481
|
+
attr_writer->kind_range = kind_rg;
|
|
2482
|
+
attr_writer->ivar_range = ivar_range;
|
|
2483
|
+
attr_writer->ivar_name_range = ivar_name_range;
|
|
2484
|
+
attr_writer->visibility_range = visibility_rg;
|
|
2485
|
+
|
|
2486
|
+
*attribute_member = (rbs_node_t *) attr_writer;
|
|
2487
|
+
|
|
2477
2488
|
return true;
|
|
2478
|
-
|
|
2479
|
-
|
|
2489
|
+
}
|
|
2490
|
+
case kATTRACCESSOR: {
|
|
2491
|
+
rbs_ast_members_attr_accessor_t *attr_accessor = rbs_ast_members_attr_accessor_new(ALLOCATOR(), loc, attr_name, type, ivar_name, kind, annotations, comment, visibility, keyword_rg, name_rg, colon_rg);
|
|
2492
|
+
attr_accessor->kind_range = kind_rg;
|
|
2493
|
+
attr_accessor->ivar_range = ivar_range;
|
|
2494
|
+
attr_accessor->ivar_name_range = ivar_name_range;
|
|
2495
|
+
attr_accessor->visibility_range = visibility_rg;
|
|
2496
|
+
|
|
2497
|
+
*attribute_member = (rbs_node_t *) attr_accessor;
|
|
2498
|
+
|
|
2480
2499
|
return true;
|
|
2500
|
+
}
|
|
2481
2501
|
default:
|
|
2482
2502
|
rbs_parser_set_error(parser, parser->current_token, false, "Unexpected error");
|
|
2483
2503
|
return false;
|
|
@@ -2568,16 +2588,12 @@ static bool parse_interface_decl(rbs_parser_t *parser, rbs_position_t comment_po
|
|
|
2568
2588
|
|
|
2569
2589
|
CHECK_PARSE(parser_pop_typevar_table(parser));
|
|
2570
2590
|
|
|
2571
|
-
|
|
2572
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 4);
|
|
2573
|
-
rbs_loc_add_required_child(loc, INTERN("keyword"), keyword_range);
|
|
2574
|
-
rbs_loc_add_required_child(loc, INTERN("name"), name_range);
|
|
2575
|
-
rbs_loc_add_required_child(loc, INTERN("end"), end_range);
|
|
2576
|
-
rbs_loc_add_optional_child(loc, INTERN("type_params"), type_params_range);
|
|
2577
|
-
|
|
2591
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(member_range);
|
|
2578
2592
|
rbs_ast_comment_t *comment = rbs_parser_get_comment(parser, comment_pos.line);
|
|
2579
2593
|
|
|
2580
|
-
*interface_decl = rbs_ast_declarations_interface_new(ALLOCATOR(), loc, name, type_params, members, annotations, comment);
|
|
2594
|
+
*interface_decl = rbs_ast_declarations_interface_new(ALLOCATOR(), loc, name, type_params, members, annotations, comment, RBS_RANGE_LEX2AST(keyword_range), RBS_RANGE_LEX2AST(name_range), RBS_RANGE_LEX2AST(end_range));
|
|
2595
|
+
(*interface_decl)->type_params_range = RBS_RANGE_LEX2AST(type_params_range);
|
|
2596
|
+
|
|
2581
2597
|
return true;
|
|
2582
2598
|
}
|
|
2583
2599
|
|
|
@@ -2605,17 +2621,15 @@ static bool parse_module_self_types(rbs_parser_t *parser, rbs_node_list_t *array
|
|
|
2605
2621
|
if (parser->next_token.type == pLBRACKET) {
|
|
2606
2622
|
rbs_parser_advance(parser);
|
|
2607
2623
|
args_range.start = parser->current_token.range.start;
|
|
2608
|
-
CHECK_PARSE(parse_type_list(parser, pRBRACKET, args, true, false));
|
|
2624
|
+
CHECK_PARSE(parse_type_list(parser, pRBRACKET, args, true, false, false));
|
|
2609
2625
|
rbs_parser_advance(parser);
|
|
2610
2626
|
self_range.end = args_range.end = parser->current_token.range.end;
|
|
2611
2627
|
}
|
|
2612
2628
|
|
|
2613
|
-
|
|
2614
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 2);
|
|
2615
|
-
rbs_loc_add_required_child(loc, INTERN("name"), name_range);
|
|
2616
|
-
rbs_loc_add_optional_child(loc, INTERN("args"), args_range);
|
|
2629
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(self_range);
|
|
2617
2630
|
|
|
2618
|
-
rbs_ast_declarations_module_self_t *self_type = rbs_ast_declarations_module_self_new(ALLOCATOR(), loc, module_name, args);
|
|
2631
|
+
rbs_ast_declarations_module_self_t *self_type = rbs_ast_declarations_module_self_new(ALLOCATOR(), loc, module_name, args, RBS_RANGE_LEX2AST(name_range));
|
|
2632
|
+
self_type->args_range = RBS_RANGE_LEX2AST(args_range);
|
|
2619
2633
|
rbs_node_list_append(array, (rbs_node_t *) self_type);
|
|
2620
2634
|
|
|
2621
2635
|
if (parser->next_token.type == pCOMMA) {
|
|
@@ -2761,18 +2775,14 @@ static bool parse_module_decl0(rbs_parser_t *parser, rbs_range_t keyword_range,
|
|
|
2761
2775
|
rbs_range_t end_range = parser->current_token.range;
|
|
2762
2776
|
decl_range.end = parser->current_token.range.end;
|
|
2763
2777
|
|
|
2764
|
-
rbs_location_t *loc = rbs_location_new(ALLOCATOR(), decl_range);
|
|
2765
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 6);
|
|
2766
|
-
rbs_loc_add_required_child(loc, INTERN("keyword"), keyword_range);
|
|
2767
|
-
rbs_loc_add_required_child(loc, INTERN("name"), name_range);
|
|
2768
|
-
rbs_loc_add_required_child(loc, INTERN("end"), end_range);
|
|
2769
|
-
rbs_loc_add_optional_child(loc, INTERN("type_params"), type_params_range);
|
|
2770
|
-
rbs_loc_add_optional_child(loc, INTERN("colon"), colon_range);
|
|
2771
|
-
rbs_loc_add_optional_child(loc, INTERN("self_types"), self_types_range);
|
|
2772
|
-
|
|
2773
2778
|
CHECK_PARSE(parser_pop_typevar_table(parser));
|
|
2774
2779
|
|
|
2775
|
-
|
|
2780
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(decl_range);
|
|
2781
|
+
|
|
2782
|
+
*module_decl = rbs_ast_declarations_module_new(ALLOCATOR(), loc, module_name, type_params, self_types, members, annotations, comment, RBS_RANGE_LEX2AST(keyword_range), RBS_RANGE_LEX2AST(name_range), RBS_RANGE_LEX2AST(end_range));
|
|
2783
|
+
(*module_decl)->type_params_range = RBS_RANGE_LEX2AST(type_params_range);
|
|
2784
|
+
(*module_decl)->colon_range = RBS_RANGE_LEX2AST(colon_range);
|
|
2785
|
+
(*module_decl)->self_types_range = RBS_RANGE_LEX2AST(self_types_range);
|
|
2776
2786
|
return true;
|
|
2777
2787
|
}
|
|
2778
2788
|
|
|
@@ -2808,14 +2818,9 @@ static bool parse_module_decl(rbs_parser_t *parser, rbs_position_t comment_pos,
|
|
|
2808
2818
|
.end = old_name_range.end
|
|
2809
2819
|
};
|
|
2810
2820
|
|
|
2811
|
-
|
|
2812
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 4);
|
|
2813
|
-
rbs_loc_add_required_child(loc, INTERN("keyword"), keyword_range);
|
|
2814
|
-
rbs_loc_add_required_child(loc, INTERN("new_name"), module_name_range);
|
|
2815
|
-
rbs_loc_add_required_child(loc, INTERN("eq"), eq_range);
|
|
2816
|
-
rbs_loc_add_optional_child(loc, INTERN("old_name"), old_name_range);
|
|
2821
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(decl_range);
|
|
2817
2822
|
|
|
2818
|
-
*module_decl = (rbs_node_t *) rbs_ast_declarations_module_alias_new(ALLOCATOR(), loc, module_name, old_name, comment, annotations);
|
|
2823
|
+
*module_decl = (rbs_node_t *) rbs_ast_declarations_module_alias_new(ALLOCATOR(), loc, module_name, old_name, comment, annotations, RBS_RANGE_LEX2AST(keyword_range), RBS_RANGE_LEX2AST(module_name_range), RBS_RANGE_LEX2AST(eq_range), RBS_RANGE_LEX2AST(old_name_range));
|
|
2819
2824
|
} else {
|
|
2820
2825
|
rbs_ast_declarations_module_t *module_decl0 = NULL;
|
|
2821
2826
|
CHECK_PARSE(parse_module_decl0(parser, keyword_range, module_name, module_name_range, comment, annotations, &module_decl0));
|
|
@@ -2840,16 +2845,13 @@ static bool parse_class_decl_super(rbs_parser_t *parser, rbs_range_t *lt_range,
|
|
|
2840
2845
|
rbs_node_list_t *args = rbs_node_list_new(ALLOCATOR());
|
|
2841
2846
|
rbs_type_name_t *name = NULL;
|
|
2842
2847
|
rbs_range_t name_range, args_range;
|
|
2843
|
-
CHECK_PARSE(class_instance_name(parser, CLASS_NAME, args, &name_range, &args_range, &name));
|
|
2848
|
+
CHECK_PARSE(class_instance_name(parser, CLASS_NAME, args, &name_range, &args_range, &name, false));
|
|
2844
2849
|
|
|
2845
2850
|
super_range.end = parser->current_token.range.end;
|
|
2846
2851
|
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
rbs_loc_add_optional_child(loc, INTERN("args"), args_range);
|
|
2851
|
-
|
|
2852
|
-
*super = rbs_ast_declarations_class_super_new(ALLOCATOR(), loc, name, args);
|
|
2852
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(super_range);
|
|
2853
|
+
*super = rbs_ast_declarations_class_super_new(ALLOCATOR(), loc, name, args, RBS_RANGE_LEX2AST(name_range));
|
|
2854
|
+
(*super)->args_range = RBS_RANGE_LEX2AST(args_range);
|
|
2853
2855
|
} else {
|
|
2854
2856
|
*lt_range = NULL_RANGE;
|
|
2855
2857
|
}
|
|
@@ -2886,15 +2888,12 @@ static bool parse_class_decl0(rbs_parser_t *parser, rbs_range_t keyword_range, r
|
|
|
2886
2888
|
|
|
2887
2889
|
CHECK_PARSE(parser_pop_typevar_table(parser));
|
|
2888
2890
|
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
rbs_loc_add_optional_child(loc, INTERN("type_params"), type_params_range);
|
|
2895
|
-
rbs_loc_add_optional_child(loc, INTERN("lt"), lt_range);
|
|
2891
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(decl_range);
|
|
2892
|
+
|
|
2893
|
+
*class_decl = rbs_ast_declarations_class_new(ALLOCATOR(), loc, name, type_params, super, members, annotations, comment, RBS_RANGE_LEX2AST(keyword_range), RBS_RANGE_LEX2AST(name_range), RBS_RANGE_LEX2AST(end_range));
|
|
2894
|
+
(*class_decl)->type_params_range = RBS_RANGE_LEX2AST(type_params_range);
|
|
2895
|
+
(*class_decl)->lt_range = RBS_RANGE_LEX2AST(lt_range);
|
|
2896
2896
|
|
|
2897
|
-
*class_decl = rbs_ast_declarations_class_new(ALLOCATOR(), loc, name, type_params, super, members, annotations, comment);
|
|
2898
2897
|
return true;
|
|
2899
2898
|
}
|
|
2900
2899
|
|
|
@@ -2928,14 +2927,9 @@ static bool parse_class_decl(rbs_parser_t *parser, rbs_position_t comment_pos, r
|
|
|
2928
2927
|
.end = old_name_range.end,
|
|
2929
2928
|
};
|
|
2930
2929
|
|
|
2931
|
-
|
|
2932
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 4);
|
|
2933
|
-
rbs_loc_add_required_child(loc, INTERN("keyword"), keyword_range);
|
|
2934
|
-
rbs_loc_add_required_child(loc, INTERN("new_name"), class_name_range);
|
|
2935
|
-
rbs_loc_add_required_child(loc, INTERN("eq"), eq_range);
|
|
2936
|
-
rbs_loc_add_optional_child(loc, INTERN("old_name"), old_name_range);
|
|
2930
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(decl_range);
|
|
2937
2931
|
|
|
2938
|
-
*class_decl = (rbs_node_t *) rbs_ast_declarations_class_alias_new(ALLOCATOR(), loc, class_name, old_name, comment, annotations);
|
|
2932
|
+
*class_decl = (rbs_node_t *) rbs_ast_declarations_class_alias_new(ALLOCATOR(), loc, class_name, old_name, comment, annotations, RBS_RANGE_LEX2AST(keyword_range), RBS_RANGE_LEX2AST(class_name_range), RBS_RANGE_LEX2AST(eq_range), RBS_RANGE_LEX2AST(old_name_range));
|
|
2939
2933
|
} else {
|
|
2940
2934
|
rbs_ast_declarations_class_t *class_decl0 = NULL;
|
|
2941
2935
|
CHECK_PARSE(parse_class_decl0(parser, keyword_range, class_name, class_name_range, comment, annotations, &class_decl0));
|
|
@@ -3078,8 +3072,8 @@ static bool parse_namespace(rbs_parser_t *parser, rbs_range_t *rg, rbs_namespace
|
|
|
3078
3072
|
|
|
3079
3073
|
while (true) {
|
|
3080
3074
|
if (parser->next_token.type == tUIDENT && parser->next_token2.type == pCOLON2) {
|
|
3081
|
-
|
|
3082
|
-
rbs_ast_symbol_t *symbol = rbs_ast_symbol_new(ALLOCATOR(),
|
|
3075
|
+
rbs_location_range symbol_loc = RBS_RANGE_LEX2AST(parser->next_token.range);
|
|
3076
|
+
rbs_ast_symbol_t *symbol = rbs_ast_symbol_new(ALLOCATOR(), symbol_loc, &parser->constant_pool, INTERN_TOKEN(parser, parser->next_token));
|
|
3083
3077
|
rbs_node_list_append(path, (rbs_node_t *) symbol);
|
|
3084
3078
|
if (rbs_null_position_p(rg->start)) {
|
|
3085
3079
|
rg->start = parser->next_token.range.start;
|
|
@@ -3092,7 +3086,7 @@ static bool parse_namespace(rbs_parser_t *parser, rbs_range_t *rg, rbs_namespace
|
|
|
3092
3086
|
}
|
|
3093
3087
|
}
|
|
3094
3088
|
|
|
3095
|
-
*out_ns = rbs_namespace_new(ALLOCATOR(),
|
|
3089
|
+
*out_ns = rbs_namespace_new(ALLOCATOR(), RBS_RANGE_LEX2AST(*rg), path, is_absolute);
|
|
3096
3090
|
return true;
|
|
3097
3091
|
}
|
|
3098
3092
|
|
|
@@ -3120,9 +3114,9 @@ static bool parse_use_clauses(rbs_parser_t *parser, rbs_node_list_t *clauses) {
|
|
|
3120
3114
|
|
|
3121
3115
|
rbs_range_t type_name_range = rbs_null_range_p(namespace_range) ? parser->current_token.range : (rbs_range_t) { .start = namespace_range.start, .end = parser->current_token.range.end };
|
|
3122
3116
|
|
|
3123
|
-
|
|
3124
|
-
rbs_ast_symbol_t *symbol = rbs_ast_symbol_new(ALLOCATOR(),
|
|
3125
|
-
rbs_type_name_t *type_name = rbs_type_name_new(ALLOCATOR(),
|
|
3117
|
+
rbs_location_range symbol_loc = rbs_location_range_current_token(parser);
|
|
3118
|
+
rbs_ast_symbol_t *symbol = rbs_ast_symbol_new(ALLOCATOR(), symbol_loc, &parser->constant_pool, INTERN_TOKEN(parser, parser->current_token));
|
|
3119
|
+
rbs_type_name_t *type_name = rbs_type_name_new(ALLOCATOR(), RBS_RANGE_LEX2AST(type_name_range), ns, symbol);
|
|
3126
3120
|
|
|
3127
3121
|
rbs_range_t keyword_range = NULL_RANGE;
|
|
3128
3122
|
rbs_range_t new_name_range = NULL_RANGE;
|
|
@@ -3136,19 +3130,18 @@ static bool parse_use_clauses(rbs_parser_t *parser, rbs_node_list_t *clauses) {
|
|
|
3136
3130
|
if (ident_type == tLIDENT) ADVANCE_ASSERT(parser, tLIDENT);
|
|
3137
3131
|
if (ident_type == tULIDENT) ADVANCE_ASSERT(parser, tULIDENT);
|
|
3138
3132
|
|
|
3139
|
-
|
|
3140
|
-
new_name = rbs_ast_symbol_new(ALLOCATOR(),
|
|
3133
|
+
rbs_location_range symbol_loc = RBS_RANGE_LEX2AST(new_name_range);
|
|
3134
|
+
new_name = rbs_ast_symbol_new(ALLOCATOR(), symbol_loc, &parser->constant_pool, INTERN_TOKEN(parser, parser->current_token));
|
|
3141
3135
|
new_name_range = parser->current_token.range;
|
|
3142
3136
|
clause_range.end = new_name_range.end;
|
|
3143
3137
|
}
|
|
3144
3138
|
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3139
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(clause_range);
|
|
3140
|
+
|
|
3141
|
+
rbs_ast_directives_use_single_clause_t *clause = rbs_ast_directives_use_single_clause_new(ALLOCATOR(), loc, type_name, new_name, RBS_RANGE_LEX2AST(type_name_range));
|
|
3142
|
+
clause->keyword_range = RBS_RANGE_LEX2AST(keyword_range);
|
|
3143
|
+
clause->new_name_range = RBS_RANGE_LEX2AST(new_name_range);
|
|
3150
3144
|
|
|
3151
|
-
rbs_ast_directives_use_single_clause_t *clause = rbs_ast_directives_use_single_clause_new(ALLOCATOR(), loc, type_name, new_name);
|
|
3152
3145
|
rbs_node_list_append(clauses, (rbs_node_t *) clause);
|
|
3153
3146
|
|
|
3154
3147
|
break;
|
|
@@ -3160,12 +3153,9 @@ static bool parse_use_clauses(rbs_parser_t *parser, rbs_node_list_t *clauses) {
|
|
|
3160
3153
|
rbs_range_t star_range = parser->current_token.range;
|
|
3161
3154
|
clause_range.end = star_range.end;
|
|
3162
3155
|
|
|
3163
|
-
|
|
3164
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 2);
|
|
3165
|
-
rbs_loc_add_required_child(loc, INTERN("namespace"), namespace_range);
|
|
3166
|
-
rbs_loc_add_required_child(loc, INTERN("star"), star_range);
|
|
3156
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(clause_range);
|
|
3167
3157
|
|
|
3168
|
-
rbs_ast_directives_use_wildcard_clause_t *clause = rbs_ast_directives_use_wildcard_clause_new(ALLOCATOR(), loc, ns);
|
|
3158
|
+
rbs_ast_directives_use_wildcard_clause_t *clause = rbs_ast_directives_use_wildcard_clause_new(ALLOCATOR(), loc, ns, RBS_RANGE_LEX2AST(namespace_range), RBS_RANGE_LEX2AST(star_range));
|
|
3169
3159
|
rbs_node_list_append(clauses, (rbs_node_t *) clause);
|
|
3170
3160
|
|
|
3171
3161
|
break;
|
|
@@ -3201,11 +3191,9 @@ static bool parse_use_directive(rbs_parser_t *parser, rbs_ast_directives_use_t *
|
|
|
3201
3191
|
rbs_range_t directive_range = keyword_range;
|
|
3202
3192
|
directive_range.end = parser->current_token.range.end;
|
|
3203
3193
|
|
|
3204
|
-
|
|
3205
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 1);
|
|
3206
|
-
rbs_loc_add_required_child(loc, INTERN("keyword"), keyword_range);
|
|
3194
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(directive_range);
|
|
3207
3195
|
|
|
3208
|
-
*use_directive = rbs_ast_directives_use_new(ALLOCATOR(), loc, clauses);
|
|
3196
|
+
*use_directive = rbs_ast_directives_use_new(ALLOCATOR(), loc, clauses, RBS_RANGE_LEX2AST(keyword_range));
|
|
3209
3197
|
}
|
|
3210
3198
|
|
|
3211
3199
|
return true;
|
|
@@ -3243,7 +3231,12 @@ static rbs_ast_comment_t *parse_comment_lines(rbs_parser_t *parser, rbs_comment_
|
|
|
3243
3231
|
|
|
3244
3232
|
return rbs_ast_comment_new(
|
|
3245
3233
|
ALLOCATOR(),
|
|
3246
|
-
|
|
3234
|
+
(rbs_location_range) {
|
|
3235
|
+
.start_char = com->start.char_pos,
|
|
3236
|
+
.start_byte = com->start.byte_pos,
|
|
3237
|
+
.end_char = com->end.char_pos,
|
|
3238
|
+
.end_byte = com->end.byte_pos,
|
|
3239
|
+
},
|
|
3247
3240
|
rbs_buffer_to_string(&rbs_buffer)
|
|
3248
3241
|
);
|
|
3249
3242
|
}
|
|
@@ -3345,7 +3338,7 @@ bool rbs_parse_signature(rbs_parser_t *parser, rbs_signature_t **signature) {
|
|
|
3345
3338
|
}
|
|
3346
3339
|
|
|
3347
3340
|
signature_range.end = parser->current_token.range.end;
|
|
3348
|
-
*signature = rbs_signature_new(ALLOCATOR(),
|
|
3341
|
+
*signature = rbs_signature_new(ALLOCATOR(), RBS_RANGE_LEX2AST(signature_range), dirs, decls);
|
|
3349
3342
|
return true;
|
|
3350
3343
|
}
|
|
3351
3344
|
|
|
@@ -3523,7 +3516,9 @@ rbs_lexer_t *rbs_lexer_new(rbs_allocator_t *allocator, rbs_string_t string, cons
|
|
|
3523
3516
|
}
|
|
3524
3517
|
|
|
3525
3518
|
if (start_pos > 0) {
|
|
3526
|
-
|
|
3519
|
+
while (lexer->current.byte_pos < start_pos) {
|
|
3520
|
+
rbs_skip(lexer);
|
|
3521
|
+
}
|
|
3527
3522
|
}
|
|
3528
3523
|
|
|
3529
3524
|
lexer->start = lexer->current;
|
|
@@ -3619,16 +3614,17 @@ static bool parse_method_overload(rbs_parser_t *parser, rbs_node_list_t *annotat
|
|
|
3619
3614
|
return false;
|
|
3620
3615
|
}
|
|
3621
3616
|
|
|
3622
|
-
return rbs_parse_method_type(parser, method_type, false);
|
|
3617
|
+
return rbs_parse_method_type(parser, method_type, false, true);
|
|
3623
3618
|
}
|
|
3624
3619
|
|
|
3625
3620
|
/*
|
|
3626
|
-
inline_method_overloads ::= {} <overload>
|
|
3621
|
+
inline_method_overloads ::= {} <overload> -- returns true
|
|
3627
3622
|
| {} overload `|` ... `|` overload -- returns true
|
|
3623
|
+
| {} overload `|` ... `|` `...` -- returns true (dot3_location is set)
|
|
3628
3624
|
| {<>} -- returns false
|
|
3629
3625
|
*/
|
|
3630
3626
|
NODISCARD
|
|
3631
|
-
static bool parse_inline_method_overloads(rbs_parser_t *parser, rbs_node_list_t *overloads,
|
|
3627
|
+
static bool parse_inline_method_overloads(rbs_parser_t *parser, rbs_node_list_t *overloads, rbs_location_range_list_t *bar_locations, rbs_location_range *dot3_location) {
|
|
3632
3628
|
while (true) {
|
|
3633
3629
|
rbs_node_list_t *annotations = rbs_node_list_new(ALLOCATOR());
|
|
3634
3630
|
rbs_method_type_t *method_type = NULL;
|
|
@@ -3637,7 +3633,7 @@ static bool parse_inline_method_overloads(rbs_parser_t *parser, rbs_node_list_t
|
|
|
3637
3633
|
return false;
|
|
3638
3634
|
}
|
|
3639
3635
|
|
|
3640
|
-
|
|
3636
|
+
rbs_location_range location = rbs_location_range_current_token(parser);
|
|
3641
3637
|
rbs_ast_members_method_definition_overload_t *overload = rbs_ast_members_method_definition_overload_new(
|
|
3642
3638
|
ALLOCATOR(),
|
|
3643
3639
|
location,
|
|
@@ -3647,11 +3643,17 @@ static bool parse_inline_method_overloads(rbs_parser_t *parser, rbs_node_list_t
|
|
|
3647
3643
|
rbs_node_list_append(overloads, (rbs_node_t *) overload);
|
|
3648
3644
|
|
|
3649
3645
|
if (parser->next_token.type == pBAR) {
|
|
3650
|
-
|
|
3646
|
+
rbs_location_range bar_range = RBS_RANGE_LEX2AST(parser->next_token.range);
|
|
3651
3647
|
|
|
3652
3648
|
rbs_parser_advance(parser);
|
|
3653
3649
|
|
|
3654
|
-
|
|
3650
|
+
rbs_location_range_list_append(bar_locations, bar_range);
|
|
3651
|
+
|
|
3652
|
+
if (parser->next_token.type == pDOT3) {
|
|
3653
|
+
*dot3_location = RBS_RANGE_LEX2AST(parser->next_token.range);
|
|
3654
|
+
rbs_parser_advance(parser);
|
|
3655
|
+
return true;
|
|
3656
|
+
}
|
|
3655
3657
|
|
|
3656
3658
|
continue;
|
|
3657
3659
|
}
|
|
@@ -3661,16 +3663,55 @@ static bool parse_inline_method_overloads(rbs_parser_t *parser, rbs_node_list_t
|
|
|
3661
3663
|
}
|
|
3662
3664
|
|
|
3663
3665
|
NODISCARD
|
|
3664
|
-
static bool parse_inline_comment(rbs_parser_t *parser,
|
|
3666
|
+
static bool parse_inline_comment(rbs_parser_t *parser, rbs_location_range *comment_range) {
|
|
3665
3667
|
if (parser->next_token.type != tINLINECOMMENT) {
|
|
3666
|
-
*
|
|
3668
|
+
*comment_range = RBS_LOCATION_NULL_RANGE;
|
|
3667
3669
|
return true;
|
|
3668
3670
|
}
|
|
3669
3671
|
|
|
3670
|
-
|
|
3672
|
+
*comment_range = RBS_RANGE_LEX2AST(parser->next_token.range);
|
|
3673
|
+
rbs_parser_advance(parser);
|
|
3674
|
+
|
|
3675
|
+
return true;
|
|
3676
|
+
}
|
|
3677
|
+
|
|
3678
|
+
NODISCARD
|
|
3679
|
+
static bool parse_inline_param_type_annotation(rbs_parser_t *parser, rbs_ast_ruby_annotations_t **annotation, rbs_range_t rbs_range) {
|
|
3671
3680
|
rbs_parser_advance(parser);
|
|
3672
3681
|
|
|
3673
|
-
|
|
3682
|
+
rbs_location_range name_loc = rbs_location_range_current_token(parser);
|
|
3683
|
+
|
|
3684
|
+
ADVANCE_ASSERT(parser, pCOLON);
|
|
3685
|
+
|
|
3686
|
+
rbs_location_range colon_loc = rbs_location_range_current_token(parser);
|
|
3687
|
+
|
|
3688
|
+
rbs_node_t *param_type = NULL;
|
|
3689
|
+
if (!rbs_parse_type(parser, ¶m_type, false, true, true)) {
|
|
3690
|
+
return false;
|
|
3691
|
+
}
|
|
3692
|
+
|
|
3693
|
+
rbs_location_range comment_loc = RBS_LOCATION_NULL_RANGE;
|
|
3694
|
+
if (!parse_inline_comment(parser, &comment_loc)) {
|
|
3695
|
+
return false;
|
|
3696
|
+
}
|
|
3697
|
+
|
|
3698
|
+
rbs_location_range full_loc = {
|
|
3699
|
+
.start_char = rbs_range.start.char_pos,
|
|
3700
|
+
.start_byte = rbs_range.start.byte_pos,
|
|
3701
|
+
.end_char = parser->current_token.range.end.char_pos,
|
|
3702
|
+
.end_byte = parser->current_token.range.end.byte_pos,
|
|
3703
|
+
};
|
|
3704
|
+
|
|
3705
|
+
*annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_param_type_annotation_new(
|
|
3706
|
+
ALLOCATOR(),
|
|
3707
|
+
full_loc,
|
|
3708
|
+
RBS_RANGE_LEX2AST(rbs_range),
|
|
3709
|
+
name_loc,
|
|
3710
|
+
colon_loc,
|
|
3711
|
+
param_type,
|
|
3712
|
+
comment_loc
|
|
3713
|
+
);
|
|
3714
|
+
|
|
3674
3715
|
return true;
|
|
3675
3716
|
}
|
|
3676
3717
|
|
|
@@ -3693,13 +3734,12 @@ static bool parse_inline_leading_annotation(rbs_parser_t *parser, rbs_ast_ruby_a
|
|
|
3693
3734
|
.end = parser->current_token.range.end
|
|
3694
3735
|
};
|
|
3695
3736
|
|
|
3696
|
-
|
|
3697
|
-
rbs_location_t *colon_loc = rbs_location_new(ALLOCATOR(), colon_range);
|
|
3737
|
+
rbs_location_range full_loc = RBS_RANGE_LEX2AST(full_range);
|
|
3698
3738
|
|
|
3699
3739
|
*annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_colon_method_type_annotation_new(
|
|
3700
3740
|
ALLOCATOR(),
|
|
3701
3741
|
full_loc,
|
|
3702
|
-
|
|
3742
|
+
RBS_RANGE_LEX2AST(colon_range),
|
|
3703
3743
|
annotations,
|
|
3704
3744
|
(rbs_node_t *) method_type
|
|
3705
3745
|
);
|
|
@@ -3710,42 +3750,39 @@ static bool parse_inline_leading_annotation(rbs_parser_t *parser, rbs_ast_ruby_a
|
|
|
3710
3750
|
rbs_parser_advance(parser);
|
|
3711
3751
|
|
|
3712
3752
|
switch (parser->next_token.type) {
|
|
3713
|
-
case
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
case tANNOTATION: {
|
|
3717
|
-
rbs_node_list_t *overloads = rbs_node_list_new(ALLOCATOR());
|
|
3718
|
-
rbs_location_list_t *bar_locations = rbs_location_list_new(ALLOCATOR());
|
|
3753
|
+
case pDOT3: {
|
|
3754
|
+
rbs_location_range dot3_range = RBS_RANGE_LEX2AST(parser->next_token.range);
|
|
3755
|
+
rbs_parser_advance(parser);
|
|
3719
3756
|
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
}
|
|
3757
|
+
rbs_node_list_t *overloads = rbs_node_list_new(ALLOCATOR());
|
|
3758
|
+
rbs_location_range_list_t *bar_locations = rbs_location_range_list_new(ALLOCATOR());
|
|
3723
3759
|
|
|
3724
3760
|
rbs_range_t full_range = {
|
|
3725
3761
|
.start = rbs_range.start,
|
|
3726
3762
|
.end = parser->current_token.range.end
|
|
3727
3763
|
};
|
|
3728
3764
|
|
|
3729
|
-
|
|
3730
|
-
rbs_location_t *rbs_loc = rbs_location_new(ALLOCATOR(), rbs_range);
|
|
3765
|
+
rbs_location_range full_loc = RBS_RANGE_LEX2AST(full_range);
|
|
3731
3766
|
|
|
3732
3767
|
*annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_method_types_annotation_new(
|
|
3733
3768
|
ALLOCATOR(),
|
|
3734
3769
|
full_loc,
|
|
3735
|
-
|
|
3770
|
+
RBS_RANGE_LEX2AST(rbs_range),
|
|
3736
3771
|
overloads,
|
|
3737
|
-
bar_locations
|
|
3772
|
+
bar_locations,
|
|
3773
|
+
dot3_range
|
|
3738
3774
|
);
|
|
3739
3775
|
return true;
|
|
3740
3776
|
}
|
|
3741
|
-
case
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3777
|
+
case pLPAREN:
|
|
3778
|
+
case pLBRACKET:
|
|
3779
|
+
case pLBRACE:
|
|
3780
|
+
case tANNOTATION: {
|
|
3781
|
+
rbs_node_list_t *overloads = rbs_node_list_new(ALLOCATOR());
|
|
3782
|
+
rbs_location_range_list_t *bar_locations = rbs_location_range_list_new(ALLOCATOR());
|
|
3783
|
+
rbs_location_range dot3_location = RBS_LOCATION_NULL_RANGE;
|
|
3746
3784
|
|
|
3747
|
-
|
|
3748
|
-
if (!parse_inline_comment(parser, &comment_loc)) {
|
|
3785
|
+
if (!parse_inline_method_overloads(parser, overloads, bar_locations, &dot3_location)) {
|
|
3749
3786
|
return false;
|
|
3750
3787
|
}
|
|
3751
3788
|
|
|
@@ -3754,35 +3791,63 @@ static bool parse_inline_leading_annotation(rbs_parser_t *parser, rbs_ast_ruby_a
|
|
|
3754
3791
|
.end = parser->current_token.range.end
|
|
3755
3792
|
};
|
|
3756
3793
|
|
|
3757
|
-
|
|
3758
|
-
rbs_location_t *rbs_loc = rbs_location_new(ALLOCATOR(), rbs_range);
|
|
3794
|
+
rbs_location_range full_loc = RBS_RANGE_LEX2AST(full_range);
|
|
3759
3795
|
|
|
3760
|
-
*annotation = (rbs_ast_ruby_annotations_t *)
|
|
3796
|
+
*annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_method_types_annotation_new(
|
|
3761
3797
|
ALLOCATOR(),
|
|
3762
3798
|
full_loc,
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3799
|
+
RBS_RANGE_LEX2AST(rbs_range),
|
|
3800
|
+
overloads,
|
|
3801
|
+
bar_locations,
|
|
3802
|
+
dot3_location
|
|
3766
3803
|
);
|
|
3767
3804
|
return true;
|
|
3768
3805
|
}
|
|
3806
|
+
case kSKIP: {
|
|
3807
|
+
if (parser->next_token2.type == pCOLON) {
|
|
3808
|
+
return parse_inline_param_type_annotation(parser, annotation, rbs_range);
|
|
3809
|
+
} else {
|
|
3810
|
+
rbs_parser_advance(parser);
|
|
3811
|
+
|
|
3812
|
+
rbs_range_t skip_range = parser->current_token.range;
|
|
3813
|
+
|
|
3814
|
+
rbs_location_range comment_loc = RBS_LOCATION_NULL_RANGE;
|
|
3815
|
+
if (!parse_inline_comment(parser, &comment_loc)) {
|
|
3816
|
+
return false;
|
|
3817
|
+
}
|
|
3818
|
+
|
|
3819
|
+
rbs_range_t full_range = {
|
|
3820
|
+
.start = rbs_range.start,
|
|
3821
|
+
.end = parser->current_token.range.end
|
|
3822
|
+
};
|
|
3823
|
+
|
|
3824
|
+
rbs_location_range full_loc = RBS_RANGE_LEX2AST(full_range);
|
|
3825
|
+
|
|
3826
|
+
*annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_skip_annotation_new(
|
|
3827
|
+
ALLOCATOR(),
|
|
3828
|
+
full_loc,
|
|
3829
|
+
RBS_RANGE_LEX2AST(rbs_range),
|
|
3830
|
+
RBS_RANGE_LEX2AST(skip_range),
|
|
3831
|
+
comment_loc
|
|
3832
|
+
);
|
|
3833
|
+
return true;
|
|
3834
|
+
}
|
|
3835
|
+
}
|
|
3769
3836
|
case kRETURN: {
|
|
3770
3837
|
rbs_parser_advance(parser);
|
|
3771
3838
|
|
|
3772
3839
|
rbs_range_t return_range = parser->current_token.range;
|
|
3773
|
-
rbs_location_t *return_loc = rbs_location_new(ALLOCATOR(), return_range);
|
|
3774
3840
|
|
|
3775
3841
|
ADVANCE_ASSERT(parser, pCOLON);
|
|
3776
3842
|
|
|
3777
3843
|
rbs_range_t colon_range = parser->current_token.range;
|
|
3778
|
-
rbs_location_t *colon_loc = rbs_location_new(ALLOCATOR(), colon_range);
|
|
3779
3844
|
|
|
3780
3845
|
rbs_node_t *return_type = NULL;
|
|
3781
|
-
if (!rbs_parse_type(parser, &return_type, true, true)) {
|
|
3846
|
+
if (!rbs_parse_type(parser, &return_type, true, true, true)) {
|
|
3782
3847
|
return false;
|
|
3783
3848
|
}
|
|
3784
3849
|
|
|
3785
|
-
|
|
3850
|
+
rbs_location_range comment_loc = RBS_LOCATION_NULL_RANGE;
|
|
3786
3851
|
if (!parse_inline_comment(parser, &comment_loc)) {
|
|
3787
3852
|
return false;
|
|
3788
3853
|
}
|
|
@@ -3792,15 +3857,14 @@ static bool parse_inline_leading_annotation(rbs_parser_t *parser, rbs_ast_ruby_a
|
|
|
3792
3857
|
.end = parser->current_token.range.end
|
|
3793
3858
|
};
|
|
3794
3859
|
|
|
3795
|
-
|
|
3796
|
-
rbs_location_t *rbs_loc = rbs_location_new(ALLOCATOR(), rbs_range);
|
|
3860
|
+
rbs_location_range full_loc = RBS_RANGE_LEX2AST(full_range);
|
|
3797
3861
|
|
|
3798
3862
|
*annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_return_type_annotation_new(
|
|
3799
3863
|
ALLOCATOR(),
|
|
3800
3864
|
full_loc,
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3865
|
+
RBS_RANGE_LEX2AST(rbs_range),
|
|
3866
|
+
RBS_RANGE_LEX2AST(return_range),
|
|
3867
|
+
RBS_RANGE_LEX2AST(colon_range),
|
|
3804
3868
|
return_type,
|
|
3805
3869
|
comment_loc
|
|
3806
3870
|
);
|
|
@@ -3811,7 +3875,7 @@ static bool parse_inline_leading_annotation(rbs_parser_t *parser, rbs_ast_ruby_a
|
|
|
3811
3875
|
rbs_parser_advance(parser);
|
|
3812
3876
|
|
|
3813
3877
|
rbs_range_t ivar_name_range = parser->current_token.range;
|
|
3814
|
-
|
|
3878
|
+
rbs_location_range ivar_name_loc = RBS_RANGE_LEX2AST(ivar_name_range);
|
|
3815
3879
|
|
|
3816
3880
|
// Extract the instance variable name as a symbol
|
|
3817
3881
|
rbs_string_t ivar_string = rbs_parser_peek_current_token(parser);
|
|
@@ -3821,14 +3885,13 @@ static bool parse_inline_leading_annotation(rbs_parser_t *parser, rbs_ast_ruby_a
|
|
|
3821
3885
|
ADVANCE_ASSERT(parser, pCOLON);
|
|
3822
3886
|
|
|
3823
3887
|
rbs_range_t colon_range = parser->current_token.range;
|
|
3824
|
-
rbs_location_t *colon_loc = rbs_location_new(ALLOCATOR(), colon_range);
|
|
3825
3888
|
|
|
3826
3889
|
rbs_node_t *type = NULL;
|
|
3827
|
-
if (!rbs_parse_type(parser, &type, false, true)) {
|
|
3890
|
+
if (!rbs_parse_type(parser, &type, false, true, true)) {
|
|
3828
3891
|
return false;
|
|
3829
3892
|
}
|
|
3830
3893
|
|
|
3831
|
-
|
|
3894
|
+
rbs_location_range comment_loc = RBS_LOCATION_NULL_RANGE;
|
|
3832
3895
|
if (!parse_inline_comment(parser, &comment_loc)) {
|
|
3833
3896
|
return false;
|
|
3834
3897
|
}
|
|
@@ -3838,21 +3901,157 @@ static bool parse_inline_leading_annotation(rbs_parser_t *parser, rbs_ast_ruby_a
|
|
|
3838
3901
|
.end = parser->current_token.range.end
|
|
3839
3902
|
};
|
|
3840
3903
|
|
|
3841
|
-
|
|
3842
|
-
rbs_location_t *rbs_loc = rbs_location_new(ALLOCATOR(), rbs_range);
|
|
3904
|
+
rbs_location_range full_loc = RBS_RANGE_LEX2AST(full_range);
|
|
3843
3905
|
|
|
3844
3906
|
*annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_instance_variable_annotation_new(
|
|
3845
3907
|
ALLOCATOR(),
|
|
3846
3908
|
full_loc,
|
|
3847
|
-
|
|
3909
|
+
RBS_RANGE_LEX2AST(rbs_range),
|
|
3848
3910
|
ivar_name,
|
|
3849
|
-
|
|
3850
|
-
|
|
3911
|
+
RBS_RANGE_LEX2AST(ivar_name_range),
|
|
3912
|
+
RBS_RANGE_LEX2AST(colon_range),
|
|
3851
3913
|
type,
|
|
3852
3914
|
comment_loc
|
|
3853
3915
|
);
|
|
3854
3916
|
return true;
|
|
3855
3917
|
}
|
|
3918
|
+
case tLIDENT:
|
|
3919
|
+
PARAM_NAME_CASES {
|
|
3920
|
+
return parse_inline_param_type_annotation(parser, annotation, rbs_range);
|
|
3921
|
+
}
|
|
3922
|
+
case pSTAR: {
|
|
3923
|
+
rbs_parser_advance(parser);
|
|
3924
|
+
rbs_location_range star_loc = rbs_location_range_current_token(parser);
|
|
3925
|
+
|
|
3926
|
+
rbs_location_range name_loc = RBS_LOCATION_NULL_RANGE;
|
|
3927
|
+
if (parser->next_token.type == tLIDENT) {
|
|
3928
|
+
rbs_parser_advance(parser);
|
|
3929
|
+
name_loc = rbs_location_range_current_token(parser);
|
|
3930
|
+
}
|
|
3931
|
+
|
|
3932
|
+
ADVANCE_ASSERT(parser, pCOLON);
|
|
3933
|
+
rbs_location_range colon_loc = rbs_location_range_current_token(parser);
|
|
3934
|
+
|
|
3935
|
+
rbs_node_t *param_type = NULL;
|
|
3936
|
+
if (!rbs_parse_type(parser, ¶m_type, false, true, true)) {
|
|
3937
|
+
return false;
|
|
3938
|
+
}
|
|
3939
|
+
|
|
3940
|
+
rbs_location_range comment_loc = RBS_LOCATION_NULL_RANGE;
|
|
3941
|
+
if (!parse_inline_comment(parser, &comment_loc)) {
|
|
3942
|
+
return false;
|
|
3943
|
+
}
|
|
3944
|
+
|
|
3945
|
+
rbs_range_t full_range = {
|
|
3946
|
+
.start = rbs_range.start,
|
|
3947
|
+
.end = parser->current_token.range.end
|
|
3948
|
+
};
|
|
3949
|
+
|
|
3950
|
+
*annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_splat_param_type_annotation_new(
|
|
3951
|
+
ALLOCATOR(),
|
|
3952
|
+
RBS_RANGE_LEX2AST(full_range),
|
|
3953
|
+
RBS_RANGE_LEX2AST(rbs_range),
|
|
3954
|
+
star_loc,
|
|
3955
|
+
name_loc,
|
|
3956
|
+
colon_loc,
|
|
3957
|
+
param_type,
|
|
3958
|
+
comment_loc
|
|
3959
|
+
);
|
|
3960
|
+
return true;
|
|
3961
|
+
}
|
|
3962
|
+
case pSTAR2: {
|
|
3963
|
+
rbs_parser_advance(parser);
|
|
3964
|
+
rbs_location_range star2_loc = rbs_location_range_current_token(parser);
|
|
3965
|
+
|
|
3966
|
+
rbs_location_range name_loc = RBS_LOCATION_NULL_RANGE;
|
|
3967
|
+
if (parser->next_token.type == tLIDENT) {
|
|
3968
|
+
rbs_parser_advance(parser);
|
|
3969
|
+
name_loc = rbs_location_range_current_token(parser);
|
|
3970
|
+
}
|
|
3971
|
+
|
|
3972
|
+
ADVANCE_ASSERT(parser, pCOLON);
|
|
3973
|
+
rbs_location_range colon_loc = rbs_location_range_current_token(parser);
|
|
3974
|
+
|
|
3975
|
+
rbs_node_t *param_type = NULL;
|
|
3976
|
+
if (!rbs_parse_type(parser, ¶m_type, false, true, true)) {
|
|
3977
|
+
return false;
|
|
3978
|
+
}
|
|
3979
|
+
|
|
3980
|
+
rbs_location_range comment_loc = RBS_LOCATION_NULL_RANGE;
|
|
3981
|
+
if (!parse_inline_comment(parser, &comment_loc)) {
|
|
3982
|
+
return false;
|
|
3983
|
+
}
|
|
3984
|
+
|
|
3985
|
+
rbs_range_t full_range = {
|
|
3986
|
+
.start = rbs_range.start,
|
|
3987
|
+
.end = parser->current_token.range.end
|
|
3988
|
+
};
|
|
3989
|
+
|
|
3990
|
+
*annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_double_splat_param_type_annotation_new(
|
|
3991
|
+
ALLOCATOR(),
|
|
3992
|
+
RBS_RANGE_LEX2AST(full_range),
|
|
3993
|
+
RBS_RANGE_LEX2AST(rbs_range),
|
|
3994
|
+
star2_loc,
|
|
3995
|
+
name_loc,
|
|
3996
|
+
colon_loc,
|
|
3997
|
+
param_type,
|
|
3998
|
+
comment_loc
|
|
3999
|
+
);
|
|
4000
|
+
return true;
|
|
4001
|
+
}
|
|
4002
|
+
case pAMP: {
|
|
4003
|
+
rbs_parser_advance(parser);
|
|
4004
|
+
rbs_location_range ampersand_loc = rbs_location_range_current_token(parser);
|
|
4005
|
+
|
|
4006
|
+
rbs_location_range name_loc = RBS_LOCATION_NULL_RANGE;
|
|
4007
|
+
if (parser->next_token.type == tLIDENT) {
|
|
4008
|
+
rbs_parser_advance(parser);
|
|
4009
|
+
name_loc = rbs_location_range_current_token(parser);
|
|
4010
|
+
}
|
|
4011
|
+
|
|
4012
|
+
ADVANCE_ASSERT(parser, pCOLON);
|
|
4013
|
+
rbs_location_range colon_loc = rbs_location_range_current_token(parser);
|
|
4014
|
+
|
|
4015
|
+
rbs_location_range question_loc = RBS_LOCATION_NULL_RANGE;
|
|
4016
|
+
if (parser->next_token.type == pQUESTION) {
|
|
4017
|
+
rbs_parser_advance(parser);
|
|
4018
|
+
question_loc = rbs_location_range_current_token(parser);
|
|
4019
|
+
}
|
|
4020
|
+
|
|
4021
|
+
rbs_range_t type_range;
|
|
4022
|
+
type_range.start = parser->next_token.range.start;
|
|
4023
|
+
|
|
4024
|
+
parse_function_result *result = rbs_allocator_alloc(ALLOCATOR(), parse_function_result);
|
|
4025
|
+
if (!parse_function(parser, true, false, &result, true, true)) {
|
|
4026
|
+
return false;
|
|
4027
|
+
}
|
|
4028
|
+
|
|
4029
|
+
type_range.end = parser->current_token.range.end;
|
|
4030
|
+
|
|
4031
|
+
rbs_location_range comment_loc = RBS_LOCATION_NULL_RANGE;
|
|
4032
|
+
if (!parse_inline_comment(parser, &comment_loc)) {
|
|
4033
|
+
return false;
|
|
4034
|
+
}
|
|
4035
|
+
|
|
4036
|
+
rbs_range_t full_range = {
|
|
4037
|
+
.start = rbs_range.start,
|
|
4038
|
+
.end = parser->current_token.range.end
|
|
4039
|
+
};
|
|
4040
|
+
|
|
4041
|
+
*annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_block_param_type_annotation_new(
|
|
4042
|
+
ALLOCATOR(),
|
|
4043
|
+
RBS_RANGE_LEX2AST(full_range),
|
|
4044
|
+
RBS_RANGE_LEX2AST(rbs_range),
|
|
4045
|
+
ampersand_loc,
|
|
4046
|
+
name_loc,
|
|
4047
|
+
colon_loc,
|
|
4048
|
+
question_loc,
|
|
4049
|
+
RBS_RANGE_LEX2AST(type_range),
|
|
4050
|
+
result->function,
|
|
4051
|
+
comment_loc
|
|
4052
|
+
);
|
|
4053
|
+
return true;
|
|
4054
|
+
}
|
|
3856
4055
|
default: {
|
|
3857
4056
|
rbs_parser_set_error(parser, parser->next_token, true, "unexpected token for @rbs annotation");
|
|
3858
4057
|
return false;
|
|
@@ -3878,11 +4077,10 @@ static bool parse_inline_trailing_annotation(rbs_parser_t *parser, rbs_ast_ruby_
|
|
|
3878
4077
|
if (parser->next_token.type == kCLASSALIAS || parser->next_token.type == kMODULEALIAS) {
|
|
3879
4078
|
bool is_class_alias = (parser->next_token.type == kCLASSALIAS);
|
|
3880
4079
|
rbs_range_t keyword_range = parser->next_token.range;
|
|
3881
|
-
rbs_location_t *keyword_loc = rbs_location_new(ALLOCATOR(), keyword_range);
|
|
3882
4080
|
rbs_parser_advance(parser);
|
|
3883
4081
|
|
|
3884
4082
|
rbs_type_name_t *type_name = NULL;
|
|
3885
|
-
|
|
4083
|
+
rbs_location_range type_name_loc = RBS_LOCATION_NULL_RANGE;
|
|
3886
4084
|
rbs_range_t full_range;
|
|
3887
4085
|
|
|
3888
4086
|
// Check if a type name is provided
|
|
@@ -3894,7 +4092,7 @@ static bool parse_inline_trailing_annotation(rbs_parser_t *parser, rbs_ast_ruby_
|
|
|
3894
4092
|
return false;
|
|
3895
4093
|
}
|
|
3896
4094
|
// parse_type_name leaves current_token at the last identifier, don't advance
|
|
3897
|
-
type_name_loc =
|
|
4095
|
+
type_name_loc = RBS_RANGE_LEX2AST(type_name_range);
|
|
3898
4096
|
full_range.start = prefix_range.start;
|
|
3899
4097
|
full_range.end = type_name_range.end;
|
|
3900
4098
|
} else {
|
|
@@ -3903,15 +4101,14 @@ static bool parse_inline_trailing_annotation(rbs_parser_t *parser, rbs_ast_ruby_
|
|
|
3903
4101
|
full_range.end = keyword_range.end;
|
|
3904
4102
|
}
|
|
3905
4103
|
|
|
3906
|
-
|
|
3907
|
-
rbs_location_t *prefix_loc = rbs_location_new(ALLOCATOR(), prefix_range);
|
|
4104
|
+
rbs_location_range full_loc = RBS_RANGE_LEX2AST(full_range);
|
|
3908
4105
|
|
|
3909
4106
|
if (is_class_alias) {
|
|
3910
4107
|
*annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_class_alias_annotation_new(
|
|
3911
4108
|
ALLOCATOR(),
|
|
3912
4109
|
full_loc,
|
|
3913
|
-
|
|
3914
|
-
|
|
4110
|
+
RBS_RANGE_LEX2AST(prefix_range),
|
|
4111
|
+
RBS_RANGE_LEX2AST(keyword_range),
|
|
3915
4112
|
type_name,
|
|
3916
4113
|
type_name_loc
|
|
3917
4114
|
);
|
|
@@ -3919,8 +4116,8 @@ static bool parse_inline_trailing_annotation(rbs_parser_t *parser, rbs_ast_ruby_
|
|
|
3919
4116
|
*annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_module_alias_annotation_new(
|
|
3920
4117
|
ALLOCATOR(),
|
|
3921
4118
|
full_loc,
|
|
3922
|
-
|
|
3923
|
-
|
|
4119
|
+
RBS_RANGE_LEX2AST(prefix_range),
|
|
4120
|
+
RBS_RANGE_LEX2AST(keyword_range),
|
|
3924
4121
|
type_name,
|
|
3925
4122
|
type_name_loc
|
|
3926
4123
|
);
|
|
@@ -3930,7 +4127,7 @@ static bool parse_inline_trailing_annotation(rbs_parser_t *parser, rbs_ast_ruby_
|
|
|
3930
4127
|
|
|
3931
4128
|
// Otherwise, parse as regular type assertion
|
|
3932
4129
|
rbs_node_t *type = NULL;
|
|
3933
|
-
if (!rbs_parse_type(parser, &type, true, true)) {
|
|
4130
|
+
if (!rbs_parse_type(parser, &type, true, true, true)) {
|
|
3934
4131
|
return false;
|
|
3935
4132
|
}
|
|
3936
4133
|
|
|
@@ -3939,13 +4136,12 @@ static bool parse_inline_trailing_annotation(rbs_parser_t *parser, rbs_ast_ruby_
|
|
|
3939
4136
|
.end = parser->current_token.range.end
|
|
3940
4137
|
};
|
|
3941
4138
|
|
|
3942
|
-
|
|
3943
|
-
rbs_location_t *prefix_loc = rbs_location_new(ALLOCATOR(), prefix_range);
|
|
4139
|
+
rbs_location_range full_loc = RBS_RANGE_LEX2AST(full_range);
|
|
3944
4140
|
|
|
3945
4141
|
*annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_node_type_assertion_new(
|
|
3946
4142
|
ALLOCATOR(),
|
|
3947
4143
|
full_loc,
|
|
3948
|
-
|
|
4144
|
+
RBS_RANGE_LEX2AST(prefix_range),
|
|
3949
4145
|
type
|
|
3950
4146
|
);
|
|
3951
4147
|
return true;
|
|
@@ -3954,7 +4150,7 @@ static bool parse_inline_trailing_annotation(rbs_parser_t *parser, rbs_ast_ruby_
|
|
|
3954
4150
|
rbs_parser_advance(parser);
|
|
3955
4151
|
|
|
3956
4152
|
rbs_node_list_t *type_args = rbs_node_list_new(ALLOCATOR());
|
|
3957
|
-
|
|
4153
|
+
rbs_location_range_list_t *comma_locations = rbs_location_range_list_new(ALLOCATOR());
|
|
3958
4154
|
|
|
3959
4155
|
// Check for empty type args
|
|
3960
4156
|
if (parser->next_token.type == pRBRACKET) {
|
|
@@ -3963,10 +4159,9 @@ static bool parse_inline_trailing_annotation(rbs_parser_t *parser, rbs_ast_ruby_
|
|
|
3963
4159
|
}
|
|
3964
4160
|
|
|
3965
4161
|
// Parse type list with comma tracking
|
|
3966
|
-
CHECK_PARSE(parse_type_list_with_commas(parser, pRBRACKET, type_args, comma_locations, true, true));
|
|
4162
|
+
CHECK_PARSE(parse_type_list_with_commas(parser, pRBRACKET, type_args, comma_locations, true, true, false));
|
|
3967
4163
|
|
|
3968
4164
|
rbs_range_t close_bracket_range = parser->next_token.range;
|
|
3969
|
-
rbs_location_t *close_bracket_loc = rbs_location_new(ALLOCATOR(), close_bracket_range);
|
|
3970
4165
|
rbs_parser_advance(parser); // consume ]
|
|
3971
4166
|
|
|
3972
4167
|
rbs_range_t full_range = {
|
|
@@ -3974,15 +4169,14 @@ static bool parse_inline_trailing_annotation(rbs_parser_t *parser, rbs_ast_ruby_
|
|
|
3974
4169
|
.end = close_bracket_range.end
|
|
3975
4170
|
};
|
|
3976
4171
|
|
|
3977
|
-
|
|
3978
|
-
rbs_location_t *prefix_loc = rbs_location_new(ALLOCATOR(), prefix_range);
|
|
4172
|
+
rbs_location_range full_loc = RBS_RANGE_LEX2AST(full_range);
|
|
3979
4173
|
|
|
3980
4174
|
*annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_type_application_annotation_new(
|
|
3981
4175
|
ALLOCATOR(),
|
|
3982
4176
|
full_loc,
|
|
3983
|
-
|
|
4177
|
+
RBS_RANGE_LEX2AST(prefix_range),
|
|
3984
4178
|
type_args,
|
|
3985
|
-
|
|
4179
|
+
RBS_RANGE_LEX2AST(close_bracket_range),
|
|
3986
4180
|
comma_locations
|
|
3987
4181
|
);
|
|
3988
4182
|
return true;
|