rbs 3.10.4 → 4.0.0
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/.github/dependabot.yml +14 -14
- data/.github/workflows/bundle-update.yml +60 -0
- data/.github/workflows/c-check.yml +7 -5
- data/.github/workflows/comments.yml +2 -2
- data/.github/workflows/dependabot.yml +2 -2
- data/.github/workflows/ruby.yml +16 -26
- data/.github/workflows/rust.yml +95 -0
- data/.github/workflows/typecheck.yml +1 -1
- data/.github/workflows/windows.yml +2 -2
- data/.rubocop.yml +2 -2
- data/.vscode/extensions.json +5 -0
- data/.vscode/settings.json +19 -0
- data/CHANGELOG.md +202 -2
- data/Rakefile +9 -23
- data/Steepfile +2 -0
- data/config.yml +457 -13
- data/core/array.rbs +218 -188
- data/core/basic_object.rbs +9 -8
- data/core/binding.rbs +0 -2
- data/core/builtin.rbs +2 -2
- data/core/class.rbs +6 -5
- data/core/comparable.rbs +45 -31
- data/core/complex.rbs +66 -55
- data/core/dir.rbs +57 -45
- data/core/encoding.rbs +6 -6
- data/core/enumerable.rbs +105 -91
- data/core/enumerator/arithmetic_sequence.rbs +70 -0
- data/core/enumerator.rbs +24 -3
- data/core/errno.rbs +3 -2
- data/core/errors.rbs +31 -29
- data/core/exception.rbs +12 -12
- data/core/fiber.rbs +47 -36
- data/core/file.rbs +242 -169
- data/core/file_test.rbs +2 -2
- data/core/float.rbs +42 -68
- data/core/gc.rbs +78 -70
- data/core/hash.rbs +70 -60
- data/core/integer.rbs +32 -75
- data/core/io/buffer.rbs +36 -36
- data/core/io/wait.rbs +7 -7
- data/core/io.rbs +192 -146
- data/core/kernel.rbs +198 -147
- data/core/marshal.rbs +3 -3
- data/core/match_data.rbs +14 -12
- data/core/math.rbs +69 -67
- data/core/method.rbs +6 -8
- data/core/module.rbs +148 -88
- data/core/nil_class.rbs +4 -3
- data/core/numeric.rbs +53 -50
- data/core/object.rbs +6 -8
- data/core/object_space.rbs +11 -10
- data/core/pathname.rbs +131 -81
- data/core/proc.rbs +65 -34
- data/core/process.rbs +221 -201
- data/core/ractor.rbs +15 -11
- data/core/random.rbs +21 -3
- data/core/range.rbs +152 -49
- data/core/rational.rbs +5 -56
- 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 -116
- 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 +318 -298
- data/core/struct.rbs +26 -25
- data/core/symbol.rbs +25 -24
- data/core/thread.rbs +40 -41
- 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 +576 -0
- data/docs/syntax.md +46 -16
- data/docs/type_fingerprint.md +21 -0
- data/exe/rbs +1 -1
- data/ext/rbs_extension/ast_translation.c +595 -98
- data/ext/rbs_extension/class_constants.c +30 -0
- data/ext/rbs_extension/class_constants.h +15 -0
- data/ext/rbs_extension/legacy_location.c +30 -53
- data/ext/rbs_extension/legacy_location.h +37 -0
- data/ext/rbs_extension/main.c +125 -24
- data/include/rbs/ast.h +485 -150
- data/include/rbs/lexer.h +11 -4
- data/include/rbs/location.h +25 -44
- data/include/rbs/parser.h +20 -2
- data/include/rbs/util/rbs_constant_pool.h +0 -3
- data/include/rbs.h +8 -0
- data/lib/rbs/ast/annotation.rb +1 -1
- data/lib/rbs/ast/comment.rb +1 -1
- data/lib/rbs/ast/declarations.rb +10 -10
- data/lib/rbs/ast/members.rb +14 -14
- data/lib/rbs/ast/ruby/annotations.rb +409 -0
- data/lib/rbs/ast/ruby/comment_block.rb +245 -0
- data/lib/rbs/ast/ruby/declarations.rb +281 -0
- data/lib/rbs/ast/ruby/helpers/constant_helper.rb +28 -0
- data/lib/rbs/ast/ruby/helpers/location_helper.rb +15 -0
- data/lib/rbs/ast/ruby/members.rb +723 -0
- data/lib/rbs/ast/type_param.rb +24 -4
- data/lib/rbs/buffer.rb +105 -20
- data/lib/rbs/cli/diff.rb +16 -15
- data/lib/rbs/cli/validate.rb +62 -125
- data/lib/rbs/cli.rb +55 -23
- data/lib/rbs/collection/config/lockfile_generator.rb +8 -4
- data/lib/rbs/collection/sources/git.rb +1 -0
- data/lib/rbs/collection.rb +0 -1
- data/lib/rbs/definition.rb +6 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +119 -63
- data/lib/rbs/definition_builder/method_builder.rb +65 -30
- data/lib/rbs/definition_builder.rb +177 -20
- data/lib/rbs/diff.rb +7 -1
- data/lib/rbs/environment/class_entry.rb +69 -0
- data/lib/rbs/environment/module_entry.rb +66 -0
- data/lib/rbs/environment.rb +338 -155
- data/lib/rbs/environment_loader.rb +2 -2
- data/lib/rbs/errors.rb +30 -20
- data/lib/rbs/inline_parser/comment_association.rb +117 -0
- data/lib/rbs/inline_parser.rb +542 -0
- data/lib/rbs/location_aux.rb +36 -4
- data/lib/rbs/locator.rb +5 -1
- data/lib/rbs/method_type.rb +5 -3
- data/lib/rbs/namespace.rb +0 -7
- data/lib/rbs/parser_aux.rb +31 -8
- data/lib/rbs/prototype/helpers.rb +57 -0
- data/lib/rbs/prototype/rb.rb +3 -28
- data/lib/rbs/prototype/rbi.rb +3 -20
- data/lib/rbs/prototype/runtime.rb +10 -2
- data/lib/rbs/resolver/type_name_resolver.rb +0 -8
- data/lib/rbs/source.rb +99 -0
- data/lib/rbs/subtractor.rb +4 -3
- data/lib/rbs/test/type_check.rb +5 -2
- data/lib/rbs/type_name.rb +1 -8
- data/lib/rbs/types.rb +88 -78
- data/lib/rbs/unit_test/convertibles.rb +1 -0
- data/lib/rbs/unit_test/type_assertions.rb +35 -8
- data/lib/rbs/validator.rb +2 -2
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs.rb +12 -1
- data/rbs.gemspec +3 -2
- 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/schema/typeParam.json +17 -1
- data/sig/ancestor_builder.rbs +1 -1
- data/sig/ast/ruby/annotations.rbs +421 -0
- data/sig/ast/ruby/comment_block.rbs +127 -0
- data/sig/ast/ruby/declarations.rbs +158 -0
- data/sig/ast/ruby/helpers/constant_helper.rbs +11 -0
- data/sig/ast/ruby/helpers/location_helper.rbs +15 -0
- data/sig/ast/ruby/members.rbs +178 -0
- data/sig/buffer.rbs +63 -5
- data/sig/cli/diff.rbs +5 -11
- data/sig/cli/validate.rbs +12 -8
- data/sig/cli.rbs +18 -18
- data/sig/definition.rbs +6 -0
- data/sig/definition_builder.rbs +3 -1
- data/sig/environment/class_entry.rbs +50 -0
- data/sig/environment/module_entry.rbs +50 -0
- data/sig/environment.rbs +37 -81
- data/sig/errors.rbs +26 -20
- data/sig/inline_parser/comment_association.rbs +71 -0
- data/sig/inline_parser.rbs +124 -0
- data/sig/location.rbs +32 -7
- data/sig/locator.rbs +0 -2
- data/sig/method_builder.rbs +9 -4
- data/sig/namespace.rbs +0 -5
- data/sig/parser.rbs +47 -13
- data/sig/prototype/helpers.rbs +2 -0
- data/sig/resolver/type_name_resolver.rbs +0 -3
- data/sig/source.rbs +48 -0
- data/sig/type_param.rbs +13 -8
- data/sig/typename.rbs +0 -5
- data/sig/types.rbs +6 -7
- data/sig/unit_test/spy.rbs +0 -8
- data/sig/unit_test/type_assertions.rbs +11 -0
- data/src/ast.c +491 -143
- data/src/lexer.c +1552 -1314
- data/src/lexer.re +7 -0
- data/src/lexstate.c +8 -1
- data/src/location.c +8 -48
- data/src/parser.c +1107 -409
- 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/digest/0/digest.rbs +110 -0
- data/stdlib/erb/0/erb.rbs +64 -53
- data/stdlib/etc/0/etc.rbs +55 -50
- data/stdlib/fileutils/0/fileutils.rbs +140 -126
- data/stdlib/forwardable/0/forwardable.rbs +10 -10
- data/stdlib/io-console/0/io-console.rbs +2 -2
- data/stdlib/json/0/json.rbs +158 -131
- 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 -30
- data/stdlib/open-uri/0/open-uri.rbs +8 -8
- data/stdlib/open3/0/open3.rbs +469 -10
- data/stdlib/openssl/0/openssl.rbs +144 -129
- data/stdlib/optparse/0/optparse.rbs +23 -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 +62 -9
- data/stdlib/psych/0/store.rbs +2 -4
- data/stdlib/pty/0/pty.rbs +9 -6
- data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
- data/stdlib/rdoc/0/code_object.rbs +2 -1
- data/stdlib/rdoc/0/parser.rbs +1 -1
- data/stdlib/rdoc/0/store.rbs +1 -1
- data/stdlib/ripper/0/ripper.rbs +20 -17
- data/stdlib/securerandom/0/manifest.yaml +2 -0
- data/stdlib/securerandom/0/securerandom.rbs +7 -20
- data/stdlib/shellwords/0/shellwords.rbs +2 -2
- data/stdlib/socket/0/addrinfo.rbs +9 -9
- 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 +31 -18
- data/stdlib/uri/0/file.rbs +2 -2
- data/stdlib/uri/0/generic.rbs +9 -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 +6 -6
- 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 +66 -3
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, \
|
|
@@ -61,6 +56,43 @@
|
|
|
61
56
|
case kUSE: \
|
|
62
57
|
case kAS: \
|
|
63
58
|
case k__TODO__: \
|
|
59
|
+
case kSKIP: \
|
|
60
|
+
case kRETURN: \
|
|
61
|
+
/* nop */
|
|
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__: \
|
|
64
96
|
/* nop */
|
|
65
97
|
|
|
66
98
|
#define CHECK_PARSE(call) \
|
|
@@ -109,18 +141,12 @@ static bool rbs_is_untyped_params(method_params *params) {
|
|
|
109
141
|
return params->required_positionals == NULL;
|
|
110
142
|
}
|
|
111
143
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
*
|
|
115
|
-
* @param parser
|
|
116
|
-
* @return New RBS::Location object.
|
|
117
|
-
* */
|
|
118
|
-
static rbs_location_t *rbs_location_current_token(rbs_parser_t *parser) {
|
|
119
|
-
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);
|
|
120
146
|
}
|
|
121
147
|
|
|
122
|
-
static bool parse_optional(rbs_parser_t *parser, rbs_node_t **optional);
|
|
123
|
-
static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type);
|
|
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);
|
|
124
150
|
|
|
125
151
|
/**
|
|
126
152
|
* @returns A borrowed copy of the current token, which does *not* need to be freed.
|
|
@@ -176,8 +202,8 @@ static bool parse_type_name(rbs_parser_t *parser, TypeNameKind kind, rbs_range_t
|
|
|
176
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
|
|
177
203
|
) {
|
|
178
204
|
rbs_constant_id_t symbol_value = INTERN_TOKEN(parser, parser->current_token);
|
|
179
|
-
|
|
180
|
-
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);
|
|
181
207
|
rbs_node_list_append(path, (rbs_node_t *) symbol);
|
|
182
208
|
|
|
183
209
|
rbs_parser_advance(parser);
|
|
@@ -188,11 +214,12 @@ static bool parse_type_name(rbs_parser_t *parser, TypeNameKind kind, rbs_range_t
|
|
|
188
214
|
.start = rg->start,
|
|
189
215
|
.end = parser->current_token.range.end
|
|
190
216
|
};
|
|
191
|
-
|
|
192
|
-
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);
|
|
193
218
|
|
|
194
219
|
switch (parser->current_token.type) {
|
|
195
220
|
case tLIDENT:
|
|
221
|
+
case kSKIP:
|
|
222
|
+
case kRETURN:
|
|
196
223
|
if (kind & ALIAS_NAME) goto success;
|
|
197
224
|
goto error_handling;
|
|
198
225
|
case tULIDENT:
|
|
@@ -210,10 +237,10 @@ success: {
|
|
|
210
237
|
rg->end = parser->current_token.range.end;
|
|
211
238
|
}
|
|
212
239
|
|
|
213
|
-
|
|
240
|
+
rbs_location_range symbol_range = rbs_location_range_current_token(parser);
|
|
214
241
|
rbs_constant_id_t name = INTERN_TOKEN(parser, parser->current_token);
|
|
215
|
-
rbs_ast_symbol_t *symbol = rbs_ast_symbol_new(ALLOCATOR(),
|
|
216
|
-
*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);
|
|
217
244
|
return true;
|
|
218
245
|
}
|
|
219
246
|
|
|
@@ -241,16 +268,53 @@ error_handling: {
|
|
|
241
268
|
| {} type `,` ... `,` <type> eol
|
|
242
269
|
*/
|
|
243
270
|
NODISCARD
|
|
244
|
-
static bool parse_type_list(rbs_parser_t *parser, enum RBSTokenType eol, rbs_node_list_t *types) {
|
|
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) {
|
|
272
|
+
while (true) {
|
|
273
|
+
rbs_node_t *type;
|
|
274
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, void_allowed, self_allowed, classish_allowed));
|
|
275
|
+
rbs_node_list_append(types, type);
|
|
276
|
+
|
|
277
|
+
if (parser->next_token.type == pCOMMA) {
|
|
278
|
+
rbs_parser_advance(parser);
|
|
279
|
+
|
|
280
|
+
if (parser->next_token.type == eol) {
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
} else {
|
|
284
|
+
if (parser->next_token.type == eol) {
|
|
285
|
+
break;
|
|
286
|
+
} else {
|
|
287
|
+
rbs_parser_set_error(parser, parser->next_token, true, "comma delimited type list is expected");
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/*
|
|
297
|
+
type_list_with_commas ::= {} type `,` ... <`,`> eol
|
|
298
|
+
| {} type `,` ... `,` <type> eol
|
|
299
|
+
*/
|
|
300
|
+
NODISCARD
|
|
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) {
|
|
245
302
|
while (true) {
|
|
246
303
|
rbs_node_t *type;
|
|
247
|
-
CHECK_PARSE(rbs_parse_type(parser, &type));
|
|
304
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, void_allowed, self_allowed, classish_allowed));
|
|
248
305
|
rbs_node_list_append(types, type);
|
|
249
306
|
|
|
250
307
|
if (parser->next_token.type == pCOMMA) {
|
|
308
|
+
rbs_location_range comma_loc = RBS_RANGE_LEX2AST(parser->next_token.range);
|
|
309
|
+
rbs_location_range_list_append(comma_locations, comma_loc);
|
|
251
310
|
rbs_parser_advance(parser);
|
|
252
311
|
|
|
253
312
|
if (parser->next_token.type == eol) {
|
|
313
|
+
// Handle trailing comma - for type applications, this is an error
|
|
314
|
+
if (eol == pRBRACKET) {
|
|
315
|
+
rbs_parser_set_error(parser, parser->next_token, true, "unexpected trailing comma");
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
254
318
|
break;
|
|
255
319
|
}
|
|
256
320
|
} else {
|
|
@@ -286,21 +350,17 @@ static bool is_keyword_token(enum RBSTokenType type) {
|
|
|
286
350
|
| {} type <param>
|
|
287
351
|
*/
|
|
288
352
|
NODISCARD
|
|
289
|
-
static bool parse_function_param(rbs_parser_t *parser, rbs_types_function_param_t **function_param) {
|
|
353
|
+
static bool parse_function_param(rbs_parser_t *parser, rbs_types_function_param_t **function_param, bool self_allowed, bool classish_allowed) {
|
|
290
354
|
rbs_range_t type_range;
|
|
291
355
|
type_range.start = parser->next_token.range.start;
|
|
292
356
|
rbs_node_t *type;
|
|
293
|
-
CHECK_PARSE(rbs_parse_type(parser, &type));
|
|
357
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, false, self_allowed, classish_allowed));
|
|
294
358
|
type_range.end = parser->current_token.range.end;
|
|
295
359
|
|
|
296
360
|
if (parser->next_token.type == pCOMMA || parser->next_token.type == pRPAREN) {
|
|
297
361
|
rbs_range_t param_range = type_range;
|
|
298
362
|
|
|
299
|
-
|
|
300
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 1);
|
|
301
|
-
rbs_loc_add_optional_child(loc, INTERN("name"), NULL_RANGE);
|
|
302
|
-
|
|
303
|
-
*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);
|
|
304
364
|
return true;
|
|
305
365
|
} else {
|
|
306
366
|
rbs_range_t name_range = parser->next_token.range;
|
|
@@ -318,15 +378,12 @@ static bool parse_function_param(rbs_parser_t *parser, rbs_types_function_param_
|
|
|
318
378
|
}
|
|
319
379
|
|
|
320
380
|
rbs_string_t unquoted_str = rbs_unquote_string(ALLOCATOR(), rbs_parser_peek_current_token(parser), parser->lexer->encoding);
|
|
321
|
-
|
|
381
|
+
rbs_location_range symbol_range = rbs_location_range_current_token(parser);
|
|
322
382
|
rbs_constant_id_t constant_id = rbs_constant_pool_insert_string(&parser->constant_pool, unquoted_str);
|
|
323
|
-
rbs_ast_symbol_t *name = rbs_ast_symbol_new(ALLOCATOR(),
|
|
324
|
-
|
|
325
|
-
rbs_location_t *loc = rbs_location_new(ALLOCATOR(), param_range);
|
|
326
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 1);
|
|
327
|
-
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);
|
|
328
384
|
|
|
329
|
-
*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);
|
|
330
387
|
return true;
|
|
331
388
|
}
|
|
332
389
|
}
|
|
@@ -348,18 +405,18 @@ NODISCARD
|
|
|
348
405
|
static bool parse_keyword_key(rbs_parser_t *parser, rbs_ast_symbol_t **key) {
|
|
349
406
|
rbs_parser_advance(parser);
|
|
350
407
|
|
|
351
|
-
|
|
408
|
+
rbs_location_range symbol_range = rbs_location_range_current_token(parser);
|
|
352
409
|
|
|
353
410
|
if (parser->next_token.type == pQUESTION) {
|
|
354
411
|
*key = rbs_ast_symbol_new(
|
|
355
412
|
ALLOCATOR(),
|
|
356
|
-
|
|
413
|
+
symbol_range,
|
|
357
414
|
&parser->constant_pool,
|
|
358
415
|
intern_token_start_end(parser, parser->current_token, parser->next_token)
|
|
359
416
|
);
|
|
360
417
|
rbs_parser_advance(parser);
|
|
361
418
|
} else {
|
|
362
|
-
*key = rbs_ast_symbol_new(ALLOCATOR(),
|
|
419
|
+
*key = rbs_ast_symbol_new(ALLOCATOR(), symbol_range, &parser->constant_pool, INTERN_TOKEN(parser, parser->current_token));
|
|
363
420
|
}
|
|
364
421
|
|
|
365
422
|
return true;
|
|
@@ -369,7 +426,7 @@ static bool parse_keyword_key(rbs_parser_t *parser, rbs_ast_symbol_t **key) {
|
|
|
369
426
|
keyword ::= {} keyword `:` <function_param>
|
|
370
427
|
*/
|
|
371
428
|
NODISCARD
|
|
372
|
-
static bool parse_keyword(rbs_parser_t *parser, rbs_hash_t *keywords, rbs_hash_t *memo) {
|
|
429
|
+
static bool parse_keyword(rbs_parser_t *parser, rbs_hash_t *keywords, rbs_hash_t *memo, bool self_allowed, bool classish_allowed) {
|
|
373
430
|
rbs_ast_symbol_t *key = NULL;
|
|
374
431
|
CHECK_PARSE(parse_keyword_key(parser, &key));
|
|
375
432
|
|
|
@@ -377,13 +434,13 @@ static bool parse_keyword(rbs_parser_t *parser, rbs_hash_t *keywords, rbs_hash_t
|
|
|
377
434
|
rbs_parser_set_error(parser, parser->current_token, true, "duplicated keyword argument");
|
|
378
435
|
return false;
|
|
379
436
|
} else {
|
|
380
|
-
|
|
381
|
-
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));
|
|
382
439
|
}
|
|
383
440
|
|
|
384
441
|
ADVANCE_ASSERT(parser, pCOLON);
|
|
385
442
|
rbs_types_function_param_t *param = NULL;
|
|
386
|
-
CHECK_PARSE(parse_function_param(parser, ¶m));
|
|
443
|
+
CHECK_PARSE(parse_function_param(parser, ¶m, self_allowed, classish_allowed));
|
|
387
444
|
|
|
388
445
|
rbs_hash_set(keywords, (rbs_node_t *) key, (rbs_node_t *) param);
|
|
389
446
|
|
|
@@ -454,7 +511,7 @@ static bool parser_advance_if(rbs_parser_t *parser, enum RBSTokenType type) {
|
|
|
454
511
|
| {} `**` <function_param>
|
|
455
512
|
*/
|
|
456
513
|
NODISCARD
|
|
457
|
-
static bool parse_params(rbs_parser_t *parser, method_params *params) {
|
|
514
|
+
static bool parse_params(rbs_parser_t *parser, method_params *params, bool self_allowed, bool classish_allowed) {
|
|
458
515
|
if (parser->next_token.type == pQUESTION && parser->next_token2.type == pRPAREN) {
|
|
459
516
|
params->required_positionals = NULL;
|
|
460
517
|
rbs_parser_advance(parser);
|
|
@@ -483,7 +540,7 @@ static bool parse_params(rbs_parser_t *parser, method_params *params) {
|
|
|
483
540
|
}
|
|
484
541
|
|
|
485
542
|
rbs_types_function_param_t *param = NULL;
|
|
486
|
-
CHECK_PARSE(parse_function_param(parser, ¶m));
|
|
543
|
+
CHECK_PARSE(parse_function_param(parser, ¶m, self_allowed, classish_allowed));
|
|
487
544
|
rbs_node_list_append(params->required_positionals, (rbs_node_t *) param);
|
|
488
545
|
|
|
489
546
|
break;
|
|
@@ -497,20 +554,21 @@ static bool parse_params(rbs_parser_t *parser, method_params *params) {
|
|
|
497
554
|
PARSE_OPTIONAL_PARAMS:
|
|
498
555
|
while (true) {
|
|
499
556
|
switch (parser->next_token.type) {
|
|
500
|
-
case pQUESTION:
|
|
557
|
+
case pQUESTION: {
|
|
501
558
|
rbs_parser_advance(parser);
|
|
502
559
|
|
|
503
560
|
if (is_keyword(parser)) {
|
|
504
|
-
CHECK_PARSE(parse_keyword(parser, params->optional_keywords, memo));
|
|
561
|
+
CHECK_PARSE(parse_keyword(parser, params->optional_keywords, memo, self_allowed, classish_allowed));
|
|
505
562
|
parser_advance_if(parser, pCOMMA);
|
|
506
563
|
goto PARSE_KEYWORDS;
|
|
507
564
|
}
|
|
508
565
|
|
|
509
566
|
rbs_types_function_param_t *param = NULL;
|
|
510
|
-
CHECK_PARSE(parse_function_param(parser, ¶m));
|
|
567
|
+
CHECK_PARSE(parse_function_param(parser, ¶m, self_allowed, classish_allowed));
|
|
511
568
|
rbs_node_list_append(params->optional_positionals, (rbs_node_t *) param);
|
|
512
569
|
|
|
513
570
|
break;
|
|
571
|
+
}
|
|
514
572
|
default:
|
|
515
573
|
goto PARSE_REST_PARAM;
|
|
516
574
|
}
|
|
@@ -524,7 +582,7 @@ PARSE_REST_PARAM:
|
|
|
524
582
|
if (parser->next_token.type == pSTAR) {
|
|
525
583
|
rbs_parser_advance(parser);
|
|
526
584
|
rbs_types_function_param_t *param = NULL;
|
|
527
|
-
CHECK_PARSE(parse_function_param(parser, ¶m));
|
|
585
|
+
CHECK_PARSE(parse_function_param(parser, ¶m, self_allowed, classish_allowed));
|
|
528
586
|
params->rest_positionals = (rbs_node_t *) param;
|
|
529
587
|
|
|
530
588
|
if (!parser_advance_if(parser, pCOMMA)) {
|
|
@@ -551,7 +609,7 @@ PARSE_TRAILING_PARAMS:
|
|
|
551
609
|
}
|
|
552
610
|
|
|
553
611
|
rbs_types_function_param_t *param = NULL;
|
|
554
|
-
CHECK_PARSE(parse_function_param(parser, ¶m));
|
|
612
|
+
CHECK_PARSE(parse_function_param(parser, ¶m, self_allowed, classish_allowed));
|
|
555
613
|
rbs_node_list_append(params->trailing_positionals, (rbs_node_t *) param);
|
|
556
614
|
|
|
557
615
|
break;
|
|
@@ -568,20 +626,20 @@ PARSE_KEYWORDS:
|
|
|
568
626
|
case pQUESTION:
|
|
569
627
|
rbs_parser_advance(parser);
|
|
570
628
|
if (is_keyword(parser)) {
|
|
571
|
-
CHECK_PARSE(parse_keyword(parser, params->optional_keywords, memo));
|
|
629
|
+
CHECK_PARSE(parse_keyword(parser, params->optional_keywords, memo, self_allowed, classish_allowed));
|
|
572
630
|
} else {
|
|
573
631
|
rbs_parser_set_error(parser, parser->next_token, true, "optional keyword argument type is expected");
|
|
574
632
|
return false;
|
|
575
633
|
}
|
|
576
634
|
break;
|
|
577
635
|
|
|
578
|
-
case pSTAR2:
|
|
636
|
+
case pSTAR2: {
|
|
579
637
|
rbs_parser_advance(parser);
|
|
580
638
|
rbs_types_function_param_t *param = NULL;
|
|
581
|
-
CHECK_PARSE(parse_function_param(parser, ¶m));
|
|
639
|
+
CHECK_PARSE(parse_function_param(parser, ¶m, self_allowed, classish_allowed));
|
|
582
640
|
params->rest_keywords = (rbs_node_t *) param;
|
|
583
641
|
break;
|
|
584
|
-
|
|
642
|
+
}
|
|
585
643
|
case tUIDENT:
|
|
586
644
|
case tLIDENT:
|
|
587
645
|
case tQIDENT:
|
|
@@ -590,7 +648,7 @@ PARSE_KEYWORDS:
|
|
|
590
648
|
case tBANGIDENT:
|
|
591
649
|
KEYWORD_CASES
|
|
592
650
|
if (is_keyword(parser)) {
|
|
593
|
-
CHECK_PARSE(parse_keyword(parser, params->required_keywords, memo));
|
|
651
|
+
CHECK_PARSE(parse_keyword(parser, params->required_keywords, memo, self_allowed, classish_allowed));
|
|
594
652
|
} else {
|
|
595
653
|
rbs_parser_set_error(parser, parser->next_token, true, "required keyword argument type is expected");
|
|
596
654
|
return false;
|
|
@@ -620,18 +678,22 @@ EOP:
|
|
|
620
678
|
| {} simple_type <`?`>
|
|
621
679
|
*/
|
|
622
680
|
NODISCARD
|
|
623
|
-
static bool parse_optional(rbs_parser_t *parser, rbs_node_t **optional) {
|
|
681
|
+
static bool parse_optional(rbs_parser_t *parser, rbs_node_t **optional, bool void_allowed, bool self_allowed, bool classish_allowed) {
|
|
624
682
|
rbs_range_t rg;
|
|
625
683
|
rg.start = parser->next_token.range.start;
|
|
626
684
|
|
|
627
685
|
rbs_node_t *type = NULL;
|
|
628
|
-
CHECK_PARSE(parse_simple(parser, &type));
|
|
686
|
+
CHECK_PARSE(parse_simple(parser, &type, void_allowed, self_allowed, classish_allowed));
|
|
629
687
|
|
|
630
688
|
if (parser->next_token.type == pQUESTION) {
|
|
689
|
+
if (void_allowed && type->type == RBS_TYPES_BASES_VOID) {
|
|
690
|
+
rbs_parser_set_error(parser, parser->current_token, true, "void type is not allowed here");
|
|
691
|
+
return false;
|
|
692
|
+
}
|
|
693
|
+
|
|
631
694
|
rbs_parser_advance(parser);
|
|
632
695
|
rg.end = parser->current_token.range.end;
|
|
633
|
-
|
|
634
|
-
*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);
|
|
635
697
|
} else {
|
|
636
698
|
*optional = type;
|
|
637
699
|
}
|
|
@@ -656,13 +718,13 @@ static void initialize_method_params(method_params *params, rbs_allocator_t *all
|
|
|
656
718
|
| {} `[` `self` `:` type <`]`>
|
|
657
719
|
*/
|
|
658
720
|
NODISCARD
|
|
659
|
-
static bool parse_self_type_binding(rbs_parser_t *parser, rbs_node_t **self_type) {
|
|
721
|
+
static bool parse_self_type_binding(rbs_parser_t *parser, rbs_node_t **self_type, bool self_allowed, bool classish_allowed) {
|
|
660
722
|
if (parser->next_token.type == pLBRACKET) {
|
|
661
723
|
rbs_parser_advance(parser);
|
|
662
724
|
ADVANCE_ASSERT(parser, kSELF);
|
|
663
725
|
ADVANCE_ASSERT(parser, pCOLON);
|
|
664
726
|
rbs_node_t *type;
|
|
665
|
-
CHECK_PARSE(rbs_parse_type(parser, &type));
|
|
727
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, false, self_allowed, classish_allowed));
|
|
666
728
|
ADVANCE_ASSERT(parser, pRBRACKET);
|
|
667
729
|
*self_type = type;
|
|
668
730
|
}
|
|
@@ -684,7 +746,7 @@ typedef struct {
|
|
|
684
746
|
| {} self_type_binding? `->` <optional>
|
|
685
747
|
*/
|
|
686
748
|
NODISCARD
|
|
687
|
-
static bool parse_function(rbs_parser_t *parser, bool accept_type_binding, parse_function_result **result) {
|
|
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) {
|
|
688
750
|
rbs_node_t *function = NULL;
|
|
689
751
|
rbs_types_block_t *block = NULL;
|
|
690
752
|
rbs_node_t *function_self_type = NULL;
|
|
@@ -696,13 +758,13 @@ static bool parse_function(rbs_parser_t *parser, bool accept_type_binding, parse
|
|
|
696
758
|
|
|
697
759
|
if (parser->next_token.type == pLPAREN) {
|
|
698
760
|
rbs_parser_advance(parser);
|
|
699
|
-
CHECK_PARSE(parse_params(parser, ¶ms));
|
|
761
|
+
CHECK_PARSE(parse_params(parser, ¶ms, self_allowed, classish_allowed));
|
|
700
762
|
ADVANCE_ASSERT(parser, pRPAREN);
|
|
701
763
|
}
|
|
702
764
|
|
|
703
765
|
// Passing NULL to function_self_type means the function itself doesn't accept self type binding. (== method type)
|
|
704
766
|
if (accept_type_binding) {
|
|
705
|
-
CHECK_PARSE(parse_self_type_binding(parser, &function_self_type));
|
|
767
|
+
CHECK_PARSE(parse_self_type_binding(parser, &function_self_type, self_allowed, classish_allowed));
|
|
706
768
|
} else {
|
|
707
769
|
if (rbs_is_untyped_params(¶ms)) {
|
|
708
770
|
if (parser->next_token.type != pARROW) {
|
|
@@ -715,6 +777,11 @@ static bool parse_function(rbs_parser_t *parser, bool accept_type_binding, parse
|
|
|
715
777
|
bool required = true;
|
|
716
778
|
rbs_range_t block_range;
|
|
717
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
|
+
|
|
718
785
|
if (parser->next_token.type == pQUESTION && parser->next_token2.type == pLBRACE) {
|
|
719
786
|
// Optional block
|
|
720
787
|
block_range.start = parser->next_token.range.start;
|
|
@@ -732,29 +799,28 @@ static bool parse_function(rbs_parser_t *parser, bool accept_type_binding, parse
|
|
|
732
799
|
|
|
733
800
|
if (parser->next_token.type == pLPAREN) {
|
|
734
801
|
rbs_parser_advance(parser);
|
|
735
|
-
CHECK_PARSE(parse_params(parser, &block_params));
|
|
802
|
+
CHECK_PARSE(parse_params(parser, &block_params, self_allowed, classish_allowed));
|
|
736
803
|
ADVANCE_ASSERT(parser, pRPAREN);
|
|
737
804
|
}
|
|
738
805
|
|
|
739
806
|
rbs_node_t *self_type = NULL;
|
|
740
|
-
CHECK_PARSE(parse_self_type_binding(parser, &self_type));
|
|
807
|
+
CHECK_PARSE(parse_self_type_binding(parser, &self_type, self_allowed, classish_allowed));
|
|
741
808
|
|
|
742
809
|
ADVANCE_ASSERT(parser, pARROW);
|
|
743
810
|
rbs_node_t *block_return_type = NULL;
|
|
744
|
-
CHECK_PARSE(parse_optional(parser, &block_return_type));
|
|
811
|
+
CHECK_PARSE(parse_optional(parser, &block_return_type, true, self_allowed, classish_allowed));
|
|
745
812
|
|
|
746
813
|
ADVANCE_ASSERT(parser, pRBRACE);
|
|
747
814
|
|
|
748
815
|
block_range.end = parser->current_token.range.end;
|
|
749
|
-
rbs_location_t *loc = rbs_location_new(ALLOCATOR(), block_range);
|
|
750
816
|
|
|
751
817
|
rbs_node_t *block_function = NULL;
|
|
752
818
|
if (rbs_is_untyped_params(&block_params)) {
|
|
753
|
-
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);
|
|
754
820
|
} else {
|
|
755
821
|
block_function = (rbs_node_t *) rbs_types_function_new(
|
|
756
822
|
ALLOCATOR(),
|
|
757
|
-
|
|
823
|
+
RBS_RANGE_LEX2AST(block_range),
|
|
758
824
|
block_params.required_positionals,
|
|
759
825
|
block_params.optional_positionals,
|
|
760
826
|
block_params.rest_positionals,
|
|
@@ -766,21 +832,20 @@ static bool parse_function(rbs_parser_t *parser, bool accept_type_binding, parse
|
|
|
766
832
|
);
|
|
767
833
|
}
|
|
768
834
|
|
|
769
|
-
block = rbs_types_block_new(ALLOCATOR(),
|
|
835
|
+
block = rbs_types_block_new(ALLOCATOR(), RBS_RANGE_LEX2AST(block_range), block_function, required, self_type);
|
|
770
836
|
}
|
|
771
837
|
|
|
772
838
|
ADVANCE_ASSERT(parser, pARROW);
|
|
773
839
|
rbs_node_t *type = NULL;
|
|
774
|
-
CHECK_PARSE(parse_optional(parser, &type));
|
|
840
|
+
CHECK_PARSE(parse_optional(parser, &type, true, self_allowed, classish_allowed));
|
|
775
841
|
|
|
776
842
|
function_range.end = parser->current_token.range.end;
|
|
777
|
-
rbs_location_t *loc = rbs_location_new(ALLOCATOR(), function_range);
|
|
778
843
|
if (rbs_is_untyped_params(¶ms)) {
|
|
779
|
-
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);
|
|
780
845
|
} else {
|
|
781
846
|
function = (rbs_node_t *) rbs_types_function_new(
|
|
782
847
|
ALLOCATOR(),
|
|
783
|
-
|
|
848
|
+
RBS_RANGE_LEX2AST(function_range),
|
|
784
849
|
params.required_positionals,
|
|
785
850
|
params.optional_positionals,
|
|
786
851
|
params.rest_positionals,
|
|
@@ -802,14 +867,14 @@ static bool parse_function(rbs_parser_t *parser, bool accept_type_binding, parse
|
|
|
802
867
|
proc_type ::= {`^`} <function>
|
|
803
868
|
*/
|
|
804
869
|
NODISCARD
|
|
805
|
-
static bool parse_proc_type(rbs_parser_t *parser, rbs_types_proc_t **proc) {
|
|
870
|
+
static bool parse_proc_type(rbs_parser_t *parser, rbs_types_proc_t **proc, bool self_allowed, bool classish_allowed) {
|
|
806
871
|
rbs_position_t start = parser->current_token.range.start;
|
|
807
872
|
parse_function_result *result = rbs_allocator_alloc(ALLOCATOR(), parse_function_result);
|
|
808
|
-
CHECK_PARSE(parse_function(parser, true, &result));
|
|
873
|
+
CHECK_PARSE(parse_function(parser, true, true, &result, self_allowed, classish_allowed));
|
|
809
874
|
|
|
810
875
|
rbs_position_t end = parser->current_token.range.end;
|
|
811
|
-
|
|
812
|
-
*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);
|
|
813
878
|
return true;
|
|
814
879
|
}
|
|
815
880
|
|
|
@@ -830,7 +895,7 @@ static void check_key_duplication(rbs_parser_t *parser, rbs_hash_t *fields, rbs_
|
|
|
830
895
|
| {} literal_type `=>` <type>
|
|
831
896
|
*/
|
|
832
897
|
NODISCARD
|
|
833
|
-
static bool parse_record_attributes(rbs_parser_t *parser, rbs_hash_t **fields) {
|
|
898
|
+
static bool parse_record_attributes(rbs_parser_t *parser, rbs_hash_t **fields, bool self_allowed, bool classish_allowed) {
|
|
834
899
|
*fields = rbs_hash_new(ALLOCATOR());
|
|
835
900
|
|
|
836
901
|
if (parser->next_token.type == pRBRACE) return true;
|
|
@@ -863,7 +928,7 @@ static bool parse_record_attributes(rbs_parser_t *parser, rbs_hash_t **fields) {
|
|
|
863
928
|
case kTRUE:
|
|
864
929
|
case kFALSE: {
|
|
865
930
|
rbs_node_t *type = NULL;
|
|
866
|
-
CHECK_PARSE(parse_simple(parser, &type));
|
|
931
|
+
CHECK_PARSE(parse_simple(parser, &type, false, self_allowed, classish_allowed));
|
|
867
932
|
|
|
868
933
|
key = (rbs_ast_symbol_t *) ((rbs_types_literal_t *) type)->literal;
|
|
869
934
|
break;
|
|
@@ -880,11 +945,10 @@ static bool parse_record_attributes(rbs_parser_t *parser, rbs_hash_t **fields) {
|
|
|
880
945
|
field_range.start = parser->current_token.range.end;
|
|
881
946
|
|
|
882
947
|
rbs_node_t *type;
|
|
883
|
-
CHECK_PARSE(rbs_parse_type(parser, &type));
|
|
948
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, false, self_allowed, classish_allowed));
|
|
884
949
|
|
|
885
950
|
field_range.end = parser->current_token.range.end;
|
|
886
|
-
|
|
887
|
-
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));
|
|
888
952
|
|
|
889
953
|
if (parser_advance_if(parser, pCOMMA)) {
|
|
890
954
|
if (parser->next_token.type == pRBRACE) {
|
|
@@ -901,7 +965,7 @@ static bool parse_record_attributes(rbs_parser_t *parser, rbs_hash_t **fields) {
|
|
|
901
965
|
symbol ::= {<tSYMBOL>}
|
|
902
966
|
*/
|
|
903
967
|
NODISCARD
|
|
904
|
-
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) {
|
|
905
969
|
size_t offset_bytes = parser->lexer->encoding->char_width((const uint8_t *) ":", (size_t) 1);
|
|
906
970
|
size_t bytes = rbs_token_bytes(parser->current_token) - offset_bytes;
|
|
907
971
|
|
|
@@ -909,7 +973,7 @@ static bool parse_symbol(rbs_parser_t *parser, rbs_location_t *location, rbs_typ
|
|
|
909
973
|
|
|
910
974
|
switch (parser->current_token.type) {
|
|
911
975
|
case tSYMBOL: {
|
|
912
|
-
|
|
976
|
+
rbs_location_range symbol_range = rbs_location_range_current_token(parser);
|
|
913
977
|
|
|
914
978
|
char *buffer = rbs_peek_token(parser->lexer, parser->current_token);
|
|
915
979
|
rbs_constant_id_t constant_id = rbs_constant_pool_insert_shared(
|
|
@@ -917,12 +981,12 @@ static bool parse_symbol(rbs_parser_t *parser, rbs_location_t *location, rbs_typ
|
|
|
917
981
|
(const uint8_t *) buffer + offset_bytes,
|
|
918
982
|
bytes
|
|
919
983
|
);
|
|
920
|
-
literal = rbs_ast_symbol_new(ALLOCATOR(),
|
|
984
|
+
literal = rbs_ast_symbol_new(ALLOCATOR(), symbol_range, &parser->constant_pool, constant_id);
|
|
921
985
|
break;
|
|
922
986
|
}
|
|
923
987
|
case tDQSYMBOL:
|
|
924
988
|
case tSQSYMBOL: {
|
|
925
|
-
|
|
989
|
+
rbs_location_range symbol_range = rbs_location_range_current_token(parser);
|
|
926
990
|
rbs_string_t current_token = rbs_parser_peek_current_token(parser);
|
|
927
991
|
|
|
928
992
|
rbs_string_t symbol = rbs_string_new(current_token.start + offset_bytes, current_token.end);
|
|
@@ -931,7 +995,7 @@ static bool parse_symbol(rbs_parser_t *parser, rbs_location_t *location, rbs_typ
|
|
|
931
995
|
|
|
932
996
|
rbs_constant_id_t constant_id = rbs_constant_pool_insert_string(&parser->constant_pool, unquoted_symbol);
|
|
933
997
|
|
|
934
|
-
literal = rbs_ast_symbol_new(ALLOCATOR(),
|
|
998
|
+
literal = rbs_ast_symbol_new(ALLOCATOR(), symbol_range, &parser->constant_pool, constant_id);
|
|
935
999
|
break;
|
|
936
1000
|
}
|
|
937
1001
|
default:
|
|
@@ -972,6 +1036,8 @@ static bool parse_instance_type(rbs_parser_t *parser, bool parse_alias, rbs_node
|
|
|
972
1036
|
kind = INTERFACE_NAME;
|
|
973
1037
|
break;
|
|
974
1038
|
}
|
|
1039
|
+
case kSKIP:
|
|
1040
|
+
case kRETURN:
|
|
975
1041
|
case tLIDENT: {
|
|
976
1042
|
kind = ALIAS_NAME;
|
|
977
1043
|
break;
|
|
@@ -985,7 +1051,7 @@ static bool parse_instance_type(rbs_parser_t *parser, bool parse_alias, rbs_node
|
|
|
985
1051
|
if (parser->next_token.type == pLBRACKET) {
|
|
986
1052
|
rbs_parser_advance(parser);
|
|
987
1053
|
args_range.start = parser->current_token.range.start;
|
|
988
|
-
CHECK_PARSE(parse_type_list(parser, pRBRACKET, types));
|
|
1054
|
+
CHECK_PARSE(parse_type_list(parser, pRBRACKET, types, true, true, true));
|
|
989
1055
|
ADVANCE_ASSERT(parser, pRBRACKET);
|
|
990
1056
|
args_range.end = parser->current_token.range.end;
|
|
991
1057
|
} else {
|
|
@@ -997,27 +1063,30 @@ static bool parse_instance_type(rbs_parser_t *parser, bool parse_alias, rbs_node
|
|
|
997
1063
|
.end = rbs_nonnull_pos_or(args_range.end, name_range.end),
|
|
998
1064
|
};
|
|
999
1065
|
|
|
1000
|
-
|
|
1001
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 2);
|
|
1002
|
-
rbs_loc_add_required_child(loc, INTERN("name"), name_range);
|
|
1003
|
-
rbs_loc_add_optional_child(loc, INTERN("args"), args_range);
|
|
1066
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(type_range);
|
|
1004
1067
|
|
|
1005
1068
|
if (kind == CLASS_NAME) {
|
|
1006
|
-
*
|
|
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;
|
|
1007
1072
|
} else if (kind == INTERFACE_NAME) {
|
|
1008
|
-
*
|
|
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;
|
|
1009
1076
|
} else if (kind == ALIAS_NAME) {
|
|
1010
|
-
*
|
|
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;
|
|
1011
1080
|
}
|
|
1012
1081
|
|
|
1013
1082
|
return true;
|
|
1014
1083
|
}
|
|
1015
1084
|
|
|
1016
1085
|
/*
|
|
1017
|
-
singleton_type ::= {`singleton`} `(` type_name <`)`>
|
|
1086
|
+
singleton_type ::= {`singleton`} `(` type_name <`)`> type_args?
|
|
1018
1087
|
*/
|
|
1019
1088
|
NODISCARD
|
|
1020
|
-
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) {
|
|
1021
1090
|
ASSERT_TOKEN(parser, kSINGLETON);
|
|
1022
1091
|
|
|
1023
1092
|
rbs_range_t type_range;
|
|
@@ -1030,13 +1099,26 @@ static bool parse_singleton_type(rbs_parser_t *parser, rbs_types_class_singleton
|
|
|
1030
1099
|
CHECK_PARSE(parse_type_name(parser, CLASS_NAME, &name_range, &type_name));
|
|
1031
1100
|
|
|
1032
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
|
+
|
|
1033
1116
|
type_range.end = parser->current_token.range.end;
|
|
1117
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(type_range);
|
|
1034
1118
|
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
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;
|
|
1038
1121
|
|
|
1039
|
-
*singleton = rbs_types_class_singleton_new(ALLOCATOR(), loc, type_name);
|
|
1040
1122
|
return true;
|
|
1041
1123
|
}
|
|
1042
1124
|
|
|
@@ -1072,69 +1154,89 @@ static bool parser_typevar_member(rbs_parser_t *parser, rbs_constant_id_t id) {
|
|
|
1072
1154
|
| {} `^` <function>
|
|
1073
1155
|
*/
|
|
1074
1156
|
NODISCARD
|
|
1075
|
-
static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type) {
|
|
1157
|
+
static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type, bool void_allowed, bool self_allowed, bool classish_allowed) {
|
|
1076
1158
|
rbs_parser_advance(parser);
|
|
1077
1159
|
|
|
1078
1160
|
switch (parser->current_token.type) {
|
|
1079
1161
|
case pLPAREN: {
|
|
1080
1162
|
rbs_node_t *lparen_type;
|
|
1081
|
-
CHECK_PARSE(rbs_parse_type(parser, &lparen_type));
|
|
1163
|
+
CHECK_PARSE(rbs_parse_type(parser, &lparen_type, false, self_allowed, classish_allowed));
|
|
1082
1164
|
ADVANCE_ASSERT(parser, pRPAREN);
|
|
1083
1165
|
*type = lparen_type;
|
|
1084
1166
|
return true;
|
|
1085
1167
|
}
|
|
1086
1168
|
case kBOOL: {
|
|
1087
|
-
|
|
1169
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1088
1170
|
*type = (rbs_node_t *) rbs_types_bases_bool_new(ALLOCATOR(), loc);
|
|
1089
1171
|
return true;
|
|
1090
1172
|
}
|
|
1091
1173
|
case kBOT: {
|
|
1092
|
-
|
|
1174
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1093
1175
|
*type = (rbs_node_t *) rbs_types_bases_bottom_new(ALLOCATOR(), loc);
|
|
1094
1176
|
return true;
|
|
1095
1177
|
}
|
|
1096
1178
|
case kCLASS: {
|
|
1097
|
-
|
|
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);
|
|
1098
1185
|
*type = (rbs_node_t *) rbs_types_bases_class_new(ALLOCATOR(), loc);
|
|
1099
1186
|
return true;
|
|
1100
1187
|
}
|
|
1101
1188
|
case kINSTANCE: {
|
|
1102
|
-
|
|
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);
|
|
1103
1195
|
*type = (rbs_node_t *) rbs_types_bases_instance_new(ALLOCATOR(), loc);
|
|
1104
1196
|
return true;
|
|
1105
1197
|
}
|
|
1106
1198
|
case kNIL: {
|
|
1107
|
-
|
|
1199
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1108
1200
|
*type = (rbs_node_t *) rbs_types_bases_nil_new(ALLOCATOR(), loc);
|
|
1109
1201
|
return true;
|
|
1110
1202
|
}
|
|
1111
1203
|
case kSELF: {
|
|
1112
|
-
|
|
1204
|
+
if (!self_allowed) {
|
|
1205
|
+
rbs_parser_set_error(parser, parser->current_token, true, "self type is not allowed here");
|
|
1206
|
+
return false;
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1113
1210
|
*type = (rbs_node_t *) rbs_types_bases_self_new(ALLOCATOR(), loc);
|
|
1114
1211
|
return true;
|
|
1115
1212
|
}
|
|
1116
1213
|
case kTOP: {
|
|
1117
|
-
|
|
1214
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1118
1215
|
*type = (rbs_node_t *) rbs_types_bases_top_new(ALLOCATOR(), loc);
|
|
1119
1216
|
return true;
|
|
1120
1217
|
}
|
|
1121
1218
|
case kVOID: {
|
|
1122
|
-
|
|
1219
|
+
if (!void_allowed) {
|
|
1220
|
+
rbs_parser_set_error(parser, parser->current_token, true, "void type is not allowed here");
|
|
1221
|
+
return false;
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1123
1225
|
*type = (rbs_node_t *) rbs_types_bases_void_new(ALLOCATOR(), loc);
|
|
1124
1226
|
return true;
|
|
1125
1227
|
}
|
|
1126
1228
|
case kUNTYPED: {
|
|
1127
|
-
|
|
1229
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1128
1230
|
*type = (rbs_node_t *) rbs_types_bases_any_new(ALLOCATOR(), loc, false);
|
|
1129
1231
|
return true;
|
|
1130
1232
|
}
|
|
1131
1233
|
case k__TODO__: {
|
|
1132
|
-
|
|
1234
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1133
1235
|
*type = (rbs_node_t *) rbs_types_bases_any_new(ALLOCATOR(), loc, true);
|
|
1134
1236
|
return true;
|
|
1135
1237
|
}
|
|
1136
1238
|
case tINTEGER: {
|
|
1137
|
-
|
|
1239
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1138
1240
|
|
|
1139
1241
|
rbs_string_t string = rbs_parser_peek_current_token(parser);
|
|
1140
1242
|
rbs_string_t stripped_string = rbs_string_strip_whitespace(&string);
|
|
@@ -1144,18 +1246,18 @@ static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type) {
|
|
|
1144
1246
|
return true;
|
|
1145
1247
|
}
|
|
1146
1248
|
case kTRUE: {
|
|
1147
|
-
|
|
1249
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1148
1250
|
*type = (rbs_node_t *) rbs_types_literal_new(ALLOCATOR(), loc, (rbs_node_t *) rbs_ast_bool_new(ALLOCATOR(), loc, true));
|
|
1149
1251
|
return true;
|
|
1150
1252
|
}
|
|
1151
1253
|
case kFALSE: {
|
|
1152
|
-
|
|
1254
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1153
1255
|
*type = (rbs_node_t *) rbs_types_literal_new(ALLOCATOR(), loc, (rbs_node_t *) rbs_ast_bool_new(ALLOCATOR(), loc, false));
|
|
1154
1256
|
return true;
|
|
1155
1257
|
}
|
|
1156
1258
|
case tSQSTRING:
|
|
1157
1259
|
case tDQSTRING: {
|
|
1158
|
-
|
|
1260
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1159
1261
|
|
|
1160
1262
|
rbs_string_t unquoted_str = rbs_unquote_string(ALLOCATOR(), rbs_parser_peek_current_token(parser), parser->lexer->encoding);
|
|
1161
1263
|
rbs_node_t *literal = (rbs_node_t *) rbs_ast_string_new(ALLOCATOR(), loc, unquoted_str);
|
|
@@ -1165,7 +1267,7 @@ static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type) {
|
|
|
1165
1267
|
case tSYMBOL:
|
|
1166
1268
|
case tSQSYMBOL:
|
|
1167
1269
|
case tDQSYMBOL: {
|
|
1168
|
-
|
|
1270
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1169
1271
|
rbs_types_literal_t *literal = NULL;
|
|
1170
1272
|
CHECK_PARSE(parse_symbol(parser, loc, &literal));
|
|
1171
1273
|
*type = (rbs_node_t *) literal;
|
|
@@ -1178,7 +1280,7 @@ static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type) {
|
|
|
1178
1280
|
rbs_constant_id_t name = rbs_constant_pool_find(&parser->constant_pool, (const uint8_t *) name_str, name_len);
|
|
1179
1281
|
|
|
1180
1282
|
if (parser_typevar_member(parser, name)) {
|
|
1181
|
-
|
|
1283
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1182
1284
|
rbs_ast_symbol_t *symbol = rbs_ast_symbol_new(ALLOCATOR(), loc, &parser->constant_pool, name);
|
|
1183
1285
|
*type = (rbs_node_t *) rbs_types_variable_new(ALLOCATOR(), loc, symbol);
|
|
1184
1286
|
return true;
|
|
@@ -1188,6 +1290,8 @@ static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type) {
|
|
|
1188
1290
|
}
|
|
1189
1291
|
case tULIDENT:
|
|
1190
1292
|
case tLIDENT:
|
|
1293
|
+
case kSKIP:
|
|
1294
|
+
case kRETURN:
|
|
1191
1295
|
case pCOLON2: {
|
|
1192
1296
|
rbs_node_t *instance_type = NULL;
|
|
1193
1297
|
CHECK_PARSE(parse_instance_type(parser, true, &instance_type));
|
|
@@ -1196,7 +1300,7 @@ static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type) {
|
|
|
1196
1300
|
}
|
|
1197
1301
|
case kSINGLETON: {
|
|
1198
1302
|
rbs_types_class_singleton_t *singleton = NULL;
|
|
1199
|
-
CHECK_PARSE(parse_singleton_type(parser, &singleton));
|
|
1303
|
+
CHECK_PARSE(parse_singleton_type(parser, &singleton, self_allowed, classish_allowed));
|
|
1200
1304
|
*type = (rbs_node_t *) singleton;
|
|
1201
1305
|
return true;
|
|
1202
1306
|
}
|
|
@@ -1205,17 +1309,16 @@ static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type) {
|
|
|
1205
1309
|
rg.start = parser->current_token.range.start;
|
|
1206
1310
|
rbs_node_list_t *types = rbs_node_list_new(ALLOCATOR());
|
|
1207
1311
|
if (parser->next_token.type != pRBRACKET) {
|
|
1208
|
-
CHECK_PARSE(parse_type_list(parser, pRBRACKET, types));
|
|
1312
|
+
CHECK_PARSE(parse_type_list(parser, pRBRACKET, types, false, self_allowed, classish_allowed));
|
|
1209
1313
|
}
|
|
1210
1314
|
ADVANCE_ASSERT(parser, pRBRACKET);
|
|
1211
1315
|
rg.end = parser->current_token.range.end;
|
|
1212
1316
|
|
|
1213
|
-
|
|
1214
|
-
*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);
|
|
1215
1318
|
return true;
|
|
1216
1319
|
}
|
|
1217
1320
|
case pAREF_OPR: {
|
|
1218
|
-
|
|
1321
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1219
1322
|
rbs_node_list_t *types = rbs_node_list_new(ALLOCATOR());
|
|
1220
1323
|
*type = (rbs_node_t *) rbs_types_tuple_new(ALLOCATOR(), loc, types);
|
|
1221
1324
|
return true;
|
|
@@ -1223,16 +1326,16 @@ static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type) {
|
|
|
1223
1326
|
case pLBRACE: {
|
|
1224
1327
|
rbs_position_t start = parser->current_token.range.start;
|
|
1225
1328
|
rbs_hash_t *fields = NULL;
|
|
1226
|
-
CHECK_PARSE(parse_record_attributes(parser, &fields));
|
|
1329
|
+
CHECK_PARSE(parse_record_attributes(parser, &fields, self_allowed, classish_allowed));
|
|
1227
1330
|
ADVANCE_ASSERT(parser, pRBRACE);
|
|
1228
1331
|
rbs_position_t end = parser->current_token.range.end;
|
|
1229
|
-
|
|
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 };
|
|
1230
1333
|
*type = (rbs_node_t *) rbs_types_record_new(ALLOCATOR(), loc, fields);
|
|
1231
1334
|
return true;
|
|
1232
1335
|
}
|
|
1233
1336
|
case pHAT: {
|
|
1234
1337
|
rbs_types_proc_t *value = NULL;
|
|
1235
|
-
CHECK_PARSE(parse_proc_type(parser, &value));
|
|
1338
|
+
CHECK_PARSE(parse_proc_type(parser, &value, self_allowed, classish_allowed));
|
|
1236
1339
|
*type = (rbs_node_t *) value;
|
|
1237
1340
|
return true;
|
|
1238
1341
|
}
|
|
@@ -1247,29 +1350,33 @@ static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type) {
|
|
|
1247
1350
|
| {} <optional>
|
|
1248
1351
|
*/
|
|
1249
1352
|
NODISCARD
|
|
1250
|
-
static bool parse_intersection(rbs_parser_t *parser, rbs_node_t **type) {
|
|
1353
|
+
static bool parse_intersection(rbs_parser_t *parser, rbs_node_t **type, bool void_allowed, bool self_allowed, bool classish_allowed) {
|
|
1251
1354
|
rbs_range_t rg;
|
|
1252
1355
|
rg.start = parser->next_token.range.start;
|
|
1253
1356
|
|
|
1254
1357
|
rbs_node_t *optional = NULL;
|
|
1255
|
-
CHECK_PARSE(parse_optional(parser, &optional));
|
|
1358
|
+
CHECK_PARSE(parse_optional(parser, &optional, void_allowed, self_allowed, classish_allowed));
|
|
1256
1359
|
*type = optional;
|
|
1257
1360
|
|
|
1258
1361
|
rbs_node_list_t *intersection_types = rbs_node_list_new(ALLOCATOR());
|
|
1259
1362
|
|
|
1260
1363
|
rbs_node_list_append(intersection_types, optional);
|
|
1261
1364
|
while (parser->next_token.type == pAMP) {
|
|
1365
|
+
if (void_allowed && (*type)->type == RBS_TYPES_BASES_VOID) {
|
|
1366
|
+
rbs_parser_set_error(parser, parser->current_token, true, "void type is not allowed here");
|
|
1367
|
+
return false;
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1262
1370
|
rbs_parser_advance(parser);
|
|
1263
1371
|
rbs_node_t *type = NULL;
|
|
1264
|
-
CHECK_PARSE(parse_optional(parser, &type));
|
|
1372
|
+
CHECK_PARSE(parse_optional(parser, &type, false, self_allowed, classish_allowed));
|
|
1265
1373
|
rbs_node_list_append(intersection_types, type);
|
|
1266
1374
|
}
|
|
1267
1375
|
|
|
1268
1376
|
rg.end = parser->current_token.range.end;
|
|
1269
1377
|
|
|
1270
1378
|
if (intersection_types->length > 1) {
|
|
1271
|
-
|
|
1272
|
-
*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);
|
|
1273
1380
|
}
|
|
1274
1381
|
|
|
1275
1382
|
return true;
|
|
@@ -1279,27 +1386,31 @@ static bool parse_intersection(rbs_parser_t *parser, rbs_node_t **type) {
|
|
|
1279
1386
|
union ::= {} intersection '|' ... '|' <intersection>
|
|
1280
1387
|
| {} <intersection>
|
|
1281
1388
|
*/
|
|
1282
|
-
bool rbs_parse_type(rbs_parser_t *parser, rbs_node_t **type) {
|
|
1389
|
+
bool rbs_parse_type(rbs_parser_t *parser, rbs_node_t **type, bool void_allowed, bool self_allowed, bool classish_allowed) {
|
|
1283
1390
|
rbs_range_t rg;
|
|
1284
1391
|
rg.start = parser->next_token.range.start;
|
|
1285
1392
|
rbs_node_list_t *union_types = rbs_node_list_new(ALLOCATOR());
|
|
1286
1393
|
|
|
1287
|
-
CHECK_PARSE(parse_intersection(parser, type));
|
|
1394
|
+
CHECK_PARSE(parse_intersection(parser, type, void_allowed, self_allowed, classish_allowed));
|
|
1288
1395
|
|
|
1289
1396
|
rbs_node_list_append(union_types, *type);
|
|
1290
1397
|
|
|
1291
1398
|
while (parser->next_token.type == pBAR) {
|
|
1399
|
+
if (void_allowed && (*type)->type == RBS_TYPES_BASES_VOID) {
|
|
1400
|
+
rbs_parser_set_error(parser, parser->current_token, true, "void type is not allowed here");
|
|
1401
|
+
return false;
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1292
1404
|
rbs_parser_advance(parser);
|
|
1293
1405
|
rbs_node_t *intersection = NULL;
|
|
1294
|
-
CHECK_PARSE(parse_intersection(parser, &intersection));
|
|
1406
|
+
CHECK_PARSE(parse_intersection(parser, &intersection, false, self_allowed, classish_allowed));
|
|
1295
1407
|
rbs_node_list_append(union_types, intersection);
|
|
1296
1408
|
}
|
|
1297
1409
|
|
|
1298
1410
|
rg.end = parser->current_token.range.end;
|
|
1299
1411
|
|
|
1300
1412
|
if (union_types->length > 1) {
|
|
1301
|
-
|
|
1302
|
-
*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);
|
|
1303
1414
|
}
|
|
1304
1415
|
|
|
1305
1416
|
return true;
|
|
@@ -1309,9 +1420,9 @@ bool rbs_parse_type(rbs_parser_t *parser, rbs_node_t **type) {
|
|
|
1309
1420
|
type_params ::= {} `[` type_param `,` ... <`]`>
|
|
1310
1421
|
| {<>}
|
|
1311
1422
|
|
|
1312
|
-
type_param ::= kUNCHECKED? (kIN|kOUT|) tUIDENT upper_bound? default_type? (module_type_params == true)
|
|
1423
|
+
type_param ::= kUNCHECKED? (kIN|kOUT|) tUIDENT upper_bound? lower_bound? default_type? (module_type_params == true)
|
|
1313
1424
|
|
|
1314
|
-
type_param ::= tUIDENT upper_bound? default_type? (module_type_params == false)
|
|
1425
|
+
type_param ::= tUIDENT upper_bound? lower_bound? default_type? (module_type_params == false)
|
|
1315
1426
|
*/
|
|
1316
1427
|
NODISCARD
|
|
1317
1428
|
static bool parse_type_params(rbs_parser_t *parser, rbs_range_t *rg, bool module_type_params, rbs_node_list_t **params) {
|
|
@@ -1326,8 +1437,9 @@ static bool parse_type_params(rbs_parser_t *parser, rbs_range_t *rg, bool module
|
|
|
1326
1437
|
|
|
1327
1438
|
while (true) {
|
|
1328
1439
|
bool unchecked = false;
|
|
1329
|
-
|
|
1440
|
+
enum rbs_type_param_variance variance = RBS_TYPE_PARAM_VARIANCE_INVARIANT;
|
|
1330
1441
|
rbs_node_t *upper_bound = NULL;
|
|
1442
|
+
rbs_node_t *lower_bound = NULL;
|
|
1331
1443
|
rbs_node_t *default_type = NULL;
|
|
1332
1444
|
|
|
1333
1445
|
rbs_range_t param_range;
|
|
@@ -1345,10 +1457,10 @@ static bool parse_type_params(rbs_parser_t *parser, rbs_range_t *rg, bool module
|
|
|
1345
1457
|
if (parser->next_token.type == kIN || parser->next_token.type == kOUT) {
|
|
1346
1458
|
switch (parser->next_token.type) {
|
|
1347
1459
|
case kIN:
|
|
1348
|
-
variance =
|
|
1460
|
+
variance = RBS_TYPE_PARAM_VARIANCE_CONTRAVARIANT;
|
|
1349
1461
|
break;
|
|
1350
1462
|
case kOUT:
|
|
1351
|
-
variance =
|
|
1463
|
+
variance = RBS_TYPE_PARAM_VARIANCE_COVARIANT;
|
|
1352
1464
|
break;
|
|
1353
1465
|
default:
|
|
1354
1466
|
rbs_parser_set_error(parser, parser->current_token, false, "Unexpected error");
|
|
@@ -1364,18 +1476,44 @@ static bool parse_type_params(rbs_parser_t *parser, rbs_range_t *rg, bool module
|
|
|
1364
1476
|
rbs_range_t name_range = parser->current_token.range;
|
|
1365
1477
|
|
|
1366
1478
|
rbs_string_t string = rbs_parser_peek_current_token(parser);
|
|
1367
|
-
|
|
1479
|
+
rbs_location_range name_symbol_range = rbs_location_range_current_token(parser);
|
|
1368
1480
|
rbs_constant_id_t id = rbs_constant_pool_insert_string(&parser->constant_pool, string);
|
|
1369
|
-
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);
|
|
1370
1482
|
|
|
1371
1483
|
CHECK_PARSE(rbs_parser_insert_typevar(parser, id));
|
|
1372
1484
|
|
|
1373
1485
|
rbs_range_t upper_bound_range = NULL_RANGE;
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1486
|
+
rbs_range_t lower_bound_range = NULL_RANGE;
|
|
1487
|
+
|
|
1488
|
+
for (int bound_parse_attempt = 0; bound_parse_attempt < 2; bound_parse_attempt++) {
|
|
1489
|
+
switch (parser->next_token.type) {
|
|
1490
|
+
case pLT:
|
|
1491
|
+
if (upper_bound != NULL) {
|
|
1492
|
+
rbs_parser_set_error(parser, parser->next_token, true, "duplicate upper bound ('<') for type parameter");
|
|
1493
|
+
return false;
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
rbs_parser_advance(parser);
|
|
1497
|
+
upper_bound_range.start = parser->current_token.range.start;
|
|
1498
|
+
CHECK_PARSE(rbs_parse_type(parser, &upper_bound, false, false, false));
|
|
1499
|
+
upper_bound_range.end = parser->current_token.range.end;
|
|
1500
|
+
break;
|
|
1501
|
+
|
|
1502
|
+
case pGT:
|
|
1503
|
+
if (lower_bound != NULL) {
|
|
1504
|
+
rbs_parser_set_error(parser, parser->next_token, true, "duplicate lower bound ('>') for type parameter");
|
|
1505
|
+
return false;
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
rbs_parser_advance(parser);
|
|
1509
|
+
lower_bound_range.start = parser->current_token.range.start;
|
|
1510
|
+
CHECK_PARSE(rbs_parse_type(parser, &lower_bound, false, false, false));
|
|
1511
|
+
lower_bound_range.end = parser->current_token.range.end;
|
|
1512
|
+
break;
|
|
1513
|
+
|
|
1514
|
+
default:
|
|
1515
|
+
break;
|
|
1516
|
+
}
|
|
1379
1517
|
}
|
|
1380
1518
|
|
|
1381
1519
|
rbs_range_t default_type_range = NULL_RANGE;
|
|
@@ -1384,7 +1522,7 @@ static bool parse_type_params(rbs_parser_t *parser, rbs_range_t *rg, bool module
|
|
|
1384
1522
|
rbs_parser_advance(parser);
|
|
1385
1523
|
|
|
1386
1524
|
default_type_range.start = parser->current_token.range.start;
|
|
1387
|
-
CHECK_PARSE(rbs_parse_type(parser, &default_type));
|
|
1525
|
+
CHECK_PARSE(rbs_parse_type(parser, &default_type, true, false, false));
|
|
1388
1526
|
default_type_range.end = parser->current_token.range.end;
|
|
1389
1527
|
|
|
1390
1528
|
required_param_allowed = false;
|
|
@@ -1398,24 +1536,22 @@ static bool parse_type_params(rbs_parser_t *parser, rbs_range_t *rg, bool module
|
|
|
1398
1536
|
|
|
1399
1537
|
param_range.end = parser->current_token.range.end;
|
|
1400
1538
|
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
rbs_loc_add_optional_child(loc, INTERN("default"), default_type_range);
|
|
1408
|
-
|
|
1409
|
-
rbs_ast_type_param_t *param = rbs_ast_type_param_new(ALLOCATOR(), loc, name, variance, upper_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);
|
|
1410
1545
|
|
|
1411
1546
|
rbs_node_list_append(*params, (rbs_node_t *) param);
|
|
1412
1547
|
|
|
1413
1548
|
if (parser->next_token.type == pCOMMA) {
|
|
1414
1549
|
rbs_parser_advance(parser);
|
|
1415
|
-
}
|
|
1416
|
-
|
|
1417
|
-
if (parser->next_token.type == pRBRACKET) {
|
|
1550
|
+
} else if (parser->next_token.type == pRBRACKET) {
|
|
1418
1551
|
break;
|
|
1552
|
+
} else {
|
|
1553
|
+
rbs_parser_set_error(parser, parser->next_token, true, "expected ',' or ']' after type parameter, got %s", rbs_token_type_str(parser->next_token.type));
|
|
1554
|
+
return false;
|
|
1419
1555
|
}
|
|
1420
1556
|
}
|
|
1421
1557
|
|
|
@@ -1452,7 +1588,7 @@ static bool parser_pop_typevar_table(rbs_parser_t *parser) {
|
|
|
1452
1588
|
method_type ::= {} type_params <function>
|
|
1453
1589
|
*/
|
|
1454
1590
|
// TODO: Should this be NODISCARD?
|
|
1455
|
-
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) {
|
|
1456
1592
|
rbs_parser_push_typevar_table(parser, false);
|
|
1457
1593
|
|
|
1458
1594
|
rbs_range_t rg;
|
|
@@ -1466,7 +1602,7 @@ bool rbs_parse_method_type(rbs_parser_t *parser, rbs_method_type_t **method_type
|
|
|
1466
1602
|
type_range.start = parser->next_token.range.start;
|
|
1467
1603
|
|
|
1468
1604
|
parse_function_result *result = rbs_allocator_alloc(ALLOCATOR(), parse_function_result);
|
|
1469
|
-
CHECK_PARSE(parse_function(parser, false, &result));
|
|
1605
|
+
CHECK_PARSE(parse_function(parser, false, true, &result, true, classish_allowed));
|
|
1470
1606
|
|
|
1471
1607
|
CHECK_PARSE(parser_pop_typevar_table(parser));
|
|
1472
1608
|
|
|
@@ -1481,12 +1617,9 @@ bool rbs_parse_method_type(rbs_parser_t *parser, rbs_method_type_t **method_type
|
|
|
1481
1617
|
}
|
|
1482
1618
|
}
|
|
1483
1619
|
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
rbs_loc_add_required_child(loc, INTERN("type"), type_range);
|
|
1487
|
-
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);
|
|
1488
1622
|
|
|
1489
|
-
*method_type = rbs_method_type_new(ALLOCATOR(), loc, type_params, result->function, result->block);
|
|
1490
1623
|
return true;
|
|
1491
1624
|
}
|
|
1492
1625
|
|
|
@@ -1501,23 +1634,17 @@ static bool parse_global_decl(rbs_parser_t *parser, rbs_node_list_t *annotations
|
|
|
1501
1634
|
rbs_ast_comment_t *comment = rbs_parser_get_comment(parser, decl_range.start.line);
|
|
1502
1635
|
|
|
1503
1636
|
rbs_range_t name_range = parser->current_token.range;
|
|
1504
|
-
rbs_location_t *symbolLoc = rbs_location_new(ALLOCATOR(), name_range);
|
|
1505
1637
|
|
|
1506
|
-
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));
|
|
1507
1639
|
|
|
1508
1640
|
ADVANCE_ASSERT(parser, pCOLON);
|
|
1509
1641
|
rbs_range_t colon_range = parser->current_token.range;
|
|
1510
1642
|
|
|
1511
1643
|
rbs_node_t *type;
|
|
1512
|
-
CHECK_PARSE(rbs_parse_type(parser, &type));
|
|
1644
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, false, false, false));
|
|
1513
1645
|
decl_range.end = parser->current_token.range.end;
|
|
1514
1646
|
|
|
1515
|
-
|
|
1516
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 2);
|
|
1517
|
-
rbs_loc_add_required_child(loc, INTERN("name"), name_range);
|
|
1518
|
-
rbs_loc_add_required_child(loc, INTERN("colon"), colon_range);
|
|
1519
|
-
|
|
1520
|
-
*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));
|
|
1521
1648
|
return true;
|
|
1522
1649
|
}
|
|
1523
1650
|
|
|
@@ -1539,16 +1666,11 @@ static bool parse_const_decl(rbs_parser_t *parser, rbs_node_list_t *annotations,
|
|
|
1539
1666
|
rbs_range_t colon_range = parser->current_token.range;
|
|
1540
1667
|
|
|
1541
1668
|
rbs_node_t *type;
|
|
1542
|
-
CHECK_PARSE(rbs_parse_type(parser, &type));
|
|
1669
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, false, false, false));
|
|
1543
1670
|
|
|
1544
1671
|
decl_range.end = parser->current_token.range.end;
|
|
1545
1672
|
|
|
1546
|
-
|
|
1547
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 2);
|
|
1548
|
-
rbs_loc_add_required_child(loc, INTERN("name"), name_range);
|
|
1549
|
-
rbs_loc_add_required_child(loc, INTERN("colon"), colon_range);
|
|
1550
|
-
|
|
1551
|
-
*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));
|
|
1552
1674
|
return true;
|
|
1553
1675
|
}
|
|
1554
1676
|
|
|
@@ -1579,22 +1701,16 @@ static bool parse_type_decl(rbs_parser_t *parser, rbs_position_t comment_pos, rb
|
|
|
1579
1701
|
rbs_range_t eq_range = parser->current_token.range;
|
|
1580
1702
|
|
|
1581
1703
|
rbs_node_t *type;
|
|
1582
|
-
CHECK_PARSE(rbs_parse_type(parser, &type));
|
|
1704
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, false, false, false));
|
|
1583
1705
|
|
|
1584
1706
|
decl_range.end = parser->current_token.range.end;
|
|
1585
1707
|
|
|
1586
|
-
rbs_location_t *loc = rbs_location_new(ALLOCATOR(), decl_range);
|
|
1587
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 4);
|
|
1588
|
-
rbs_loc_add_required_child(loc, INTERN("keyword"), keyword_range);
|
|
1589
|
-
rbs_loc_add_required_child(loc, INTERN("name"), name_range);
|
|
1590
|
-
rbs_loc_add_optional_child(loc, INTERN("type_params"), params_range);
|
|
1591
|
-
rbs_loc_add_required_child(loc, INTERN("eq"), eq_range);
|
|
1592
|
-
|
|
1593
1708
|
CHECK_PARSE(parser_pop_typevar_table(parser));
|
|
1594
1709
|
|
|
1595
1710
|
rbs_ast_comment_t *comment = rbs_parser_get_comment(parser, comment_pos.line);
|
|
1596
1711
|
|
|
1597
|
-
*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);
|
|
1598
1714
|
return true;
|
|
1599
1715
|
}
|
|
1600
1716
|
|
|
@@ -1653,7 +1769,7 @@ static bool parse_annotation(rbs_parser_t *parser, rbs_ast_annotation_t **annota
|
|
|
1653
1769
|
|
|
1654
1770
|
rbs_string_t stripped_annotation_str = rbs_string_strip_whitespace(&annotation_str);
|
|
1655
1771
|
|
|
1656
|
-
*annotation = rbs_ast_annotation_new(ALLOCATOR(),
|
|
1772
|
+
*annotation = rbs_ast_annotation_new(ALLOCATOR(), RBS_RANGE_LEX2AST(rg), stripped_annotation_str);
|
|
1657
1773
|
return true;
|
|
1658
1774
|
}
|
|
1659
1775
|
|
|
@@ -1710,28 +1826,24 @@ static bool parse_method_name(rbs_parser_t *parser, rbs_range_t *range, rbs_ast_
|
|
|
1710
1826
|
parser->lexer->encoding
|
|
1711
1827
|
);
|
|
1712
1828
|
|
|
1713
|
-
|
|
1714
|
-
*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);
|
|
1715
1830
|
} else {
|
|
1716
1831
|
*range = parser->current_token.range;
|
|
1717
|
-
|
|
1718
|
-
*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));
|
|
1719
1833
|
}
|
|
1720
1834
|
return true;
|
|
1721
1835
|
|
|
1722
1836
|
case tBANGIDENT:
|
|
1723
1837
|
case tEQIDENT: {
|
|
1724
1838
|
*range = parser->current_token.range;
|
|
1725
|
-
|
|
1726
|
-
*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));
|
|
1727
1840
|
return true;
|
|
1728
1841
|
}
|
|
1729
1842
|
case tQIDENT: {
|
|
1730
1843
|
rbs_string_t string = rbs_parser_peek_current_token(parser);
|
|
1731
1844
|
rbs_string_t unquoted_str = rbs_unquote_string(ALLOCATOR(), string, parser->lexer->encoding);
|
|
1732
1845
|
rbs_constant_id_t constant_id = rbs_constant_pool_insert_string(&parser->constant_pool, unquoted_str);
|
|
1733
|
-
|
|
1734
|
-
*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);
|
|
1735
1847
|
return true;
|
|
1736
1848
|
}
|
|
1737
1849
|
|
|
@@ -1741,11 +1853,11 @@ static bool parse_method_name(rbs_parser_t *parser, rbs_range_t *range, rbs_ast_
|
|
|
1741
1853
|
case pSTAR:
|
|
1742
1854
|
case pSTAR2:
|
|
1743
1855
|
case pLT:
|
|
1856
|
+
case pGT:
|
|
1744
1857
|
case pAREF_OPR:
|
|
1745
1858
|
case tOPERATOR: {
|
|
1746
1859
|
*range = parser->current_token.range;
|
|
1747
|
-
|
|
1748
|
-
*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));
|
|
1749
1861
|
return true;
|
|
1750
1862
|
}
|
|
1751
1863
|
|
|
@@ -1819,25 +1931,25 @@ static bool parse_member_def(rbs_parser_t *parser, bool instance_only, bool acce
|
|
|
1819
1931
|
rbs_ast_comment_t *comment = rbs_parser_get_comment(parser, comment_pos.line);
|
|
1820
1932
|
|
|
1821
1933
|
rbs_range_t visibility_range;
|
|
1822
|
-
|
|
1934
|
+
enum rbs_method_definition_visibility visibility;
|
|
1823
1935
|
switch (parser->current_token.type) {
|
|
1824
1936
|
case kPRIVATE: {
|
|
1825
1937
|
visibility_range = parser->current_token.range;
|
|
1826
|
-
visibility =
|
|
1938
|
+
visibility = RBS_METHOD_DEFINITION_VISIBILITY_PRIVATE;
|
|
1827
1939
|
member_range.start = visibility_range.start;
|
|
1828
1940
|
rbs_parser_advance(parser);
|
|
1829
1941
|
break;
|
|
1830
1942
|
}
|
|
1831
1943
|
case kPUBLIC: {
|
|
1832
1944
|
visibility_range = parser->current_token.range;
|
|
1833
|
-
visibility =
|
|
1945
|
+
visibility = RBS_METHOD_DEFINITION_VISIBILITY_PUBLIC;
|
|
1834
1946
|
member_range.start = visibility_range.start;
|
|
1835
1947
|
rbs_parser_advance(parser);
|
|
1836
1948
|
break;
|
|
1837
1949
|
}
|
|
1838
1950
|
default:
|
|
1839
1951
|
visibility_range = NULL_RANGE;
|
|
1840
|
-
visibility =
|
|
1952
|
+
visibility = RBS_METHOD_DEFINITION_VISIBILITY_UNSPECIFIED;
|
|
1841
1953
|
break;
|
|
1842
1954
|
}
|
|
1843
1955
|
|
|
@@ -1849,7 +1961,7 @@ static bool parse_member_def(rbs_parser_t *parser, bool instance_only, bool acce
|
|
|
1849
1961
|
kind_range = NULL_RANGE;
|
|
1850
1962
|
kind = INSTANCE_KIND;
|
|
1851
1963
|
} else {
|
|
1852
|
-
kind = parse_instance_singleton_kind(parser, visibility ==
|
|
1964
|
+
kind = parse_instance_singleton_kind(parser, visibility == RBS_METHOD_DEFINITION_VISIBILITY_UNSPECIFIED, &kind_range);
|
|
1853
1965
|
}
|
|
1854
1966
|
|
|
1855
1967
|
rbs_range_t name_range;
|
|
@@ -1889,11 +2001,10 @@ static bool parse_member_def(rbs_parser_t *parser, bool instance_only, bool acce
|
|
|
1889
2001
|
case pLBRACKET:
|
|
1890
2002
|
case pQUESTION: {
|
|
1891
2003
|
rbs_method_type_t *method_type = NULL;
|
|
1892
|
-
CHECK_PARSE(rbs_parse_method_type(parser, &method_type, false));
|
|
2004
|
+
CHECK_PARSE(rbs_parse_method_type(parser, &method_type, false, !instance_only));
|
|
1893
2005
|
|
|
1894
2006
|
overload_range.end = parser->current_token.range.end;
|
|
1895
|
-
|
|
1896
|
-
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);
|
|
1897
2008
|
rbs_node_list_append(overloads, overload);
|
|
1898
2009
|
member_range.end = parser->current_token.range.end;
|
|
1899
2010
|
break;
|
|
@@ -1926,18 +2037,18 @@ static bool parse_member_def(rbs_parser_t *parser, bool instance_only, bool acce
|
|
|
1926
2037
|
|
|
1927
2038
|
CHECK_PARSE(parser_pop_typevar_table(parser));
|
|
1928
2039
|
|
|
1929
|
-
|
|
2040
|
+
enum rbs_method_definition_kind k;
|
|
1930
2041
|
switch (kind) {
|
|
1931
2042
|
case INSTANCE_KIND: {
|
|
1932
|
-
k =
|
|
2043
|
+
k = RBS_METHOD_DEFINITION_KIND_INSTANCE;
|
|
1933
2044
|
break;
|
|
1934
2045
|
}
|
|
1935
2046
|
case SINGLETON_KIND: {
|
|
1936
|
-
k =
|
|
2047
|
+
k = RBS_METHOD_DEFINITION_KIND_SINGLETON;
|
|
1937
2048
|
break;
|
|
1938
2049
|
}
|
|
1939
2050
|
case INSTANCE_SINGLETON_KIND: {
|
|
1940
|
-
k =
|
|
2051
|
+
k = RBS_METHOD_DEFINITION_KIND_SINGLETON_INSTANCE;
|
|
1941
2052
|
break;
|
|
1942
2053
|
}
|
|
1943
2054
|
default:
|
|
@@ -1945,15 +2056,11 @@ static bool parse_member_def(rbs_parser_t *parser, bool instance_only, bool acce
|
|
|
1945
2056
|
return false;
|
|
1946
2057
|
}
|
|
1947
2058
|
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
rbs_loc_add_optional_child(loc, INTERN("kind"), kind_range);
|
|
1953
|
-
rbs_loc_add_optional_child(loc, INTERN("overloading"), overloading_range);
|
|
1954
|
-
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);
|
|
1955
2063
|
|
|
1956
|
-
*method_definition = rbs_ast_members_method_definition_new(ALLOCATOR(), loc, name, k, overloads, annotations, comment, overloading, visibility);
|
|
1957
2064
|
return true;
|
|
1958
2065
|
}
|
|
1959
2066
|
|
|
@@ -1964,7 +2071,7 @@ static bool parse_member_def(rbs_parser_t *parser, bool instance_only, bool acce
|
|
|
1964
2071
|
* @param kind
|
|
1965
2072
|
* */
|
|
1966
2073
|
NODISCARD
|
|
1967
|
-
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) {
|
|
1968
2075
|
rbs_parser_advance(parser);
|
|
1969
2076
|
|
|
1970
2077
|
rbs_type_name_t *type_name = NULL;
|
|
@@ -1974,7 +2081,7 @@ static bool class_instance_name(rbs_parser_t *parser, TypeNameKind kind, rbs_nod
|
|
|
1974
2081
|
if (parser->next_token.type == pLBRACKET) {
|
|
1975
2082
|
rbs_parser_advance(parser);
|
|
1976
2083
|
args_range->start = parser->current_token.range.start;
|
|
1977
|
-
CHECK_PARSE(parse_type_list(parser, pRBRACKET, args));
|
|
2084
|
+
CHECK_PARSE(parse_type_list(parser, pRBRACKET, args, true, false, classish_allowed));
|
|
1978
2085
|
ADVANCE_ASSERT(parser, pRBRACKET);
|
|
1979
2086
|
args_range->end = parser->current_token.range.end;
|
|
1980
2087
|
} else {
|
|
@@ -2035,30 +2142,39 @@ static bool parse_mixin_member(rbs_parser_t *parser, bool from_interface, rbs_po
|
|
|
2035
2142
|
args,
|
|
2036
2143
|
&name_range,
|
|
2037
2144
|
&args_range,
|
|
2038
|
-
&name
|
|
2145
|
+
&name,
|
|
2146
|
+
!from_interface
|
|
2039
2147
|
));
|
|
2040
2148
|
|
|
2041
2149
|
CHECK_PARSE(parser_pop_typevar_table(parser));
|
|
2042
2150
|
|
|
2043
2151
|
member_range.end = parser->current_token.range.end;
|
|
2044
2152
|
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
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);
|
|
2050
2157
|
|
|
2051
2158
|
rbs_ast_comment_t *comment = rbs_parser_get_comment(parser, comment_pos.line);
|
|
2052
2159
|
switch (type) {
|
|
2053
|
-
case kINCLUDE:
|
|
2054
|
-
*
|
|
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;
|
|
2055
2164
|
return true;
|
|
2056
|
-
|
|
2057
|
-
|
|
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;
|
|
2058
2170
|
return true;
|
|
2059
|
-
|
|
2060
|
-
|
|
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;
|
|
2061
2176
|
return true;
|
|
2177
|
+
}
|
|
2062
2178
|
default:
|
|
2063
2179
|
rbs_parser_set_error(parser, parser->current_token, false, "Unexpected error");
|
|
2064
2180
|
return false;
|
|
@@ -2082,12 +2198,12 @@ static bool parse_alias_member(rbs_parser_t *parser, bool instance_only, rbs_pos
|
|
|
2082
2198
|
comment_pos = rbs_nonnull_pos_or(comment_pos, member_range.start);
|
|
2083
2199
|
rbs_ast_comment_t *comment = rbs_parser_get_comment(parser, comment_pos.line);
|
|
2084
2200
|
|
|
2085
|
-
|
|
2201
|
+
enum rbs_alias_kind kind;
|
|
2086
2202
|
rbs_ast_symbol_t *new_name, *old_name;
|
|
2087
2203
|
rbs_range_t new_kind_range, old_kind_range, new_name_range, old_name_range;
|
|
2088
2204
|
|
|
2089
2205
|
if (!instance_only && parser->next_token.type == kSELF) {
|
|
2090
|
-
kind =
|
|
2206
|
+
kind = RBS_ALIAS_KIND_SINGLETON;
|
|
2091
2207
|
|
|
2092
2208
|
new_kind_range.start = parser->next_token.range.start;
|
|
2093
2209
|
new_kind_range.end = parser->next_token2.range.end;
|
|
@@ -2101,7 +2217,7 @@ static bool parse_alias_member(rbs_parser_t *parser, bool instance_only, rbs_pos
|
|
|
2101
2217
|
ADVANCE_ASSERT(parser, pDOT);
|
|
2102
2218
|
CHECK_PARSE(parse_method_name(parser, &old_name_range, &old_name));
|
|
2103
2219
|
} else {
|
|
2104
|
-
kind =
|
|
2220
|
+
kind = RBS_ALIAS_KIND_INSTANCE;
|
|
2105
2221
|
CHECK_PARSE(parse_method_name(parser, &new_name_range, &new_name));
|
|
2106
2222
|
CHECK_PARSE(parse_method_name(parser, &old_name_range, &old_name));
|
|
2107
2223
|
new_kind_range = NULL_RANGE;
|
|
@@ -2109,15 +2225,13 @@ static bool parse_alias_member(rbs_parser_t *parser, bool instance_only, rbs_pos
|
|
|
2109
2225
|
}
|
|
2110
2226
|
|
|
2111
2227
|
member_range.end = parser->current_token.range.end;
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
*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
|
+
|
|
2121
2235
|
return true;
|
|
2122
2236
|
}
|
|
2123
2237
|
|
|
@@ -2139,31 +2253,29 @@ static bool parse_variable_member(rbs_parser_t *parser, rbs_position_t comment_p
|
|
|
2139
2253
|
rbs_ast_comment_t *comment = rbs_parser_get_comment(parser, comment_pos.line);
|
|
2140
2254
|
|
|
2141
2255
|
switch (parser->current_token.type) {
|
|
2142
|
-
case tAIDENT:
|
|
2256
|
+
case tAIDENT:
|
|
2257
|
+
case kATRBS: {
|
|
2143
2258
|
rbs_range_t name_range = parser->current_token.range;
|
|
2144
|
-
|
|
2259
|
+
rbs_location_range symbolLoc = RBS_RANGE_LEX2AST(name_range);
|
|
2145
2260
|
rbs_ast_symbol_t *name = rbs_ast_symbol_new(ALLOCATOR(), symbolLoc, &parser->constant_pool, INTERN_TOKEN(parser, parser->current_token));
|
|
2146
2261
|
|
|
2147
2262
|
ADVANCE_ASSERT(parser, pCOLON);
|
|
2148
2263
|
rbs_range_t colon_range = parser->current_token.range;
|
|
2149
2264
|
|
|
2150
2265
|
rbs_node_t *type;
|
|
2151
|
-
CHECK_PARSE(rbs_parse_type(parser, &type));
|
|
2266
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, false, true, true));
|
|
2152
2267
|
member_range.end = parser->current_token.range.end;
|
|
2153
2268
|
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
rbs_loc_add_required_child(loc, INTERN("colon"), colon_range);
|
|
2158
|
-
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));
|
|
2159
2272
|
|
|
2160
|
-
*variable_member = (rbs_node_t *) rbs_ast_members_instance_variable_new(ALLOCATOR(), loc, name, type, comment);
|
|
2161
2273
|
return true;
|
|
2162
2274
|
}
|
|
2163
2275
|
case tA2IDENT: {
|
|
2164
2276
|
rbs_range_t name_range = parser->current_token.range;
|
|
2165
|
-
|
|
2166
|
-
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));
|
|
2167
2279
|
|
|
2168
2280
|
ADVANCE_ASSERT(parser, pCOLON);
|
|
2169
2281
|
rbs_range_t colon_range = parser->current_token.range;
|
|
@@ -2171,19 +2283,16 @@ static bool parse_variable_member(rbs_parser_t *parser, rbs_position_t comment_p
|
|
|
2171
2283
|
rbs_parser_push_typevar_table(parser, true);
|
|
2172
2284
|
|
|
2173
2285
|
rbs_node_t *type;
|
|
2174
|
-
CHECK_PARSE(rbs_parse_type(parser, &type));
|
|
2286
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, false, false, true));
|
|
2175
2287
|
|
|
2176
2288
|
CHECK_PARSE(parser_pop_typevar_table(parser));
|
|
2177
2289
|
|
|
2178
2290
|
member_range.end = parser->current_token.range.end;
|
|
2179
2291
|
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
rbs_loc_add_required_child(loc, INTERN("colon"), colon_range);
|
|
2184
|
-
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));
|
|
2185
2295
|
|
|
2186
|
-
*variable_member = (rbs_node_t *) rbs_ast_members_class_variable_new(ALLOCATOR(), loc, name, type, comment);
|
|
2187
2296
|
return true;
|
|
2188
2297
|
}
|
|
2189
2298
|
case kSELF: {
|
|
@@ -2193,7 +2302,7 @@ static bool parse_variable_member(rbs_parser_t *parser, rbs_position_t comment_p
|
|
|
2193
2302
|
};
|
|
2194
2303
|
|
|
2195
2304
|
ADVANCE_ASSERT(parser, pDOT);
|
|
2196
|
-
if (parser->next_token.type == tAIDENT) {
|
|
2305
|
+
if (parser->next_token.type == tAIDENT || parser->next_token.type == kATRBS) {
|
|
2197
2306
|
rbs_parser_advance(parser);
|
|
2198
2307
|
} else {
|
|
2199
2308
|
rbs_parser_set_error(parser, parser->current_token, false, "Unexpected error");
|
|
@@ -2201,8 +2310,8 @@ static bool parse_variable_member(rbs_parser_t *parser, rbs_position_t comment_p
|
|
|
2201
2310
|
}
|
|
2202
2311
|
|
|
2203
2312
|
rbs_range_t name_range = parser->current_token.range;
|
|
2204
|
-
|
|
2205
|
-
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));
|
|
2206
2315
|
|
|
2207
2316
|
ADVANCE_ASSERT(parser, pCOLON);
|
|
2208
2317
|
rbs_range_t colon_range = parser->current_token.range;
|
|
@@ -2210,19 +2319,19 @@ static bool parse_variable_member(rbs_parser_t *parser, rbs_position_t comment_p
|
|
|
2210
2319
|
rbs_parser_push_typevar_table(parser, true);
|
|
2211
2320
|
|
|
2212
2321
|
rbs_node_t *type;
|
|
2213
|
-
CHECK_PARSE(rbs_parse_type(parser, &type));
|
|
2322
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, false, true, true));
|
|
2214
2323
|
|
|
2215
2324
|
CHECK_PARSE(parser_pop_typevar_table(parser));
|
|
2216
2325
|
|
|
2217
2326
|
member_range.end = parser->current_token.range.end;
|
|
2218
2327
|
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
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;
|
|
2224
2334
|
|
|
2225
|
-
*variable_member = (rbs_node_t *) rbs_ast_members_class_instance_variable_new(ALLOCATOR(), loc, name, type, comment);
|
|
2226
2335
|
return true;
|
|
2227
2336
|
}
|
|
2228
2337
|
default:
|
|
@@ -2242,7 +2351,7 @@ static bool parse_visibility_member(rbs_parser_t *parser, rbs_node_list_t *annot
|
|
|
2242
2351
|
return false;
|
|
2243
2352
|
}
|
|
2244
2353
|
|
|
2245
|
-
|
|
2354
|
+
rbs_location_range location = rbs_location_range_current_token(parser);
|
|
2246
2355
|
|
|
2247
2356
|
switch (parser->current_token.type) {
|
|
2248
2357
|
case kPUBLIC: {
|
|
@@ -2282,22 +2391,23 @@ static bool parse_attribute_member(rbs_parser_t *parser, rbs_position_t comment_
|
|
|
2282
2391
|
rbs_ast_comment_t *comment = rbs_parser_get_comment(parser, comment_pos.line);
|
|
2283
2392
|
|
|
2284
2393
|
rbs_range_t visibility_range;
|
|
2285
|
-
|
|
2394
|
+
enum rbs_attribute_visibility visibility;
|
|
2395
|
+
|
|
2286
2396
|
switch (parser->current_token.type) {
|
|
2287
2397
|
case kPRIVATE: {
|
|
2288
2398
|
visibility_range = parser->current_token.range;
|
|
2289
|
-
visibility =
|
|
2399
|
+
visibility = RBS_ATTRIBUTE_VISIBILITY_PRIVATE;
|
|
2290
2400
|
rbs_parser_advance(parser);
|
|
2291
2401
|
break;
|
|
2292
2402
|
}
|
|
2293
2403
|
case kPUBLIC: {
|
|
2294
2404
|
visibility_range = parser->current_token.range;
|
|
2295
|
-
visibility =
|
|
2405
|
+
visibility = RBS_ATTRIBUTE_VISIBILITY_PUBLIC;
|
|
2296
2406
|
rbs_parser_advance(parser);
|
|
2297
2407
|
break;
|
|
2298
2408
|
}
|
|
2299
2409
|
default:
|
|
2300
|
-
visibility =
|
|
2410
|
+
visibility = RBS_ATTRIBUTE_VISIBILITY_UNSPECIFIED;
|
|
2301
2411
|
visibility_range = NULL_RANGE;
|
|
2302
2412
|
break;
|
|
2303
2413
|
}
|
|
@@ -2308,41 +2418,31 @@ static bool parse_attribute_member(rbs_parser_t *parser, rbs_position_t comment_
|
|
|
2308
2418
|
rbs_range_t kind_range;
|
|
2309
2419
|
InstanceSingletonKind is_kind = parse_instance_singleton_kind(parser, false, &kind_range);
|
|
2310
2420
|
|
|
2311
|
-
|
|
2312
|
-
ALLOCATOR(),
|
|
2313
|
-
rbs_location_new(ALLOCATOR(), keyword_range),
|
|
2314
|
-
INTERN(((is_kind == INSTANCE_KIND) ? "instance" : "singleton"))
|
|
2315
|
-
);
|
|
2421
|
+
enum rbs_attribute_kind kind = (is_kind == INSTANCE_KIND) ? RBS_ATTRIBUTE_KIND_INSTANCE : RBS_ATTRIBUTE_KIND_SINGLETON;
|
|
2316
2422
|
|
|
2317
2423
|
rbs_range_t name_range;
|
|
2318
2424
|
rbs_ast_symbol_t *attr_name;
|
|
2319
2425
|
CHECK_PARSE(parse_method_name(parser, &name_range, &attr_name));
|
|
2320
2426
|
|
|
2321
|
-
|
|
2322
|
-
|
|
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;
|
|
2323
2430
|
if (parser->next_token.type == pLPAREN) {
|
|
2324
2431
|
ADVANCE_ASSERT(parser, pLPAREN);
|
|
2325
|
-
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;
|
|
2326
2434
|
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
.start = parser->current_token.range.start,
|
|
2334
|
-
.end = parser->current_token.range.end
|
|
2335
|
-
};
|
|
2336
|
-
ivar_name = (rbs_node_t *) rbs_ast_bool_new(ALLOCATOR(), rbs_location_new(ALLOCATOR(), false_range), false);
|
|
2337
|
-
ivar_name_range = NULL_RANGE;
|
|
2435
|
+
ivar_name.tag = RBS_ATTR_IVAR_NAME_TAG_EMPTY;
|
|
2436
|
+
|
|
2437
|
+
if (parser_advance_if(parser, tAIDENT) || parser_advance_if(parser, kATRBS)) {
|
|
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);
|
|
2338
2441
|
}
|
|
2339
2442
|
|
|
2340
2443
|
ADVANCE_ASSERT(parser, pRPAREN);
|
|
2341
|
-
ivar_range.
|
|
2342
|
-
|
|
2343
|
-
ivar_range = NULL_RANGE;
|
|
2344
|
-
ivar_name = NULL;
|
|
2345
|
-
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;
|
|
2346
2446
|
}
|
|
2347
2447
|
|
|
2348
2448
|
ADVANCE_ASSERT(parser, pCOLON);
|
|
@@ -2351,32 +2451,53 @@ static bool parse_attribute_member(rbs_parser_t *parser, rbs_position_t comment_
|
|
|
2351
2451
|
rbs_parser_push_typevar_table(parser, is_kind == SINGLETON_KIND);
|
|
2352
2452
|
|
|
2353
2453
|
rbs_node_t *type;
|
|
2354
|
-
CHECK_PARSE(rbs_parse_type(parser, &type));
|
|
2454
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, false, true, true));
|
|
2355
2455
|
|
|
2356
2456
|
CHECK_PARSE(parser_pop_typevar_table(parser));
|
|
2357
2457
|
|
|
2358
2458
|
member_range.end = parser->current_token.range.end;
|
|
2359
2459
|
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
rbs_loc_add_optional_child(loc, INTERN("ivar"), ivar_range);
|
|
2367
|
-
rbs_loc_add_optional_child(loc, INTERN("ivar_name"), ivar_name_range);
|
|
2368
|
-
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);
|
|
2369
2466
|
|
|
2370
2467
|
switch (attr_type) {
|
|
2371
|
-
case kATTRREADER:
|
|
2372
|
-
*
|
|
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
|
+
|
|
2373
2477
|
return true;
|
|
2374
|
-
|
|
2375
|
-
|
|
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
|
+
|
|
2376
2488
|
return true;
|
|
2377
|
-
|
|
2378
|
-
|
|
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
|
+
|
|
2379
2499
|
return true;
|
|
2500
|
+
}
|
|
2380
2501
|
default:
|
|
2381
2502
|
rbs_parser_set_error(parser, parser->current_token, false, "Unexpected error");
|
|
2382
2503
|
return false;
|
|
@@ -2467,16 +2588,12 @@ static bool parse_interface_decl(rbs_parser_t *parser, rbs_position_t comment_po
|
|
|
2467
2588
|
|
|
2468
2589
|
CHECK_PARSE(parser_pop_typevar_table(parser));
|
|
2469
2590
|
|
|
2470
|
-
|
|
2471
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 4);
|
|
2472
|
-
rbs_loc_add_required_child(loc, INTERN("keyword"), keyword_range);
|
|
2473
|
-
rbs_loc_add_required_child(loc, INTERN("name"), name_range);
|
|
2474
|
-
rbs_loc_add_required_child(loc, INTERN("end"), end_range);
|
|
2475
|
-
rbs_loc_add_optional_child(loc, INTERN("type_params"), type_params_range);
|
|
2476
|
-
|
|
2591
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(member_range);
|
|
2477
2592
|
rbs_ast_comment_t *comment = rbs_parser_get_comment(parser, comment_pos.line);
|
|
2478
2593
|
|
|
2479
|
-
*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
|
+
|
|
2480
2597
|
return true;
|
|
2481
2598
|
}
|
|
2482
2599
|
|
|
@@ -2504,17 +2621,15 @@ static bool parse_module_self_types(rbs_parser_t *parser, rbs_node_list_t *array
|
|
|
2504
2621
|
if (parser->next_token.type == pLBRACKET) {
|
|
2505
2622
|
rbs_parser_advance(parser);
|
|
2506
2623
|
args_range.start = parser->current_token.range.start;
|
|
2507
|
-
CHECK_PARSE(parse_type_list(parser, pRBRACKET, args));
|
|
2624
|
+
CHECK_PARSE(parse_type_list(parser, pRBRACKET, args, true, false, false));
|
|
2508
2625
|
rbs_parser_advance(parser);
|
|
2509
2626
|
self_range.end = args_range.end = parser->current_token.range.end;
|
|
2510
2627
|
}
|
|
2511
2628
|
|
|
2512
|
-
|
|
2513
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 2);
|
|
2514
|
-
rbs_loc_add_required_child(loc, INTERN("name"), name_range);
|
|
2515
|
-
rbs_loc_add_optional_child(loc, INTERN("args"), args_range);
|
|
2629
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(self_range);
|
|
2516
2630
|
|
|
2517
|
-
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);
|
|
2518
2633
|
rbs_node_list_append(array, (rbs_node_t *) self_type);
|
|
2519
2634
|
|
|
2520
2635
|
if (parser->next_token.type == pCOMMA) {
|
|
@@ -2575,6 +2690,7 @@ static bool parse_module_members(rbs_parser_t *parser, rbs_node_list_t **members
|
|
|
2575
2690
|
}
|
|
2576
2691
|
case tAIDENT:
|
|
2577
2692
|
case tA2IDENT:
|
|
2693
|
+
case kATRBS:
|
|
2578
2694
|
case kSELF: {
|
|
2579
2695
|
CHECK_PARSE(parse_variable_member(parser, annot_pos, annotations, &member));
|
|
2580
2696
|
break;
|
|
@@ -2659,18 +2775,14 @@ static bool parse_module_decl0(rbs_parser_t *parser, rbs_range_t keyword_range,
|
|
|
2659
2775
|
rbs_range_t end_range = parser->current_token.range;
|
|
2660
2776
|
decl_range.end = parser->current_token.range.end;
|
|
2661
2777
|
|
|
2662
|
-
rbs_location_t *loc = rbs_location_new(ALLOCATOR(), decl_range);
|
|
2663
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 6);
|
|
2664
|
-
rbs_loc_add_required_child(loc, INTERN("keyword"), keyword_range);
|
|
2665
|
-
rbs_loc_add_required_child(loc, INTERN("name"), name_range);
|
|
2666
|
-
rbs_loc_add_required_child(loc, INTERN("end"), end_range);
|
|
2667
|
-
rbs_loc_add_optional_child(loc, INTERN("type_params"), type_params_range);
|
|
2668
|
-
rbs_loc_add_optional_child(loc, INTERN("colon"), colon_range);
|
|
2669
|
-
rbs_loc_add_optional_child(loc, INTERN("self_types"), self_types_range);
|
|
2670
|
-
|
|
2671
2778
|
CHECK_PARSE(parser_pop_typevar_table(parser));
|
|
2672
2779
|
|
|
2673
|
-
|
|
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);
|
|
2674
2786
|
return true;
|
|
2675
2787
|
}
|
|
2676
2788
|
|
|
@@ -2706,14 +2818,9 @@ static bool parse_module_decl(rbs_parser_t *parser, rbs_position_t comment_pos,
|
|
|
2706
2818
|
.end = old_name_range.end
|
|
2707
2819
|
};
|
|
2708
2820
|
|
|
2709
|
-
|
|
2710
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 4);
|
|
2711
|
-
rbs_loc_add_required_child(loc, INTERN("keyword"), keyword_range);
|
|
2712
|
-
rbs_loc_add_required_child(loc, INTERN("new_name"), module_name_range);
|
|
2713
|
-
rbs_loc_add_required_child(loc, INTERN("eq"), eq_range);
|
|
2714
|
-
rbs_loc_add_optional_child(loc, INTERN("old_name"), old_name_range);
|
|
2821
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(decl_range);
|
|
2715
2822
|
|
|
2716
|
-
*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));
|
|
2717
2824
|
} else {
|
|
2718
2825
|
rbs_ast_declarations_module_t *module_decl0 = NULL;
|
|
2719
2826
|
CHECK_PARSE(parse_module_decl0(parser, keyword_range, module_name, module_name_range, comment, annotations, &module_decl0));
|
|
@@ -2738,16 +2845,13 @@ static bool parse_class_decl_super(rbs_parser_t *parser, rbs_range_t *lt_range,
|
|
|
2738
2845
|
rbs_node_list_t *args = rbs_node_list_new(ALLOCATOR());
|
|
2739
2846
|
rbs_type_name_t *name = NULL;
|
|
2740
2847
|
rbs_range_t name_range, args_range;
|
|
2741
|
-
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));
|
|
2742
2849
|
|
|
2743
2850
|
super_range.end = parser->current_token.range.end;
|
|
2744
2851
|
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
rbs_loc_add_optional_child(loc, INTERN("args"), args_range);
|
|
2749
|
-
|
|
2750
|
-
*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);
|
|
2751
2855
|
} else {
|
|
2752
2856
|
*lt_range = NULL_RANGE;
|
|
2753
2857
|
}
|
|
@@ -2784,15 +2888,12 @@ static bool parse_class_decl0(rbs_parser_t *parser, rbs_range_t keyword_range, r
|
|
|
2784
2888
|
|
|
2785
2889
|
CHECK_PARSE(parser_pop_typevar_table(parser));
|
|
2786
2890
|
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
rbs_loc_add_optional_child(loc, INTERN("type_params"), type_params_range);
|
|
2793
|
-
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);
|
|
2794
2896
|
|
|
2795
|
-
*class_decl = rbs_ast_declarations_class_new(ALLOCATOR(), loc, name, type_params, super, members, annotations, comment);
|
|
2796
2897
|
return true;
|
|
2797
2898
|
}
|
|
2798
2899
|
|
|
@@ -2826,14 +2927,9 @@ static bool parse_class_decl(rbs_parser_t *parser, rbs_position_t comment_pos, r
|
|
|
2826
2927
|
.end = old_name_range.end,
|
|
2827
2928
|
};
|
|
2828
2929
|
|
|
2829
|
-
|
|
2830
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 4);
|
|
2831
|
-
rbs_loc_add_required_child(loc, INTERN("keyword"), keyword_range);
|
|
2832
|
-
rbs_loc_add_required_child(loc, INTERN("new_name"), class_name_range);
|
|
2833
|
-
rbs_loc_add_required_child(loc, INTERN("eq"), eq_range);
|
|
2834
|
-
rbs_loc_add_optional_child(loc, INTERN("old_name"), old_name_range);
|
|
2930
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(decl_range);
|
|
2835
2931
|
|
|
2836
|
-
*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));
|
|
2837
2933
|
} else {
|
|
2838
2934
|
rbs_ast_declarations_class_t *class_decl0 = NULL;
|
|
2839
2935
|
CHECK_PARSE(parse_class_decl0(parser, keyword_range, class_name, class_name_range, comment, annotations, &class_decl0));
|
|
@@ -2976,8 +3072,8 @@ static bool parse_namespace(rbs_parser_t *parser, rbs_range_t *rg, rbs_namespace
|
|
|
2976
3072
|
|
|
2977
3073
|
while (true) {
|
|
2978
3074
|
if (parser->next_token.type == tUIDENT && parser->next_token2.type == pCOLON2) {
|
|
2979
|
-
|
|
2980
|
-
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));
|
|
2981
3077
|
rbs_node_list_append(path, (rbs_node_t *) symbol);
|
|
2982
3078
|
if (rbs_null_position_p(rg->start)) {
|
|
2983
3079
|
rg->start = parser->next_token.range.start;
|
|
@@ -2990,7 +3086,7 @@ static bool parse_namespace(rbs_parser_t *parser, rbs_range_t *rg, rbs_namespace
|
|
|
2990
3086
|
}
|
|
2991
3087
|
}
|
|
2992
3088
|
|
|
2993
|
-
*out_ns = rbs_namespace_new(ALLOCATOR(),
|
|
3089
|
+
*out_ns = rbs_namespace_new(ALLOCATOR(), RBS_RANGE_LEX2AST(*rg), path, is_absolute);
|
|
2994
3090
|
return true;
|
|
2995
3091
|
}
|
|
2996
3092
|
|
|
@@ -3018,9 +3114,9 @@ static bool parse_use_clauses(rbs_parser_t *parser, rbs_node_list_t *clauses) {
|
|
|
3018
3114
|
|
|
3019
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 };
|
|
3020
3116
|
|
|
3021
|
-
|
|
3022
|
-
rbs_ast_symbol_t *symbol = rbs_ast_symbol_new(ALLOCATOR(),
|
|
3023
|
-
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);
|
|
3024
3120
|
|
|
3025
3121
|
rbs_range_t keyword_range = NULL_RANGE;
|
|
3026
3122
|
rbs_range_t new_name_range = NULL_RANGE;
|
|
@@ -3034,19 +3130,18 @@ static bool parse_use_clauses(rbs_parser_t *parser, rbs_node_list_t *clauses) {
|
|
|
3034
3130
|
if (ident_type == tLIDENT) ADVANCE_ASSERT(parser, tLIDENT);
|
|
3035
3131
|
if (ident_type == tULIDENT) ADVANCE_ASSERT(parser, tULIDENT);
|
|
3036
3132
|
|
|
3037
|
-
|
|
3038
|
-
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));
|
|
3039
3135
|
new_name_range = parser->current_token.range;
|
|
3040
3136
|
clause_range.end = new_name_range.end;
|
|
3041
3137
|
}
|
|
3042
3138
|
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
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);
|
|
3048
3144
|
|
|
3049
|
-
rbs_ast_directives_use_single_clause_t *clause = rbs_ast_directives_use_single_clause_new(ALLOCATOR(), loc, type_name, new_name);
|
|
3050
3145
|
rbs_node_list_append(clauses, (rbs_node_t *) clause);
|
|
3051
3146
|
|
|
3052
3147
|
break;
|
|
@@ -3058,12 +3153,9 @@ static bool parse_use_clauses(rbs_parser_t *parser, rbs_node_list_t *clauses) {
|
|
|
3058
3153
|
rbs_range_t star_range = parser->current_token.range;
|
|
3059
3154
|
clause_range.end = star_range.end;
|
|
3060
3155
|
|
|
3061
|
-
|
|
3062
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 2);
|
|
3063
|
-
rbs_loc_add_required_child(loc, INTERN("namespace"), namespace_range);
|
|
3064
|
-
rbs_loc_add_required_child(loc, INTERN("star"), star_range);
|
|
3156
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(clause_range);
|
|
3065
3157
|
|
|
3066
|
-
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));
|
|
3067
3159
|
rbs_node_list_append(clauses, (rbs_node_t *) clause);
|
|
3068
3160
|
|
|
3069
3161
|
break;
|
|
@@ -3099,11 +3191,9 @@ static bool parse_use_directive(rbs_parser_t *parser, rbs_ast_directives_use_t *
|
|
|
3099
3191
|
rbs_range_t directive_range = keyword_range;
|
|
3100
3192
|
directive_range.end = parser->current_token.range.end;
|
|
3101
3193
|
|
|
3102
|
-
|
|
3103
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 1);
|
|
3104
|
-
rbs_loc_add_required_child(loc, INTERN("keyword"), keyword_range);
|
|
3194
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(directive_range);
|
|
3105
3195
|
|
|
3106
|
-
*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));
|
|
3107
3197
|
}
|
|
3108
3198
|
|
|
3109
3199
|
return true;
|
|
@@ -3141,7 +3231,12 @@ static rbs_ast_comment_t *parse_comment_lines(rbs_parser_t *parser, rbs_comment_
|
|
|
3141
3231
|
|
|
3142
3232
|
return rbs_ast_comment_new(
|
|
3143
3233
|
ALLOCATOR(),
|
|
3144
|
-
|
|
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
|
+
},
|
|
3145
3240
|
rbs_buffer_to_string(&rbs_buffer)
|
|
3146
3241
|
);
|
|
3147
3242
|
}
|
|
@@ -3243,7 +3338,7 @@ bool rbs_parse_signature(rbs_parser_t *parser, rbs_signature_t **signature) {
|
|
|
3243
3338
|
}
|
|
3244
3339
|
|
|
3245
3340
|
signature_range.end = parser->current_token.range.end;
|
|
3246
|
-
*signature = rbs_signature_new(ALLOCATOR(),
|
|
3341
|
+
*signature = rbs_signature_new(ALLOCATOR(), RBS_RANGE_LEX2AST(signature_range), dirs, decls);
|
|
3247
3342
|
return true;
|
|
3248
3343
|
}
|
|
3249
3344
|
|
|
@@ -3421,7 +3516,9 @@ rbs_lexer_t *rbs_lexer_new(rbs_allocator_t *allocator, rbs_string_t string, cons
|
|
|
3421
3516
|
}
|
|
3422
3517
|
|
|
3423
3518
|
if (start_pos > 0) {
|
|
3424
|
-
|
|
3519
|
+
while (lexer->current.byte_pos < start_pos) {
|
|
3520
|
+
rbs_skip(lexer);
|
|
3521
|
+
}
|
|
3425
3522
|
}
|
|
3426
3523
|
|
|
3427
3524
|
lexer->start = lexer->current;
|
|
@@ -3505,3 +3602,604 @@ void rbs_parser_set_error(rbs_parser_t *parser, rbs_token_t tok, bool syntax_err
|
|
|
3505
3602
|
parser->error->message = message;
|
|
3506
3603
|
parser->error->syntax_error = syntax_error;
|
|
3507
3604
|
}
|
|
3605
|
+
|
|
3606
|
+
/*
|
|
3607
|
+
parse_method_overload ::= {} annotations <method_type>
|
|
3608
|
+
*/
|
|
3609
|
+
NODISCARD
|
|
3610
|
+
static bool parse_method_overload(rbs_parser_t *parser, rbs_node_list_t *annotations, rbs_method_type_t **method_type) {
|
|
3611
|
+
rbs_position_t pos = NullPosition;
|
|
3612
|
+
|
|
3613
|
+
if (!parse_annotations(parser, annotations, &pos)) {
|
|
3614
|
+
return false;
|
|
3615
|
+
}
|
|
3616
|
+
|
|
3617
|
+
return rbs_parse_method_type(parser, method_type, false, true);
|
|
3618
|
+
}
|
|
3619
|
+
|
|
3620
|
+
/*
|
|
3621
|
+
inline_method_overloads ::= {} <overload> -- returns true
|
|
3622
|
+
| {} overload `|` ... `|` overload -- returns true
|
|
3623
|
+
| {} overload `|` ... `|` `...` -- returns true (dot3_location is set)
|
|
3624
|
+
| {<>} -- returns false
|
|
3625
|
+
*/
|
|
3626
|
+
NODISCARD
|
|
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) {
|
|
3628
|
+
while (true) {
|
|
3629
|
+
rbs_node_list_t *annotations = rbs_node_list_new(ALLOCATOR());
|
|
3630
|
+
rbs_method_type_t *method_type = NULL;
|
|
3631
|
+
|
|
3632
|
+
if (!parse_method_overload(parser, annotations, &method_type)) {
|
|
3633
|
+
return false;
|
|
3634
|
+
}
|
|
3635
|
+
|
|
3636
|
+
rbs_location_range location = rbs_location_range_current_token(parser);
|
|
3637
|
+
rbs_ast_members_method_definition_overload_t *overload = rbs_ast_members_method_definition_overload_new(
|
|
3638
|
+
ALLOCATOR(),
|
|
3639
|
+
location,
|
|
3640
|
+
annotations,
|
|
3641
|
+
(rbs_node_t *) method_type
|
|
3642
|
+
);
|
|
3643
|
+
rbs_node_list_append(overloads, (rbs_node_t *) overload);
|
|
3644
|
+
|
|
3645
|
+
if (parser->next_token.type == pBAR) {
|
|
3646
|
+
rbs_location_range bar_range = RBS_RANGE_LEX2AST(parser->next_token.range);
|
|
3647
|
+
|
|
3648
|
+
rbs_parser_advance(parser);
|
|
3649
|
+
|
|
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
|
+
}
|
|
3657
|
+
|
|
3658
|
+
continue;
|
|
3659
|
+
}
|
|
3660
|
+
|
|
3661
|
+
return true;
|
|
3662
|
+
}
|
|
3663
|
+
}
|
|
3664
|
+
|
|
3665
|
+
NODISCARD
|
|
3666
|
+
static bool parse_inline_comment(rbs_parser_t *parser, rbs_location_range *comment_range) {
|
|
3667
|
+
if (parser->next_token.type != tINLINECOMMENT) {
|
|
3668
|
+
*comment_range = RBS_LOCATION_NULL_RANGE;
|
|
3669
|
+
return true;
|
|
3670
|
+
}
|
|
3671
|
+
|
|
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) {
|
|
3680
|
+
rbs_parser_advance(parser);
|
|
3681
|
+
|
|
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
|
+
|
|
3715
|
+
return true;
|
|
3716
|
+
}
|
|
3717
|
+
|
|
3718
|
+
NODISCARD
|
|
3719
|
+
static bool parse_inline_leading_annotation(rbs_parser_t *parser, rbs_ast_ruby_annotations_t **annotation) {
|
|
3720
|
+
switch (parser->next_token.type) {
|
|
3721
|
+
case pCOLON: {
|
|
3722
|
+
rbs_range_t colon_range = parser->next_token.range;
|
|
3723
|
+
rbs_parser_advance(parser);
|
|
3724
|
+
|
|
3725
|
+
rbs_node_list_t *annotations = rbs_node_list_new(ALLOCATOR());
|
|
3726
|
+
rbs_method_type_t *method_type = NULL;
|
|
3727
|
+
|
|
3728
|
+
if (!parse_method_overload(parser, annotations, &method_type)) {
|
|
3729
|
+
return false;
|
|
3730
|
+
}
|
|
3731
|
+
|
|
3732
|
+
rbs_range_t full_range = {
|
|
3733
|
+
.start = colon_range.start,
|
|
3734
|
+
.end = parser->current_token.range.end
|
|
3735
|
+
};
|
|
3736
|
+
|
|
3737
|
+
rbs_location_range full_loc = RBS_RANGE_LEX2AST(full_range);
|
|
3738
|
+
|
|
3739
|
+
*annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_colon_method_type_annotation_new(
|
|
3740
|
+
ALLOCATOR(),
|
|
3741
|
+
full_loc,
|
|
3742
|
+
RBS_RANGE_LEX2AST(colon_range),
|
|
3743
|
+
annotations,
|
|
3744
|
+
(rbs_node_t *) method_type
|
|
3745
|
+
);
|
|
3746
|
+
return true;
|
|
3747
|
+
}
|
|
3748
|
+
case kATRBS: {
|
|
3749
|
+
rbs_range_t rbs_range = parser->next_token.range;
|
|
3750
|
+
rbs_parser_advance(parser);
|
|
3751
|
+
|
|
3752
|
+
switch (parser->next_token.type) {
|
|
3753
|
+
case pDOT3: {
|
|
3754
|
+
rbs_location_range dot3_range = RBS_RANGE_LEX2AST(parser->next_token.range);
|
|
3755
|
+
rbs_parser_advance(parser);
|
|
3756
|
+
|
|
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());
|
|
3759
|
+
|
|
3760
|
+
rbs_range_t full_range = {
|
|
3761
|
+
.start = rbs_range.start,
|
|
3762
|
+
.end = parser->current_token.range.end
|
|
3763
|
+
};
|
|
3764
|
+
|
|
3765
|
+
rbs_location_range full_loc = RBS_RANGE_LEX2AST(full_range);
|
|
3766
|
+
|
|
3767
|
+
*annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_method_types_annotation_new(
|
|
3768
|
+
ALLOCATOR(),
|
|
3769
|
+
full_loc,
|
|
3770
|
+
RBS_RANGE_LEX2AST(rbs_range),
|
|
3771
|
+
overloads,
|
|
3772
|
+
bar_locations,
|
|
3773
|
+
dot3_range
|
|
3774
|
+
);
|
|
3775
|
+
return true;
|
|
3776
|
+
}
|
|
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;
|
|
3784
|
+
|
|
3785
|
+
if (!parse_inline_method_overloads(parser, overloads, bar_locations, &dot3_location)) {
|
|
3786
|
+
return false;
|
|
3787
|
+
}
|
|
3788
|
+
|
|
3789
|
+
rbs_range_t full_range = {
|
|
3790
|
+
.start = rbs_range.start,
|
|
3791
|
+
.end = parser->current_token.range.end
|
|
3792
|
+
};
|
|
3793
|
+
|
|
3794
|
+
rbs_location_range full_loc = RBS_RANGE_LEX2AST(full_range);
|
|
3795
|
+
|
|
3796
|
+
*annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_method_types_annotation_new(
|
|
3797
|
+
ALLOCATOR(),
|
|
3798
|
+
full_loc,
|
|
3799
|
+
RBS_RANGE_LEX2AST(rbs_range),
|
|
3800
|
+
overloads,
|
|
3801
|
+
bar_locations,
|
|
3802
|
+
dot3_location
|
|
3803
|
+
);
|
|
3804
|
+
return true;
|
|
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
|
+
}
|
|
3836
|
+
case kRETURN: {
|
|
3837
|
+
rbs_parser_advance(parser);
|
|
3838
|
+
|
|
3839
|
+
rbs_range_t return_range = parser->current_token.range;
|
|
3840
|
+
|
|
3841
|
+
ADVANCE_ASSERT(parser, pCOLON);
|
|
3842
|
+
|
|
3843
|
+
rbs_range_t colon_range = parser->current_token.range;
|
|
3844
|
+
|
|
3845
|
+
rbs_node_t *return_type = NULL;
|
|
3846
|
+
if (!rbs_parse_type(parser, &return_type, true, true, true)) {
|
|
3847
|
+
return false;
|
|
3848
|
+
}
|
|
3849
|
+
|
|
3850
|
+
rbs_location_range comment_loc = RBS_LOCATION_NULL_RANGE;
|
|
3851
|
+
if (!parse_inline_comment(parser, &comment_loc)) {
|
|
3852
|
+
return false;
|
|
3853
|
+
}
|
|
3854
|
+
|
|
3855
|
+
rbs_range_t full_range = {
|
|
3856
|
+
.start = rbs_range.start,
|
|
3857
|
+
.end = parser->current_token.range.end
|
|
3858
|
+
};
|
|
3859
|
+
|
|
3860
|
+
rbs_location_range full_loc = RBS_RANGE_LEX2AST(full_range);
|
|
3861
|
+
|
|
3862
|
+
*annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_return_type_annotation_new(
|
|
3863
|
+
ALLOCATOR(),
|
|
3864
|
+
full_loc,
|
|
3865
|
+
RBS_RANGE_LEX2AST(rbs_range),
|
|
3866
|
+
RBS_RANGE_LEX2AST(return_range),
|
|
3867
|
+
RBS_RANGE_LEX2AST(colon_range),
|
|
3868
|
+
return_type,
|
|
3869
|
+
comment_loc
|
|
3870
|
+
);
|
|
3871
|
+
return true;
|
|
3872
|
+
}
|
|
3873
|
+
case tAIDENT: {
|
|
3874
|
+
// Parse instance variable annotation: @rbs @name: Type
|
|
3875
|
+
rbs_parser_advance(parser);
|
|
3876
|
+
|
|
3877
|
+
rbs_range_t ivar_name_range = parser->current_token.range;
|
|
3878
|
+
rbs_location_range ivar_name_loc = RBS_RANGE_LEX2AST(ivar_name_range);
|
|
3879
|
+
|
|
3880
|
+
// Extract the instance variable name as a symbol
|
|
3881
|
+
rbs_string_t ivar_string = rbs_parser_peek_current_token(parser);
|
|
3882
|
+
rbs_constant_id_t ivar_id = rbs_constant_pool_insert_string(&parser->constant_pool, ivar_string);
|
|
3883
|
+
rbs_ast_symbol_t *ivar_name = rbs_ast_symbol_new(ALLOCATOR(), ivar_name_loc, &parser->constant_pool, ivar_id);
|
|
3884
|
+
|
|
3885
|
+
ADVANCE_ASSERT(parser, pCOLON);
|
|
3886
|
+
|
|
3887
|
+
rbs_range_t colon_range = parser->current_token.range;
|
|
3888
|
+
|
|
3889
|
+
rbs_node_t *type = NULL;
|
|
3890
|
+
if (!rbs_parse_type(parser, &type, false, true, true)) {
|
|
3891
|
+
return false;
|
|
3892
|
+
}
|
|
3893
|
+
|
|
3894
|
+
rbs_location_range comment_loc = RBS_LOCATION_NULL_RANGE;
|
|
3895
|
+
if (!parse_inline_comment(parser, &comment_loc)) {
|
|
3896
|
+
return false;
|
|
3897
|
+
}
|
|
3898
|
+
|
|
3899
|
+
rbs_range_t full_range = {
|
|
3900
|
+
.start = rbs_range.start,
|
|
3901
|
+
.end = parser->current_token.range.end
|
|
3902
|
+
};
|
|
3903
|
+
|
|
3904
|
+
rbs_location_range full_loc = RBS_RANGE_LEX2AST(full_range);
|
|
3905
|
+
|
|
3906
|
+
*annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_instance_variable_annotation_new(
|
|
3907
|
+
ALLOCATOR(),
|
|
3908
|
+
full_loc,
|
|
3909
|
+
RBS_RANGE_LEX2AST(rbs_range),
|
|
3910
|
+
ivar_name,
|
|
3911
|
+
RBS_RANGE_LEX2AST(ivar_name_range),
|
|
3912
|
+
RBS_RANGE_LEX2AST(colon_range),
|
|
3913
|
+
type,
|
|
3914
|
+
comment_loc
|
|
3915
|
+
);
|
|
3916
|
+
return true;
|
|
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
|
+
}
|
|
4055
|
+
default: {
|
|
4056
|
+
rbs_parser_set_error(parser, parser->next_token, true, "unexpected token for @rbs annotation");
|
|
4057
|
+
return false;
|
|
4058
|
+
}
|
|
4059
|
+
}
|
|
4060
|
+
}
|
|
4061
|
+
default: {
|
|
4062
|
+
rbs_parser_set_error(parser, parser->next_token, true, "unexpected token for inline leading annotation");
|
|
4063
|
+
return false;
|
|
4064
|
+
}
|
|
4065
|
+
}
|
|
4066
|
+
}
|
|
4067
|
+
|
|
4068
|
+
NODISCARD
|
|
4069
|
+
static bool parse_inline_trailing_annotation(rbs_parser_t *parser, rbs_ast_ruby_annotations_t **annotation) {
|
|
4070
|
+
rbs_range_t prefix_range = parser->next_token.range;
|
|
4071
|
+
|
|
4072
|
+
switch (parser->next_token.type) {
|
|
4073
|
+
case pCOLON: {
|
|
4074
|
+
rbs_parser_advance(parser);
|
|
4075
|
+
|
|
4076
|
+
// Check for class-alias or module-alias keywords
|
|
4077
|
+
if (parser->next_token.type == kCLASSALIAS || parser->next_token.type == kMODULEALIAS) {
|
|
4078
|
+
bool is_class_alias = (parser->next_token.type == kCLASSALIAS);
|
|
4079
|
+
rbs_range_t keyword_range = parser->next_token.range;
|
|
4080
|
+
rbs_parser_advance(parser);
|
|
4081
|
+
|
|
4082
|
+
rbs_type_name_t *type_name = NULL;
|
|
4083
|
+
rbs_location_range type_name_loc = RBS_LOCATION_NULL_RANGE;
|
|
4084
|
+
rbs_range_t full_range;
|
|
4085
|
+
|
|
4086
|
+
// Check if a type name is provided
|
|
4087
|
+
if (parser->next_token.type == tUIDENT || parser->next_token.type == pCOLON2) {
|
|
4088
|
+
rbs_parser_advance(parser);
|
|
4089
|
+
|
|
4090
|
+
rbs_range_t type_name_range;
|
|
4091
|
+
if (!parse_type_name(parser, CLASS_NAME, &type_name_range, &type_name)) {
|
|
4092
|
+
return false;
|
|
4093
|
+
}
|
|
4094
|
+
// parse_type_name leaves current_token at the last identifier, don't advance
|
|
4095
|
+
type_name_loc = RBS_RANGE_LEX2AST(type_name_range);
|
|
4096
|
+
full_range.start = prefix_range.start;
|
|
4097
|
+
full_range.end = type_name_range.end;
|
|
4098
|
+
} else {
|
|
4099
|
+
// No type name provided - will be inferred
|
|
4100
|
+
full_range.start = prefix_range.start;
|
|
4101
|
+
full_range.end = keyword_range.end;
|
|
4102
|
+
}
|
|
4103
|
+
|
|
4104
|
+
rbs_location_range full_loc = RBS_RANGE_LEX2AST(full_range);
|
|
4105
|
+
|
|
4106
|
+
if (is_class_alias) {
|
|
4107
|
+
*annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_class_alias_annotation_new(
|
|
4108
|
+
ALLOCATOR(),
|
|
4109
|
+
full_loc,
|
|
4110
|
+
RBS_RANGE_LEX2AST(prefix_range),
|
|
4111
|
+
RBS_RANGE_LEX2AST(keyword_range),
|
|
4112
|
+
type_name,
|
|
4113
|
+
type_name_loc
|
|
4114
|
+
);
|
|
4115
|
+
} else {
|
|
4116
|
+
*annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_module_alias_annotation_new(
|
|
4117
|
+
ALLOCATOR(),
|
|
4118
|
+
full_loc,
|
|
4119
|
+
RBS_RANGE_LEX2AST(prefix_range),
|
|
4120
|
+
RBS_RANGE_LEX2AST(keyword_range),
|
|
4121
|
+
type_name,
|
|
4122
|
+
type_name_loc
|
|
4123
|
+
);
|
|
4124
|
+
}
|
|
4125
|
+
return true;
|
|
4126
|
+
}
|
|
4127
|
+
|
|
4128
|
+
// Otherwise, parse as regular type assertion
|
|
4129
|
+
rbs_node_t *type = NULL;
|
|
4130
|
+
if (!rbs_parse_type(parser, &type, true, true, true)) {
|
|
4131
|
+
return false;
|
|
4132
|
+
}
|
|
4133
|
+
|
|
4134
|
+
rbs_range_t full_range = {
|
|
4135
|
+
.start = prefix_range.start,
|
|
4136
|
+
.end = parser->current_token.range.end
|
|
4137
|
+
};
|
|
4138
|
+
|
|
4139
|
+
rbs_location_range full_loc = RBS_RANGE_LEX2AST(full_range);
|
|
4140
|
+
|
|
4141
|
+
*annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_node_type_assertion_new(
|
|
4142
|
+
ALLOCATOR(),
|
|
4143
|
+
full_loc,
|
|
4144
|
+
RBS_RANGE_LEX2AST(prefix_range),
|
|
4145
|
+
type
|
|
4146
|
+
);
|
|
4147
|
+
return true;
|
|
4148
|
+
}
|
|
4149
|
+
case pLBRACKET: {
|
|
4150
|
+
rbs_parser_advance(parser);
|
|
4151
|
+
|
|
4152
|
+
rbs_node_list_t *type_args = rbs_node_list_new(ALLOCATOR());
|
|
4153
|
+
rbs_location_range_list_t *comma_locations = rbs_location_range_list_new(ALLOCATOR());
|
|
4154
|
+
|
|
4155
|
+
// Check for empty type args
|
|
4156
|
+
if (parser->next_token.type == pRBRACKET) {
|
|
4157
|
+
rbs_parser_set_error(parser, parser->next_token, true, "type application cannot be empty");
|
|
4158
|
+
return false;
|
|
4159
|
+
}
|
|
4160
|
+
|
|
4161
|
+
// Parse type list with comma tracking
|
|
4162
|
+
CHECK_PARSE(parse_type_list_with_commas(parser, pRBRACKET, type_args, comma_locations, true, true, false));
|
|
4163
|
+
|
|
4164
|
+
rbs_range_t close_bracket_range = parser->next_token.range;
|
|
4165
|
+
rbs_parser_advance(parser); // consume ]
|
|
4166
|
+
|
|
4167
|
+
rbs_range_t full_range = {
|
|
4168
|
+
.start = prefix_range.start,
|
|
4169
|
+
.end = close_bracket_range.end
|
|
4170
|
+
};
|
|
4171
|
+
|
|
4172
|
+
rbs_location_range full_loc = RBS_RANGE_LEX2AST(full_range);
|
|
4173
|
+
|
|
4174
|
+
*annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_type_application_annotation_new(
|
|
4175
|
+
ALLOCATOR(),
|
|
4176
|
+
full_loc,
|
|
4177
|
+
RBS_RANGE_LEX2AST(prefix_range),
|
|
4178
|
+
type_args,
|
|
4179
|
+
RBS_RANGE_LEX2AST(close_bracket_range),
|
|
4180
|
+
comma_locations
|
|
4181
|
+
);
|
|
4182
|
+
return true;
|
|
4183
|
+
}
|
|
4184
|
+
default: {
|
|
4185
|
+
rbs_parser_set_error(parser, parser->next_token, true, "unexpected token for inline trailing annotation");
|
|
4186
|
+
return false;
|
|
4187
|
+
}
|
|
4188
|
+
}
|
|
4189
|
+
}
|
|
4190
|
+
|
|
4191
|
+
bool rbs_parse_inline_leading_annotation(rbs_parser_t *parser, rbs_ast_ruby_annotations_t **annotation) {
|
|
4192
|
+
bool success = parse_inline_leading_annotation(parser, annotation);
|
|
4193
|
+
|
|
4194
|
+
ADVANCE_ASSERT(parser, pEOF);
|
|
4195
|
+
|
|
4196
|
+
return success;
|
|
4197
|
+
}
|
|
4198
|
+
|
|
4199
|
+
bool rbs_parse_inline_trailing_annotation(rbs_parser_t *parser, rbs_ast_ruby_annotations_t **annotation) {
|
|
4200
|
+
bool success = parse_inline_trailing_annotation(parser, annotation);
|
|
4201
|
+
|
|
4202
|
+
ADVANCE_ASSERT(parser, pEOF);
|
|
4203
|
+
|
|
4204
|
+
return success;
|
|
4205
|
+
}
|