rbs 4.0.0.dev.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 +18 -11
- data/.github/workflows/comments.yml +5 -3
- data/.github/workflows/dependabot.yml +2 -2
- data/.github/workflows/ruby.yml +27 -34
- data/.github/workflows/rust.yml +95 -0
- data/.github/workflows/typecheck.yml +2 -2
- data/.github/workflows/windows.yml +2 -2
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +323 -0
- data/README.md +1 -1
- data/Rakefile +43 -33
- data/Steepfile +1 -0
- data/config.yml +426 -24
- data/core/array.rbs +307 -227
- 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 +55 -34
- data/core/complex.rbs +104 -78
- data/core/dir.rbs +61 -49
- data/core/encoding.rbs +12 -15
- data/core/enumerable.rbs +179 -87
- data/core/enumerator/arithmetic_sequence.rbs +70 -0
- data/core/enumerator.rbs +65 -2
- data/core/errno.rbs +11 -2
- data/core/errors.rbs +58 -29
- data/core/exception.rbs +13 -13
- data/core/fiber.rbs +74 -54
- data/core/file.rbs +280 -177
- data/core/file_test.rbs +3 -3
- data/core/float.rbs +257 -92
- data/core/gc.rbs +425 -281
- data/core/hash.rbs +1045 -739
- data/core/integer.rbs +135 -137
- data/core/io/buffer.rbs +53 -42
- data/core/io/wait.rbs +13 -35
- data/core/io.rbs +192 -144
- data/core/kernel.rbs +216 -155
- data/core/marshal.rbs +4 -4
- data/core/match_data.rbs +15 -13
- data/core/math.rbs +107 -66
- data/core/method.rbs +69 -33
- data/core/module.rbs +244 -106
- data/core/nil_class.rbs +7 -6
- data/core/numeric.rbs +74 -63
- data/core/object.rbs +9 -11
- data/core/object_space.rbs +30 -23
- data/core/pathname.rbs +1322 -0
- data/core/proc.rbs +95 -58
- data/core/process.rbs +222 -202
- data/core/ractor.rbs +371 -515
- data/core/random.rbs +21 -3
- data/core/range.rbs +159 -57
- data/core/rational.rbs +60 -89
- data/core/rbs/unnamed/argf.rbs +60 -53
- data/core/rbs/unnamed/env_class.rbs +19 -14
- data/core/rbs/unnamed/main_class.rbs +123 -0
- data/core/rbs/unnamed/random.rbs +11 -118
- data/core/regexp.rbs +258 -214
- data/core/ruby.rbs +53 -0
- data/core/ruby_vm.rbs +38 -34
- data/core/rubygems/config_file.rbs +5 -5
- data/core/rubygems/errors.rbs +4 -71
- data/core/rubygems/requirement.rbs +5 -5
- data/core/rubygems/rubygems.rbs +16 -82
- data/core/rubygems/version.rbs +2 -3
- data/core/set.rbs +490 -360
- data/core/signal.rbs +26 -16
- data/core/string.rbs +3234 -1285
- data/core/struct.rbs +27 -26
- data/core/symbol.rbs +41 -34
- data/core/thread.rbs +135 -67
- data/core/time.rbs +81 -50
- data/core/trace_point.rbs +41 -35
- data/core/true_class.rbs +2 -2
- data/core/unbound_method.rbs +24 -16
- data/core/warning.rbs +7 -7
- data/docs/aliases.md +79 -0
- data/docs/collection.md +3 -3
- data/docs/config.md +171 -0
- data/docs/encoding.md +56 -0
- data/docs/gem.md +0 -1
- data/docs/inline.md +576 -0
- data/docs/sigs.md +3 -3
- 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 +544 -116
- data/ext/rbs_extension/ast_translation.h +3 -0
- data/ext/rbs_extension/class_constants.c +16 -2
- data/ext/rbs_extension/class_constants.h +8 -0
- data/ext/rbs_extension/extconf.rb +5 -1
- data/ext/rbs_extension/legacy_location.c +33 -56
- data/ext/rbs_extension/legacy_location.h +37 -0
- data/ext/rbs_extension/main.c +44 -35
- data/include/rbs/ast.h +448 -173
- data/include/rbs/defines.h +27 -0
- data/include/rbs/lexer.h +30 -11
- data/include/rbs/location.h +25 -44
- data/include/rbs/parser.h +6 -6
- data/include/rbs/string.h +0 -2
- data/include/rbs/util/rbs_allocator.h +34 -13
- data/include/rbs/util/rbs_assert.h +12 -1
- data/include/rbs/util/rbs_constant_pool.h +0 -3
- data/include/rbs/util/rbs_encoding.h +2 -0
- data/include/rbs/util/rbs_unescape.h +2 -1
- 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 +293 -3
- data/lib/rbs/ast/ruby/comment_block.rb +24 -0
- data/lib/rbs/ast/ruby/declarations.rb +198 -3
- data/lib/rbs/ast/ruby/helpers/constant_helper.rb +4 -0
- data/lib/rbs/ast/ruby/members.rb +532 -22
- data/lib/rbs/ast/type_param.rb +24 -4
- data/lib/rbs/buffer.rb +20 -15
- data/lib/rbs/cli/diff.rb +16 -15
- data/lib/rbs/cli/validate.rb +38 -106
- data/lib/rbs/cli.rb +52 -19
- data/lib/rbs/collection/config/lockfile_generator.rb +14 -2
- data/lib/rbs/collection/sources/git.rb +1 -0
- data/lib/rbs/definition.rb +1 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +62 -9
- data/lib/rbs/definition_builder/method_builder.rb +20 -0
- data/lib/rbs/definition_builder.rb +147 -25
- data/lib/rbs/diff.rb +7 -1
- data/lib/rbs/environment.rb +227 -74
- data/lib/rbs/environment_loader.rb +0 -6
- data/lib/rbs/errors.rb +27 -18
- data/lib/rbs/inline_parser.rb +342 -6
- data/lib/rbs/location_aux.rb +1 -1
- data/lib/rbs/locator.rb +5 -1
- data/lib/rbs/method_type.rb +5 -3
- data/lib/rbs/parser_aux.rb +20 -7
- 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 +8 -0
- data/lib/rbs/resolver/constant_resolver.rb +2 -2
- data/lib/rbs/resolver/type_name_resolver.rb +116 -38
- data/lib/rbs/subtractor.rb +3 -1
- data/lib/rbs/test/type_check.rb +19 -2
- data/lib/rbs/type_name.rb +1 -1
- data/lib/rbs/types.rb +88 -78
- 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 +1 -2
- data/lib/rdoc/discover.rb +1 -1
- data/lib/rdoc_plugin/parser.rb +1 -1
- data/rbs.gemspec +4 -3
- 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/ast/ruby/annotations.rbs +315 -4
- data/sig/ast/ruby/comment_block.rbs +8 -0
- data/sig/ast/ruby/declarations.rbs +102 -4
- data/sig/ast/ruby/members.rbs +108 -2
- 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 -1
- data/sig/definition_builder.rbs +2 -0
- data/sig/environment.rbs +70 -12
- data/sig/errors.rbs +13 -14
- data/sig/inline_parser.rbs +39 -2
- data/sig/locator.rbs +0 -2
- data/sig/manifest.yaml +0 -1
- data/sig/method_builder.rbs +3 -1
- data/sig/parser.rbs +31 -13
- data/sig/prototype/helpers.rbs +2 -0
- data/sig/resolver/type_name_resolver.rbs +35 -7
- data/sig/source.rbs +3 -3
- data/sig/type_param.rbs +13 -8
- 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 +410 -153
- data/src/lexer.c +1392 -1313
- data/src/lexer.re +3 -0
- data/src/lexstate.c +58 -37
- data/src/location.c +8 -48
- data/src/parser.c +977 -516
- data/src/string.c +0 -48
- data/src/util/rbs_allocator.c +89 -71
- data/src/util/rbs_assert.c +1 -1
- data/src/util/rbs_buffer.c +2 -2
- data/src/util/rbs_constant_pool.c +10 -14
- data/src/util/rbs_encoding.c +4 -8
- data/src/util/rbs_unescape.c +56 -20
- data/stdlib/bigdecimal/0/big_decimal.rbs +116 -98
- data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
- data/stdlib/cgi/0/core.rbs +9 -393
- data/stdlib/cgi/0/manifest.yaml +1 -0
- data/stdlib/cgi-escape/0/escape.rbs +171 -0
- data/stdlib/coverage/0/coverage.rbs +7 -4
- data/stdlib/date/0/date.rbs +92 -79
- data/stdlib/date/0/date_time.rbs +25 -24
- data/stdlib/delegate/0/delegator.rbs +10 -7
- 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 +748 -347
- data/stdlib/etc/0/etc.rbs +55 -50
- data/stdlib/fileutils/0/fileutils.rbs +158 -139
- data/stdlib/forwardable/0/forwardable.rbs +13 -10
- data/stdlib/io-console/0/io-console.rbs +2 -2
- data/stdlib/json/0/json.rbs +217 -136
- data/stdlib/monitor/0/monitor.rbs +3 -3
- data/stdlib/net-http/0/net-http.rbs +162 -134
- data/stdlib/objspace/0/objspace.rbs +17 -34
- data/stdlib/open-uri/0/open-uri.rbs +48 -8
- data/stdlib/open3/0/open3.rbs +469 -10
- data/stdlib/openssl/0/openssl.rbs +475 -357
- data/stdlib/optparse/0/optparse.rbs +26 -17
- data/stdlib/pathname/0/pathname.rbs +11 -1381
- 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 +65 -12
- 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/rdoc.rbs +1 -1
- data/stdlib/rdoc/0/store.rbs +1 -1
- data/stdlib/resolv/0/resolv.rbs +25 -68
- data/stdlib/ripper/0/ripper.rbs +22 -19
- 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/singleton/0/singleton.rbs +3 -0
- data/stdlib/socket/0/addrinfo.rbs +7 -7
- data/stdlib/socket/0/basic_socket.rbs +3 -3
- data/stdlib/socket/0/ip_socket.rbs +10 -8
- data/stdlib/socket/0/socket.rbs +23 -10
- data/stdlib/socket/0/tcp_server.rbs +1 -1
- data/stdlib/socket/0/tcp_socket.rbs +11 -3
- data/stdlib/socket/0/udp_socket.rbs +1 -1
- data/stdlib/socket/0/unix_server.rbs +1 -1
- data/stdlib/stringio/0/stringio.rbs +1177 -85
- data/stdlib/strscan/0/string_scanner.rbs +27 -25
- data/stdlib/tempfile/0/tempfile.rbs +25 -21
- data/stdlib/time/0/time.rbs +8 -6
- data/stdlib/timeout/0/timeout.rbs +63 -7
- data/stdlib/tsort/0/cyclic.rbs +3 -0
- data/stdlib/tsort/0/tsort.rbs +7 -6
- data/stdlib/uri/0/common.rbs +42 -20
- data/stdlib/uri/0/file.rbs +3 -3
- data/stdlib/uri/0/generic.rbs +26 -18
- 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 +12 -12
- 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
- data/stdlib/zlib/0/zstream.rbs +1 -0
- metadata +50 -6
data/src/parser.c
CHANGED
|
@@ -6,25 +6,21 @@
|
|
|
6
6
|
#include <ctype.h>
|
|
7
7
|
#include <string.h>
|
|
8
8
|
|
|
9
|
+
#include "rbs/ast.h"
|
|
9
10
|
#include "rbs/defines.h"
|
|
11
|
+
#include "rbs/lexer.h"
|
|
12
|
+
#include "rbs/location.h"
|
|
10
13
|
#include "rbs/string.h"
|
|
11
14
|
#include "rbs/util/rbs_unescape.h"
|
|
12
15
|
#include "rbs/util/rbs_buffer.h"
|
|
13
16
|
#include "rbs/util/rbs_assert.h"
|
|
14
17
|
|
|
15
|
-
#define
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
(const uint8_t *)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
#define INTERN_TOKEN(parser, tok) \
|
|
23
|
-
rbs_constant_pool_insert_shared_with_encoding( \
|
|
24
|
-
&parser->constant_pool, \
|
|
25
|
-
(const uint8_t *) rbs_peek_token(parser->rbs_lexer_t, tok), \
|
|
26
|
-
rbs_token_bytes(tok), \
|
|
27
|
-
(void *) parser->rbs_lexer_t->encoding \
|
|
18
|
+
#define INTERN_TOKEN(parser, tok) \
|
|
19
|
+
rbs_constant_pool_insert_shared_with_encoding( \
|
|
20
|
+
&parser->constant_pool, \
|
|
21
|
+
(const uint8_t *) rbs_peek_token(parser->lexer, tok), \
|
|
22
|
+
rbs_token_bytes(tok), \
|
|
23
|
+
parser->lexer->encoding \
|
|
28
24
|
)
|
|
29
25
|
|
|
30
26
|
#define KEYWORD_CASES \
|
|
@@ -64,6 +60,41 @@
|
|
|
64
60
|
case kRETURN: \
|
|
65
61
|
/* nop */
|
|
66
62
|
|
|
63
|
+
#define PARAM_NAME_CASES \
|
|
64
|
+
case kBOOL: \
|
|
65
|
+
case kBOT: \
|
|
66
|
+
case kCLASS: \
|
|
67
|
+
case kFALSE: \
|
|
68
|
+
case kINSTANCE: \
|
|
69
|
+
case kINTERFACE: \
|
|
70
|
+
case kNIL: \
|
|
71
|
+
case kSELF: \
|
|
72
|
+
case kSINGLETON: \
|
|
73
|
+
case kTOP: \
|
|
74
|
+
case kTRUE: \
|
|
75
|
+
case kVOID: \
|
|
76
|
+
case kTYPE: \
|
|
77
|
+
case kUNCHECKED: \
|
|
78
|
+
case kIN: \
|
|
79
|
+
case kOUT: \
|
|
80
|
+
case kEND: \
|
|
81
|
+
case kDEF: \
|
|
82
|
+
case kINCLUDE: \
|
|
83
|
+
case kEXTEND: \
|
|
84
|
+
case kPREPEND: \
|
|
85
|
+
case kALIAS: \
|
|
86
|
+
case kMODULE: \
|
|
87
|
+
case kATTRREADER: \
|
|
88
|
+
case kATTRWRITER: \
|
|
89
|
+
case kATTRACCESSOR: \
|
|
90
|
+
case kPUBLIC: \
|
|
91
|
+
case kPRIVATE: \
|
|
92
|
+
case kUNTYPED: \
|
|
93
|
+
case kUSE: \
|
|
94
|
+
case kAS: \
|
|
95
|
+
case k__TODO__: \
|
|
96
|
+
/* nop */
|
|
97
|
+
|
|
67
98
|
#define CHECK_PARSE(call) \
|
|
68
99
|
if (!call) { \
|
|
69
100
|
return false; \
|
|
@@ -110,18 +141,12 @@ static bool rbs_is_untyped_params(method_params *params) {
|
|
|
110
141
|
return params->required_positionals == NULL;
|
|
111
142
|
}
|
|
112
143
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
*
|
|
116
|
-
* @param parser
|
|
117
|
-
* @return New RBS::Location object.
|
|
118
|
-
* */
|
|
119
|
-
static rbs_location_t *rbs_location_current_token(rbs_parser_t *parser) {
|
|
120
|
-
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);
|
|
121
146
|
}
|
|
122
147
|
|
|
123
|
-
static bool parse_optional(rbs_parser_t *parser, rbs_node_t **optional);
|
|
124
|
-
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);
|
|
125
150
|
|
|
126
151
|
/**
|
|
127
152
|
* @returns A borrowed copy of the current token, which does *not* need to be freed.
|
|
@@ -129,7 +154,7 @@ static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type);
|
|
|
129
154
|
static rbs_string_t rbs_parser_peek_current_token(rbs_parser_t *parser) {
|
|
130
155
|
rbs_range_t rg = parser->current_token.range;
|
|
131
156
|
|
|
132
|
-
const char *start = parser->
|
|
157
|
+
const char *start = parser->lexer->string.start + rg.start.byte_pos;
|
|
133
158
|
size_t length = rg.end.byte_pos - rg.start.byte_pos;
|
|
134
159
|
|
|
135
160
|
return rbs_string_new(start, start + length);
|
|
@@ -177,8 +202,8 @@ static bool parse_type_name(rbs_parser_t *parser, TypeNameKind kind, rbs_range_t
|
|
|
177
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
|
|
178
203
|
) {
|
|
179
204
|
rbs_constant_id_t symbol_value = INTERN_TOKEN(parser, parser->current_token);
|
|
180
|
-
|
|
181
|
-
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);
|
|
182
207
|
rbs_node_list_append(path, (rbs_node_t *) symbol);
|
|
183
208
|
|
|
184
209
|
rbs_parser_advance(parser);
|
|
@@ -189,8 +214,7 @@ static bool parse_type_name(rbs_parser_t *parser, TypeNameKind kind, rbs_range_t
|
|
|
189
214
|
.start = rg->start,
|
|
190
215
|
.end = parser->current_token.range.end
|
|
191
216
|
};
|
|
192
|
-
|
|
193
|
-
rbs_namespace_t *namespace = rbs_namespace_new(ALLOCATOR(), loc, path, absolute);
|
|
217
|
+
rbs_namespace_t *ns = rbs_namespace_new(ALLOCATOR(), RBS_RANGE_LEX2AST(namespace_range), path, absolute);
|
|
194
218
|
|
|
195
219
|
switch (parser->current_token.type) {
|
|
196
220
|
case tLIDENT:
|
|
@@ -213,10 +237,10 @@ success: {
|
|
|
213
237
|
rg->end = parser->current_token.range.end;
|
|
214
238
|
}
|
|
215
239
|
|
|
216
|
-
|
|
240
|
+
rbs_location_range symbol_range = rbs_location_range_current_token(parser);
|
|
217
241
|
rbs_constant_id_t name = INTERN_TOKEN(parser, parser->current_token);
|
|
218
|
-
rbs_ast_symbol_t *symbol = rbs_ast_symbol_new(ALLOCATOR(),
|
|
219
|
-
*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);
|
|
220
244
|
return true;
|
|
221
245
|
}
|
|
222
246
|
|
|
@@ -232,7 +256,7 @@ error_handling: {
|
|
|
232
256
|
ids = "class/module/constant name";
|
|
233
257
|
}
|
|
234
258
|
|
|
235
|
-
|
|
259
|
+
RBS_ASSERT(ids != NULL, "Unknown kind of type: %i", kind);
|
|
236
260
|
|
|
237
261
|
rbs_parser_set_error(parser, parser->current_token, true, "expected one of %s", ids);
|
|
238
262
|
return false;
|
|
@@ -244,10 +268,10 @@ error_handling: {
|
|
|
244
268
|
| {} type `,` ... `,` <type> eol
|
|
245
269
|
*/
|
|
246
270
|
NODISCARD
|
|
247
|
-
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) {
|
|
248
272
|
while (true) {
|
|
249
273
|
rbs_node_t *type;
|
|
250
|
-
CHECK_PARSE(rbs_parse_type(parser, &type));
|
|
274
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, void_allowed, self_allowed, classish_allowed));
|
|
251
275
|
rbs_node_list_append(types, type);
|
|
252
276
|
|
|
253
277
|
if (parser->next_token.type == pCOMMA) {
|
|
@@ -269,6 +293,43 @@ static bool parse_type_list(rbs_parser_t *parser, enum RBSTokenType eol, rbs_nod
|
|
|
269
293
|
return true;
|
|
270
294
|
}
|
|
271
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) {
|
|
302
|
+
while (true) {
|
|
303
|
+
rbs_node_t *type;
|
|
304
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, void_allowed, self_allowed, classish_allowed));
|
|
305
|
+
rbs_node_list_append(types, type);
|
|
306
|
+
|
|
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);
|
|
310
|
+
rbs_parser_advance(parser);
|
|
311
|
+
|
|
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
|
+
}
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
} else {
|
|
321
|
+
if (parser->next_token.type == eol) {
|
|
322
|
+
break;
|
|
323
|
+
} else {
|
|
324
|
+
rbs_parser_set_error(parser, parser->next_token, true, "comma delimited type list is expected");
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return true;
|
|
331
|
+
}
|
|
332
|
+
|
|
272
333
|
static bool is_keyword_token(enum RBSTokenType type) {
|
|
273
334
|
switch (type) {
|
|
274
335
|
case tLIDENT:
|
|
@@ -289,21 +350,17 @@ static bool is_keyword_token(enum RBSTokenType type) {
|
|
|
289
350
|
| {} type <param>
|
|
290
351
|
*/
|
|
291
352
|
NODISCARD
|
|
292
|
-
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) {
|
|
293
354
|
rbs_range_t type_range;
|
|
294
355
|
type_range.start = parser->next_token.range.start;
|
|
295
356
|
rbs_node_t *type;
|
|
296
|
-
CHECK_PARSE(rbs_parse_type(parser, &type));
|
|
357
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, false, self_allowed, classish_allowed));
|
|
297
358
|
type_range.end = parser->current_token.range.end;
|
|
298
359
|
|
|
299
360
|
if (parser->next_token.type == pCOMMA || parser->next_token.type == pRPAREN) {
|
|
300
361
|
rbs_range_t param_range = type_range;
|
|
301
362
|
|
|
302
|
-
|
|
303
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 1);
|
|
304
|
-
rbs_loc_add_optional_child(loc, INTERN("name"), NULL_RANGE);
|
|
305
|
-
|
|
306
|
-
*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);
|
|
307
364
|
return true;
|
|
308
365
|
} else {
|
|
309
366
|
rbs_range_t name_range = parser->next_token.range;
|
|
@@ -320,16 +377,13 @@ static bool parse_function_param(rbs_parser_t *parser, rbs_types_function_param_
|
|
|
320
377
|
return false;
|
|
321
378
|
}
|
|
322
379
|
|
|
323
|
-
rbs_string_t unquoted_str = rbs_unquote_string(ALLOCATOR(), rbs_parser_peek_current_token(parser));
|
|
324
|
-
|
|
380
|
+
rbs_string_t unquoted_str = rbs_unquote_string(ALLOCATOR(), rbs_parser_peek_current_token(parser), parser->lexer->encoding);
|
|
381
|
+
rbs_location_range symbol_range = rbs_location_range_current_token(parser);
|
|
325
382
|
rbs_constant_id_t constant_id = rbs_constant_pool_insert_string(&parser->constant_pool, unquoted_str);
|
|
326
|
-
rbs_ast_symbol_t *name = rbs_ast_symbol_new(ALLOCATOR(),
|
|
327
|
-
|
|
328
|
-
rbs_location_t *loc = rbs_location_new(ALLOCATOR(), param_range);
|
|
329
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 1);
|
|
330
|
-
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);
|
|
331
384
|
|
|
332
|
-
*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);
|
|
333
387
|
return true;
|
|
334
388
|
}
|
|
335
389
|
}
|
|
@@ -337,9 +391,9 @@ static bool parse_function_param(rbs_parser_t *parser, rbs_types_function_param_
|
|
|
337
391
|
static rbs_constant_id_t intern_token_start_end(rbs_parser_t *parser, rbs_token_t start_token, rbs_token_t end_token) {
|
|
338
392
|
return rbs_constant_pool_insert_shared_with_encoding(
|
|
339
393
|
&parser->constant_pool,
|
|
340
|
-
(const uint8_t *) rbs_peek_token(parser->
|
|
394
|
+
(const uint8_t *) rbs_peek_token(parser->lexer, start_token),
|
|
341
395
|
end_token.range.end.byte_pos - start_token.range.start.byte_pos,
|
|
342
|
-
parser->
|
|
396
|
+
parser->lexer->encoding
|
|
343
397
|
);
|
|
344
398
|
}
|
|
345
399
|
|
|
@@ -351,18 +405,18 @@ NODISCARD
|
|
|
351
405
|
static bool parse_keyword_key(rbs_parser_t *parser, rbs_ast_symbol_t **key) {
|
|
352
406
|
rbs_parser_advance(parser);
|
|
353
407
|
|
|
354
|
-
|
|
408
|
+
rbs_location_range symbol_range = rbs_location_range_current_token(parser);
|
|
355
409
|
|
|
356
410
|
if (parser->next_token.type == pQUESTION) {
|
|
357
411
|
*key = rbs_ast_symbol_new(
|
|
358
412
|
ALLOCATOR(),
|
|
359
|
-
|
|
413
|
+
symbol_range,
|
|
360
414
|
&parser->constant_pool,
|
|
361
415
|
intern_token_start_end(parser, parser->current_token, parser->next_token)
|
|
362
416
|
);
|
|
363
417
|
rbs_parser_advance(parser);
|
|
364
418
|
} else {
|
|
365
|
-
*key = rbs_ast_symbol_new(ALLOCATOR(),
|
|
419
|
+
*key = rbs_ast_symbol_new(ALLOCATOR(), symbol_range, &parser->constant_pool, INTERN_TOKEN(parser, parser->current_token));
|
|
366
420
|
}
|
|
367
421
|
|
|
368
422
|
return true;
|
|
@@ -372,7 +426,7 @@ static bool parse_keyword_key(rbs_parser_t *parser, rbs_ast_symbol_t **key) {
|
|
|
372
426
|
keyword ::= {} keyword `:` <function_param>
|
|
373
427
|
*/
|
|
374
428
|
NODISCARD
|
|
375
|
-
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) {
|
|
376
430
|
rbs_ast_symbol_t *key = NULL;
|
|
377
431
|
CHECK_PARSE(parse_keyword_key(parser, &key));
|
|
378
432
|
|
|
@@ -380,13 +434,13 @@ static bool parse_keyword(rbs_parser_t *parser, rbs_hash_t *keywords, rbs_hash_t
|
|
|
380
434
|
rbs_parser_set_error(parser, parser->current_token, true, "duplicated keyword argument");
|
|
381
435
|
return false;
|
|
382
436
|
} else {
|
|
383
|
-
|
|
384
|
-
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));
|
|
385
439
|
}
|
|
386
440
|
|
|
387
441
|
ADVANCE_ASSERT(parser, pCOLON);
|
|
388
442
|
rbs_types_function_param_t *param = NULL;
|
|
389
|
-
CHECK_PARSE(parse_function_param(parser, ¶m));
|
|
443
|
+
CHECK_PARSE(parse_function_param(parser, ¶m, self_allowed, classish_allowed));
|
|
390
444
|
|
|
391
445
|
rbs_hash_set(keywords, (rbs_node_t *) key, (rbs_node_t *) param);
|
|
392
446
|
|
|
@@ -457,7 +511,7 @@ static bool parser_advance_if(rbs_parser_t *parser, enum RBSTokenType type) {
|
|
|
457
511
|
| {} `**` <function_param>
|
|
458
512
|
*/
|
|
459
513
|
NODISCARD
|
|
460
|
-
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) {
|
|
461
515
|
if (parser->next_token.type == pQUESTION && parser->next_token2.type == pRPAREN) {
|
|
462
516
|
params->required_positionals = NULL;
|
|
463
517
|
rbs_parser_advance(parser);
|
|
@@ -486,7 +540,7 @@ static bool parse_params(rbs_parser_t *parser, method_params *params) {
|
|
|
486
540
|
}
|
|
487
541
|
|
|
488
542
|
rbs_types_function_param_t *param = NULL;
|
|
489
|
-
CHECK_PARSE(parse_function_param(parser, ¶m));
|
|
543
|
+
CHECK_PARSE(parse_function_param(parser, ¶m, self_allowed, classish_allowed));
|
|
490
544
|
rbs_node_list_append(params->required_positionals, (rbs_node_t *) param);
|
|
491
545
|
|
|
492
546
|
break;
|
|
@@ -500,20 +554,21 @@ static bool parse_params(rbs_parser_t *parser, method_params *params) {
|
|
|
500
554
|
PARSE_OPTIONAL_PARAMS:
|
|
501
555
|
while (true) {
|
|
502
556
|
switch (parser->next_token.type) {
|
|
503
|
-
case pQUESTION:
|
|
557
|
+
case pQUESTION: {
|
|
504
558
|
rbs_parser_advance(parser);
|
|
505
559
|
|
|
506
560
|
if (is_keyword(parser)) {
|
|
507
|
-
CHECK_PARSE(parse_keyword(parser, params->optional_keywords, memo));
|
|
561
|
+
CHECK_PARSE(parse_keyword(parser, params->optional_keywords, memo, self_allowed, classish_allowed));
|
|
508
562
|
parser_advance_if(parser, pCOMMA);
|
|
509
563
|
goto PARSE_KEYWORDS;
|
|
510
564
|
}
|
|
511
565
|
|
|
512
566
|
rbs_types_function_param_t *param = NULL;
|
|
513
|
-
CHECK_PARSE(parse_function_param(parser, ¶m));
|
|
567
|
+
CHECK_PARSE(parse_function_param(parser, ¶m, self_allowed, classish_allowed));
|
|
514
568
|
rbs_node_list_append(params->optional_positionals, (rbs_node_t *) param);
|
|
515
569
|
|
|
516
570
|
break;
|
|
571
|
+
}
|
|
517
572
|
default:
|
|
518
573
|
goto PARSE_REST_PARAM;
|
|
519
574
|
}
|
|
@@ -527,7 +582,7 @@ PARSE_REST_PARAM:
|
|
|
527
582
|
if (parser->next_token.type == pSTAR) {
|
|
528
583
|
rbs_parser_advance(parser);
|
|
529
584
|
rbs_types_function_param_t *param = NULL;
|
|
530
|
-
CHECK_PARSE(parse_function_param(parser, ¶m));
|
|
585
|
+
CHECK_PARSE(parse_function_param(parser, ¶m, self_allowed, classish_allowed));
|
|
531
586
|
params->rest_positionals = (rbs_node_t *) param;
|
|
532
587
|
|
|
533
588
|
if (!parser_advance_if(parser, pCOMMA)) {
|
|
@@ -554,7 +609,7 @@ PARSE_TRAILING_PARAMS:
|
|
|
554
609
|
}
|
|
555
610
|
|
|
556
611
|
rbs_types_function_param_t *param = NULL;
|
|
557
|
-
CHECK_PARSE(parse_function_param(parser, ¶m));
|
|
612
|
+
CHECK_PARSE(parse_function_param(parser, ¶m, self_allowed, classish_allowed));
|
|
558
613
|
rbs_node_list_append(params->trailing_positionals, (rbs_node_t *) param);
|
|
559
614
|
|
|
560
615
|
break;
|
|
@@ -571,20 +626,20 @@ PARSE_KEYWORDS:
|
|
|
571
626
|
case pQUESTION:
|
|
572
627
|
rbs_parser_advance(parser);
|
|
573
628
|
if (is_keyword(parser)) {
|
|
574
|
-
CHECK_PARSE(parse_keyword(parser, params->optional_keywords, memo));
|
|
629
|
+
CHECK_PARSE(parse_keyword(parser, params->optional_keywords, memo, self_allowed, classish_allowed));
|
|
575
630
|
} else {
|
|
576
631
|
rbs_parser_set_error(parser, parser->next_token, true, "optional keyword argument type is expected");
|
|
577
632
|
return false;
|
|
578
633
|
}
|
|
579
634
|
break;
|
|
580
635
|
|
|
581
|
-
case pSTAR2:
|
|
636
|
+
case pSTAR2: {
|
|
582
637
|
rbs_parser_advance(parser);
|
|
583
638
|
rbs_types_function_param_t *param = NULL;
|
|
584
|
-
CHECK_PARSE(parse_function_param(parser, ¶m));
|
|
639
|
+
CHECK_PARSE(parse_function_param(parser, ¶m, self_allowed, classish_allowed));
|
|
585
640
|
params->rest_keywords = (rbs_node_t *) param;
|
|
586
641
|
break;
|
|
587
|
-
|
|
642
|
+
}
|
|
588
643
|
case tUIDENT:
|
|
589
644
|
case tLIDENT:
|
|
590
645
|
case tQIDENT:
|
|
@@ -593,7 +648,7 @@ PARSE_KEYWORDS:
|
|
|
593
648
|
case tBANGIDENT:
|
|
594
649
|
KEYWORD_CASES
|
|
595
650
|
if (is_keyword(parser)) {
|
|
596
|
-
CHECK_PARSE(parse_keyword(parser, params->required_keywords, memo));
|
|
651
|
+
CHECK_PARSE(parse_keyword(parser, params->required_keywords, memo, self_allowed, classish_allowed));
|
|
597
652
|
} else {
|
|
598
653
|
rbs_parser_set_error(parser, parser->next_token, true, "required keyword argument type is expected");
|
|
599
654
|
return false;
|
|
@@ -623,18 +678,22 @@ EOP:
|
|
|
623
678
|
| {} simple_type <`?`>
|
|
624
679
|
*/
|
|
625
680
|
NODISCARD
|
|
626
|
-
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) {
|
|
627
682
|
rbs_range_t rg;
|
|
628
683
|
rg.start = parser->next_token.range.start;
|
|
629
684
|
|
|
630
685
|
rbs_node_t *type = NULL;
|
|
631
|
-
CHECK_PARSE(parse_simple(parser, &type));
|
|
686
|
+
CHECK_PARSE(parse_simple(parser, &type, void_allowed, self_allowed, classish_allowed));
|
|
632
687
|
|
|
633
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
|
+
|
|
634
694
|
rbs_parser_advance(parser);
|
|
635
695
|
rg.end = parser->current_token.range.end;
|
|
636
|
-
|
|
637
|
-
*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);
|
|
638
697
|
} else {
|
|
639
698
|
*optional = type;
|
|
640
699
|
}
|
|
@@ -659,13 +718,13 @@ static void initialize_method_params(method_params *params, rbs_allocator_t *all
|
|
|
659
718
|
| {} `[` `self` `:` type <`]`>
|
|
660
719
|
*/
|
|
661
720
|
NODISCARD
|
|
662
|
-
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) {
|
|
663
722
|
if (parser->next_token.type == pLBRACKET) {
|
|
664
723
|
rbs_parser_advance(parser);
|
|
665
724
|
ADVANCE_ASSERT(parser, kSELF);
|
|
666
725
|
ADVANCE_ASSERT(parser, pCOLON);
|
|
667
726
|
rbs_node_t *type;
|
|
668
|
-
CHECK_PARSE(rbs_parse_type(parser, &type));
|
|
727
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, false, self_allowed, classish_allowed));
|
|
669
728
|
ADVANCE_ASSERT(parser, pRBRACKET);
|
|
670
729
|
*self_type = type;
|
|
671
730
|
}
|
|
@@ -687,7 +746,7 @@ typedef struct {
|
|
|
687
746
|
| {} self_type_binding? `->` <optional>
|
|
688
747
|
*/
|
|
689
748
|
NODISCARD
|
|
690
|
-
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) {
|
|
691
750
|
rbs_node_t *function = NULL;
|
|
692
751
|
rbs_types_block_t *block = NULL;
|
|
693
752
|
rbs_node_t *function_self_type = NULL;
|
|
@@ -699,13 +758,13 @@ static bool parse_function(rbs_parser_t *parser, bool accept_type_binding, parse
|
|
|
699
758
|
|
|
700
759
|
if (parser->next_token.type == pLPAREN) {
|
|
701
760
|
rbs_parser_advance(parser);
|
|
702
|
-
CHECK_PARSE(parse_params(parser, ¶ms));
|
|
761
|
+
CHECK_PARSE(parse_params(parser, ¶ms, self_allowed, classish_allowed));
|
|
703
762
|
ADVANCE_ASSERT(parser, pRPAREN);
|
|
704
763
|
}
|
|
705
764
|
|
|
706
765
|
// Passing NULL to function_self_type means the function itself doesn't accept self type binding. (== method type)
|
|
707
766
|
if (accept_type_binding) {
|
|
708
|
-
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));
|
|
709
768
|
} else {
|
|
710
769
|
if (rbs_is_untyped_params(¶ms)) {
|
|
711
770
|
if (parser->next_token.type != pARROW) {
|
|
@@ -718,6 +777,11 @@ static bool parse_function(rbs_parser_t *parser, bool accept_type_binding, parse
|
|
|
718
777
|
bool required = true;
|
|
719
778
|
rbs_range_t block_range;
|
|
720
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
|
+
|
|
721
785
|
if (parser->next_token.type == pQUESTION && parser->next_token2.type == pLBRACE) {
|
|
722
786
|
// Optional block
|
|
723
787
|
block_range.start = parser->next_token.range.start;
|
|
@@ -735,29 +799,28 @@ static bool parse_function(rbs_parser_t *parser, bool accept_type_binding, parse
|
|
|
735
799
|
|
|
736
800
|
if (parser->next_token.type == pLPAREN) {
|
|
737
801
|
rbs_parser_advance(parser);
|
|
738
|
-
CHECK_PARSE(parse_params(parser, &block_params));
|
|
802
|
+
CHECK_PARSE(parse_params(parser, &block_params, self_allowed, classish_allowed));
|
|
739
803
|
ADVANCE_ASSERT(parser, pRPAREN);
|
|
740
804
|
}
|
|
741
805
|
|
|
742
806
|
rbs_node_t *self_type = NULL;
|
|
743
|
-
CHECK_PARSE(parse_self_type_binding(parser, &self_type));
|
|
807
|
+
CHECK_PARSE(parse_self_type_binding(parser, &self_type, self_allowed, classish_allowed));
|
|
744
808
|
|
|
745
809
|
ADVANCE_ASSERT(parser, pARROW);
|
|
746
810
|
rbs_node_t *block_return_type = NULL;
|
|
747
|
-
CHECK_PARSE(parse_optional(parser, &block_return_type));
|
|
811
|
+
CHECK_PARSE(parse_optional(parser, &block_return_type, true, self_allowed, classish_allowed));
|
|
748
812
|
|
|
749
813
|
ADVANCE_ASSERT(parser, pRBRACE);
|
|
750
814
|
|
|
751
815
|
block_range.end = parser->current_token.range.end;
|
|
752
|
-
rbs_location_t *loc = rbs_location_new(ALLOCATOR(), block_range);
|
|
753
816
|
|
|
754
817
|
rbs_node_t *block_function = NULL;
|
|
755
818
|
if (rbs_is_untyped_params(&block_params)) {
|
|
756
|
-
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);
|
|
757
820
|
} else {
|
|
758
821
|
block_function = (rbs_node_t *) rbs_types_function_new(
|
|
759
822
|
ALLOCATOR(),
|
|
760
|
-
|
|
823
|
+
RBS_RANGE_LEX2AST(block_range),
|
|
761
824
|
block_params.required_positionals,
|
|
762
825
|
block_params.optional_positionals,
|
|
763
826
|
block_params.rest_positionals,
|
|
@@ -769,21 +832,20 @@ static bool parse_function(rbs_parser_t *parser, bool accept_type_binding, parse
|
|
|
769
832
|
);
|
|
770
833
|
}
|
|
771
834
|
|
|
772
|
-
block = rbs_types_block_new(ALLOCATOR(),
|
|
835
|
+
block = rbs_types_block_new(ALLOCATOR(), RBS_RANGE_LEX2AST(block_range), block_function, required, self_type);
|
|
773
836
|
}
|
|
774
837
|
|
|
775
838
|
ADVANCE_ASSERT(parser, pARROW);
|
|
776
839
|
rbs_node_t *type = NULL;
|
|
777
|
-
CHECK_PARSE(parse_optional(parser, &type));
|
|
840
|
+
CHECK_PARSE(parse_optional(parser, &type, true, self_allowed, classish_allowed));
|
|
778
841
|
|
|
779
842
|
function_range.end = parser->current_token.range.end;
|
|
780
|
-
rbs_location_t *loc = rbs_location_new(ALLOCATOR(), function_range);
|
|
781
843
|
if (rbs_is_untyped_params(¶ms)) {
|
|
782
|
-
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);
|
|
783
845
|
} else {
|
|
784
846
|
function = (rbs_node_t *) rbs_types_function_new(
|
|
785
847
|
ALLOCATOR(),
|
|
786
|
-
|
|
848
|
+
RBS_RANGE_LEX2AST(function_range),
|
|
787
849
|
params.required_positionals,
|
|
788
850
|
params.optional_positionals,
|
|
789
851
|
params.rest_positionals,
|
|
@@ -805,14 +867,14 @@ static bool parse_function(rbs_parser_t *parser, bool accept_type_binding, parse
|
|
|
805
867
|
proc_type ::= {`^`} <function>
|
|
806
868
|
*/
|
|
807
869
|
NODISCARD
|
|
808
|
-
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) {
|
|
809
871
|
rbs_position_t start = parser->current_token.range.start;
|
|
810
872
|
parse_function_result *result = rbs_allocator_alloc(ALLOCATOR(), parse_function_result);
|
|
811
|
-
CHECK_PARSE(parse_function(parser, true, &result));
|
|
873
|
+
CHECK_PARSE(parse_function(parser, true, true, &result, self_allowed, classish_allowed));
|
|
812
874
|
|
|
813
875
|
rbs_position_t end = parser->current_token.range.end;
|
|
814
|
-
|
|
815
|
-
*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);
|
|
816
878
|
return true;
|
|
817
879
|
}
|
|
818
880
|
|
|
@@ -833,7 +895,7 @@ static void check_key_duplication(rbs_parser_t *parser, rbs_hash_t *fields, rbs_
|
|
|
833
895
|
| {} literal_type `=>` <type>
|
|
834
896
|
*/
|
|
835
897
|
NODISCARD
|
|
836
|
-
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) {
|
|
837
899
|
*fields = rbs_hash_new(ALLOCATOR());
|
|
838
900
|
|
|
839
901
|
if (parser->next_token.type == pRBRACE) return true;
|
|
@@ -866,7 +928,7 @@ static bool parse_record_attributes(rbs_parser_t *parser, rbs_hash_t **fields) {
|
|
|
866
928
|
case kTRUE:
|
|
867
929
|
case kFALSE: {
|
|
868
930
|
rbs_node_t *type = NULL;
|
|
869
|
-
CHECK_PARSE(parse_simple(parser, &type));
|
|
931
|
+
CHECK_PARSE(parse_simple(parser, &type, false, self_allowed, classish_allowed));
|
|
870
932
|
|
|
871
933
|
key = (rbs_ast_symbol_t *) ((rbs_types_literal_t *) type)->literal;
|
|
872
934
|
break;
|
|
@@ -883,11 +945,10 @@ static bool parse_record_attributes(rbs_parser_t *parser, rbs_hash_t **fields) {
|
|
|
883
945
|
field_range.start = parser->current_token.range.end;
|
|
884
946
|
|
|
885
947
|
rbs_node_t *type;
|
|
886
|
-
CHECK_PARSE(rbs_parse_type(parser, &type));
|
|
948
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, false, self_allowed, classish_allowed));
|
|
887
949
|
|
|
888
950
|
field_range.end = parser->current_token.range.end;
|
|
889
|
-
|
|
890
|
-
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));
|
|
891
952
|
|
|
892
953
|
if (parser_advance_if(parser, pCOMMA)) {
|
|
893
954
|
if (parser->next_token.type == pRBRACE) {
|
|
@@ -904,37 +965,37 @@ static bool parse_record_attributes(rbs_parser_t *parser, rbs_hash_t **fields) {
|
|
|
904
965
|
symbol ::= {<tSYMBOL>}
|
|
905
966
|
*/
|
|
906
967
|
NODISCARD
|
|
907
|
-
static bool parse_symbol(rbs_parser_t *parser,
|
|
908
|
-
size_t offset_bytes = parser->
|
|
968
|
+
static bool parse_symbol(rbs_parser_t *parser, rbs_location_range location, rbs_types_literal_t **symbol) {
|
|
969
|
+
size_t offset_bytes = parser->lexer->encoding->char_width((const uint8_t *) ":", (size_t) 1);
|
|
909
970
|
size_t bytes = rbs_token_bytes(parser->current_token) - offset_bytes;
|
|
910
971
|
|
|
911
972
|
rbs_ast_symbol_t *literal;
|
|
912
973
|
|
|
913
974
|
switch (parser->current_token.type) {
|
|
914
975
|
case tSYMBOL: {
|
|
915
|
-
|
|
976
|
+
rbs_location_range symbol_range = rbs_location_range_current_token(parser);
|
|
916
977
|
|
|
917
|
-
char *buffer = rbs_peek_token(parser->
|
|
978
|
+
char *buffer = rbs_peek_token(parser->lexer, parser->current_token);
|
|
918
979
|
rbs_constant_id_t constant_id = rbs_constant_pool_insert_shared(
|
|
919
980
|
&parser->constant_pool,
|
|
920
981
|
(const uint8_t *) buffer + offset_bytes,
|
|
921
982
|
bytes
|
|
922
983
|
);
|
|
923
|
-
literal = rbs_ast_symbol_new(ALLOCATOR(),
|
|
984
|
+
literal = rbs_ast_symbol_new(ALLOCATOR(), symbol_range, &parser->constant_pool, constant_id);
|
|
924
985
|
break;
|
|
925
986
|
}
|
|
926
987
|
case tDQSYMBOL:
|
|
927
988
|
case tSQSYMBOL: {
|
|
928
|
-
|
|
989
|
+
rbs_location_range symbol_range = rbs_location_range_current_token(parser);
|
|
929
990
|
rbs_string_t current_token = rbs_parser_peek_current_token(parser);
|
|
930
991
|
|
|
931
992
|
rbs_string_t symbol = rbs_string_new(current_token.start + offset_bytes, current_token.end);
|
|
932
993
|
|
|
933
|
-
rbs_string_t unquoted_symbol = rbs_unquote_string(ALLOCATOR(), symbol);
|
|
994
|
+
rbs_string_t unquoted_symbol = rbs_unquote_string(ALLOCATOR(), symbol, parser->lexer->encoding);
|
|
934
995
|
|
|
935
996
|
rbs_constant_id_t constant_id = rbs_constant_pool_insert_string(&parser->constant_pool, unquoted_symbol);
|
|
936
997
|
|
|
937
|
-
literal = rbs_ast_symbol_new(ALLOCATOR(),
|
|
998
|
+
literal = rbs_ast_symbol_new(ALLOCATOR(), symbol_range, &parser->constant_pool, constant_id);
|
|
938
999
|
break;
|
|
939
1000
|
}
|
|
940
1001
|
default:
|
|
@@ -954,9 +1015,9 @@ static bool parse_symbol(rbs_parser_t *parser, rbs_location_t *location, rbs_typ
|
|
|
954
1015
|
*/
|
|
955
1016
|
NODISCARD
|
|
956
1017
|
static bool parse_instance_type(rbs_parser_t *parser, bool parse_alias, rbs_node_t **type) {
|
|
957
|
-
TypeNameKind expected_kind = INTERFACE_NAME | CLASS_NAME;
|
|
1018
|
+
TypeNameKind expected_kind = (TypeNameKind) (INTERFACE_NAME | CLASS_NAME);
|
|
958
1019
|
if (parse_alias) {
|
|
959
|
-
expected_kind
|
|
1020
|
+
expected_kind = (TypeNameKind) (expected_kind | ALIAS_NAME);
|
|
960
1021
|
}
|
|
961
1022
|
|
|
962
1023
|
rbs_range_t name_range;
|
|
@@ -990,7 +1051,7 @@ static bool parse_instance_type(rbs_parser_t *parser, bool parse_alias, rbs_node
|
|
|
990
1051
|
if (parser->next_token.type == pLBRACKET) {
|
|
991
1052
|
rbs_parser_advance(parser);
|
|
992
1053
|
args_range.start = parser->current_token.range.start;
|
|
993
|
-
CHECK_PARSE(parse_type_list(parser, pRBRACKET, types));
|
|
1054
|
+
CHECK_PARSE(parse_type_list(parser, pRBRACKET, types, true, true, true));
|
|
994
1055
|
ADVANCE_ASSERT(parser, pRBRACKET);
|
|
995
1056
|
args_range.end = parser->current_token.range.end;
|
|
996
1057
|
} else {
|
|
@@ -1002,27 +1063,30 @@ static bool parse_instance_type(rbs_parser_t *parser, bool parse_alias, rbs_node
|
|
|
1002
1063
|
.end = rbs_nonnull_pos_or(args_range.end, name_range.end),
|
|
1003
1064
|
};
|
|
1004
1065
|
|
|
1005
|
-
|
|
1006
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 2);
|
|
1007
|
-
rbs_loc_add_required_child(loc, INTERN("name"), name_range);
|
|
1008
|
-
rbs_loc_add_optional_child(loc, INTERN("args"), args_range);
|
|
1066
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(type_range);
|
|
1009
1067
|
|
|
1010
1068
|
if (kind == CLASS_NAME) {
|
|
1011
|
-
*
|
|
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;
|
|
1012
1072
|
} else if (kind == INTERFACE_NAME) {
|
|
1013
|
-
*
|
|
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;
|
|
1014
1076
|
} else if (kind == ALIAS_NAME) {
|
|
1015
|
-
*
|
|
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;
|
|
1016
1080
|
}
|
|
1017
1081
|
|
|
1018
1082
|
return true;
|
|
1019
1083
|
}
|
|
1020
1084
|
|
|
1021
1085
|
/*
|
|
1022
|
-
singleton_type ::= {`singleton`} `(` type_name <`)`>
|
|
1086
|
+
singleton_type ::= {`singleton`} `(` type_name <`)`> type_args?
|
|
1023
1087
|
*/
|
|
1024
1088
|
NODISCARD
|
|
1025
|
-
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) {
|
|
1026
1090
|
ASSERT_TOKEN(parser, kSINGLETON);
|
|
1027
1091
|
|
|
1028
1092
|
rbs_range_t type_range;
|
|
@@ -1035,13 +1099,26 @@ static bool parse_singleton_type(rbs_parser_t *parser, rbs_types_class_singleton
|
|
|
1035
1099
|
CHECK_PARSE(parse_type_name(parser, CLASS_NAME, &name_range, &type_name));
|
|
1036
1100
|
|
|
1037
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
|
+
|
|
1038
1116
|
type_range.end = parser->current_token.range.end;
|
|
1117
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(type_range);
|
|
1039
1118
|
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
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;
|
|
1043
1121
|
|
|
1044
|
-
*singleton = rbs_types_class_singleton_new(ALLOCATOR(), loc, type_name);
|
|
1045
1122
|
return true;
|
|
1046
1123
|
}
|
|
1047
1124
|
|
|
@@ -1077,69 +1154,89 @@ static bool parser_typevar_member(rbs_parser_t *parser, rbs_constant_id_t id) {
|
|
|
1077
1154
|
| {} `^` <function>
|
|
1078
1155
|
*/
|
|
1079
1156
|
NODISCARD
|
|
1080
|
-
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) {
|
|
1081
1158
|
rbs_parser_advance(parser);
|
|
1082
1159
|
|
|
1083
1160
|
switch (parser->current_token.type) {
|
|
1084
1161
|
case pLPAREN: {
|
|
1085
1162
|
rbs_node_t *lparen_type;
|
|
1086
|
-
CHECK_PARSE(rbs_parse_type(parser, &lparen_type));
|
|
1163
|
+
CHECK_PARSE(rbs_parse_type(parser, &lparen_type, false, self_allowed, classish_allowed));
|
|
1087
1164
|
ADVANCE_ASSERT(parser, pRPAREN);
|
|
1088
1165
|
*type = lparen_type;
|
|
1089
1166
|
return true;
|
|
1090
1167
|
}
|
|
1091
1168
|
case kBOOL: {
|
|
1092
|
-
|
|
1169
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1093
1170
|
*type = (rbs_node_t *) rbs_types_bases_bool_new(ALLOCATOR(), loc);
|
|
1094
1171
|
return true;
|
|
1095
1172
|
}
|
|
1096
1173
|
case kBOT: {
|
|
1097
|
-
|
|
1174
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1098
1175
|
*type = (rbs_node_t *) rbs_types_bases_bottom_new(ALLOCATOR(), loc);
|
|
1099
1176
|
return true;
|
|
1100
1177
|
}
|
|
1101
1178
|
case kCLASS: {
|
|
1102
|
-
|
|
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);
|
|
1103
1185
|
*type = (rbs_node_t *) rbs_types_bases_class_new(ALLOCATOR(), loc);
|
|
1104
1186
|
return true;
|
|
1105
1187
|
}
|
|
1106
1188
|
case kINSTANCE: {
|
|
1107
|
-
|
|
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);
|
|
1108
1195
|
*type = (rbs_node_t *) rbs_types_bases_instance_new(ALLOCATOR(), loc);
|
|
1109
1196
|
return true;
|
|
1110
1197
|
}
|
|
1111
1198
|
case kNIL: {
|
|
1112
|
-
|
|
1199
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1113
1200
|
*type = (rbs_node_t *) rbs_types_bases_nil_new(ALLOCATOR(), loc);
|
|
1114
1201
|
return true;
|
|
1115
1202
|
}
|
|
1116
1203
|
case kSELF: {
|
|
1117
|
-
|
|
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);
|
|
1118
1210
|
*type = (rbs_node_t *) rbs_types_bases_self_new(ALLOCATOR(), loc);
|
|
1119
1211
|
return true;
|
|
1120
1212
|
}
|
|
1121
1213
|
case kTOP: {
|
|
1122
|
-
|
|
1214
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1123
1215
|
*type = (rbs_node_t *) rbs_types_bases_top_new(ALLOCATOR(), loc);
|
|
1124
1216
|
return true;
|
|
1125
1217
|
}
|
|
1126
1218
|
case kVOID: {
|
|
1127
|
-
|
|
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);
|
|
1128
1225
|
*type = (rbs_node_t *) rbs_types_bases_void_new(ALLOCATOR(), loc);
|
|
1129
1226
|
return true;
|
|
1130
1227
|
}
|
|
1131
1228
|
case kUNTYPED: {
|
|
1132
|
-
|
|
1229
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1133
1230
|
*type = (rbs_node_t *) rbs_types_bases_any_new(ALLOCATOR(), loc, false);
|
|
1134
1231
|
return true;
|
|
1135
1232
|
}
|
|
1136
1233
|
case k__TODO__: {
|
|
1137
|
-
|
|
1234
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1138
1235
|
*type = (rbs_node_t *) rbs_types_bases_any_new(ALLOCATOR(), loc, true);
|
|
1139
1236
|
return true;
|
|
1140
1237
|
}
|
|
1141
1238
|
case tINTEGER: {
|
|
1142
|
-
|
|
1239
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1143
1240
|
|
|
1144
1241
|
rbs_string_t string = rbs_parser_peek_current_token(parser);
|
|
1145
1242
|
rbs_string_t stripped_string = rbs_string_strip_whitespace(&string);
|
|
@@ -1149,20 +1246,20 @@ static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type) {
|
|
|
1149
1246
|
return true;
|
|
1150
1247
|
}
|
|
1151
1248
|
case kTRUE: {
|
|
1152
|
-
|
|
1249
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1153
1250
|
*type = (rbs_node_t *) rbs_types_literal_new(ALLOCATOR(), loc, (rbs_node_t *) rbs_ast_bool_new(ALLOCATOR(), loc, true));
|
|
1154
1251
|
return true;
|
|
1155
1252
|
}
|
|
1156
1253
|
case kFALSE: {
|
|
1157
|
-
|
|
1254
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1158
1255
|
*type = (rbs_node_t *) rbs_types_literal_new(ALLOCATOR(), loc, (rbs_node_t *) rbs_ast_bool_new(ALLOCATOR(), loc, false));
|
|
1159
1256
|
return true;
|
|
1160
1257
|
}
|
|
1161
1258
|
case tSQSTRING:
|
|
1162
1259
|
case tDQSTRING: {
|
|
1163
|
-
|
|
1260
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1164
1261
|
|
|
1165
|
-
rbs_string_t unquoted_str = rbs_unquote_string(ALLOCATOR(), rbs_parser_peek_current_token(parser));
|
|
1262
|
+
rbs_string_t unquoted_str = rbs_unquote_string(ALLOCATOR(), rbs_parser_peek_current_token(parser), parser->lexer->encoding);
|
|
1166
1263
|
rbs_node_t *literal = (rbs_node_t *) rbs_ast_string_new(ALLOCATOR(), loc, unquoted_str);
|
|
1167
1264
|
*type = (rbs_node_t *) rbs_types_literal_new(ALLOCATOR(), loc, literal);
|
|
1168
1265
|
return true;
|
|
@@ -1170,20 +1267,20 @@ static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type) {
|
|
|
1170
1267
|
case tSYMBOL:
|
|
1171
1268
|
case tSQSYMBOL:
|
|
1172
1269
|
case tDQSYMBOL: {
|
|
1173
|
-
|
|
1270
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1174
1271
|
rbs_types_literal_t *literal = NULL;
|
|
1175
1272
|
CHECK_PARSE(parse_symbol(parser, loc, &literal));
|
|
1176
1273
|
*type = (rbs_node_t *) literal;
|
|
1177
1274
|
return true;
|
|
1178
1275
|
}
|
|
1179
1276
|
case tUIDENT: {
|
|
1180
|
-
const char *name_str = rbs_peek_token(parser->
|
|
1277
|
+
const char *name_str = rbs_peek_token(parser->lexer, parser->current_token);
|
|
1181
1278
|
size_t name_len = rbs_token_bytes(parser->current_token);
|
|
1182
1279
|
|
|
1183
1280
|
rbs_constant_id_t name = rbs_constant_pool_find(&parser->constant_pool, (const uint8_t *) name_str, name_len);
|
|
1184
1281
|
|
|
1185
1282
|
if (parser_typevar_member(parser, name)) {
|
|
1186
|
-
|
|
1283
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1187
1284
|
rbs_ast_symbol_t *symbol = rbs_ast_symbol_new(ALLOCATOR(), loc, &parser->constant_pool, name);
|
|
1188
1285
|
*type = (rbs_node_t *) rbs_types_variable_new(ALLOCATOR(), loc, symbol);
|
|
1189
1286
|
return true;
|
|
@@ -1203,7 +1300,7 @@ static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type) {
|
|
|
1203
1300
|
}
|
|
1204
1301
|
case kSINGLETON: {
|
|
1205
1302
|
rbs_types_class_singleton_t *singleton = NULL;
|
|
1206
|
-
CHECK_PARSE(parse_singleton_type(parser, &singleton));
|
|
1303
|
+
CHECK_PARSE(parse_singleton_type(parser, &singleton, self_allowed, classish_allowed));
|
|
1207
1304
|
*type = (rbs_node_t *) singleton;
|
|
1208
1305
|
return true;
|
|
1209
1306
|
}
|
|
@@ -1212,17 +1309,16 @@ static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type) {
|
|
|
1212
1309
|
rg.start = parser->current_token.range.start;
|
|
1213
1310
|
rbs_node_list_t *types = rbs_node_list_new(ALLOCATOR());
|
|
1214
1311
|
if (parser->next_token.type != pRBRACKET) {
|
|
1215
|
-
CHECK_PARSE(parse_type_list(parser, pRBRACKET, types));
|
|
1312
|
+
CHECK_PARSE(parse_type_list(parser, pRBRACKET, types, false, self_allowed, classish_allowed));
|
|
1216
1313
|
}
|
|
1217
1314
|
ADVANCE_ASSERT(parser, pRBRACKET);
|
|
1218
1315
|
rg.end = parser->current_token.range.end;
|
|
1219
1316
|
|
|
1220
|
-
|
|
1221
|
-
*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);
|
|
1222
1318
|
return true;
|
|
1223
1319
|
}
|
|
1224
1320
|
case pAREF_OPR: {
|
|
1225
|
-
|
|
1321
|
+
rbs_location_range loc = rbs_location_range_current_token(parser);
|
|
1226
1322
|
rbs_node_list_t *types = rbs_node_list_new(ALLOCATOR());
|
|
1227
1323
|
*type = (rbs_node_t *) rbs_types_tuple_new(ALLOCATOR(), loc, types);
|
|
1228
1324
|
return true;
|
|
@@ -1230,16 +1326,16 @@ static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type) {
|
|
|
1230
1326
|
case pLBRACE: {
|
|
1231
1327
|
rbs_position_t start = parser->current_token.range.start;
|
|
1232
1328
|
rbs_hash_t *fields = NULL;
|
|
1233
|
-
CHECK_PARSE(parse_record_attributes(parser, &fields));
|
|
1329
|
+
CHECK_PARSE(parse_record_attributes(parser, &fields, self_allowed, classish_allowed));
|
|
1234
1330
|
ADVANCE_ASSERT(parser, pRBRACE);
|
|
1235
1331
|
rbs_position_t end = parser->current_token.range.end;
|
|
1236
|
-
|
|
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 };
|
|
1237
1333
|
*type = (rbs_node_t *) rbs_types_record_new(ALLOCATOR(), loc, fields);
|
|
1238
1334
|
return true;
|
|
1239
1335
|
}
|
|
1240
1336
|
case pHAT: {
|
|
1241
1337
|
rbs_types_proc_t *value = NULL;
|
|
1242
|
-
CHECK_PARSE(parse_proc_type(parser, &value));
|
|
1338
|
+
CHECK_PARSE(parse_proc_type(parser, &value, self_allowed, classish_allowed));
|
|
1243
1339
|
*type = (rbs_node_t *) value;
|
|
1244
1340
|
return true;
|
|
1245
1341
|
}
|
|
@@ -1254,29 +1350,33 @@ static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type) {
|
|
|
1254
1350
|
| {} <optional>
|
|
1255
1351
|
*/
|
|
1256
1352
|
NODISCARD
|
|
1257
|
-
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) {
|
|
1258
1354
|
rbs_range_t rg;
|
|
1259
1355
|
rg.start = parser->next_token.range.start;
|
|
1260
1356
|
|
|
1261
1357
|
rbs_node_t *optional = NULL;
|
|
1262
|
-
CHECK_PARSE(parse_optional(parser, &optional));
|
|
1358
|
+
CHECK_PARSE(parse_optional(parser, &optional, void_allowed, self_allowed, classish_allowed));
|
|
1263
1359
|
*type = optional;
|
|
1264
1360
|
|
|
1265
1361
|
rbs_node_list_t *intersection_types = rbs_node_list_new(ALLOCATOR());
|
|
1266
1362
|
|
|
1267
1363
|
rbs_node_list_append(intersection_types, optional);
|
|
1268
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
|
+
|
|
1269
1370
|
rbs_parser_advance(parser);
|
|
1270
1371
|
rbs_node_t *type = NULL;
|
|
1271
|
-
CHECK_PARSE(parse_optional(parser, &type));
|
|
1372
|
+
CHECK_PARSE(parse_optional(parser, &type, false, self_allowed, classish_allowed));
|
|
1272
1373
|
rbs_node_list_append(intersection_types, type);
|
|
1273
1374
|
}
|
|
1274
1375
|
|
|
1275
1376
|
rg.end = parser->current_token.range.end;
|
|
1276
1377
|
|
|
1277
1378
|
if (intersection_types->length > 1) {
|
|
1278
|
-
|
|
1279
|
-
*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);
|
|
1280
1380
|
}
|
|
1281
1381
|
|
|
1282
1382
|
return true;
|
|
@@ -1286,27 +1386,31 @@ static bool parse_intersection(rbs_parser_t *parser, rbs_node_t **type) {
|
|
|
1286
1386
|
union ::= {} intersection '|' ... '|' <intersection>
|
|
1287
1387
|
| {} <intersection>
|
|
1288
1388
|
*/
|
|
1289
|
-
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) {
|
|
1290
1390
|
rbs_range_t rg;
|
|
1291
1391
|
rg.start = parser->next_token.range.start;
|
|
1292
1392
|
rbs_node_list_t *union_types = rbs_node_list_new(ALLOCATOR());
|
|
1293
1393
|
|
|
1294
|
-
CHECK_PARSE(parse_intersection(parser, type));
|
|
1394
|
+
CHECK_PARSE(parse_intersection(parser, type, void_allowed, self_allowed, classish_allowed));
|
|
1295
1395
|
|
|
1296
1396
|
rbs_node_list_append(union_types, *type);
|
|
1297
1397
|
|
|
1298
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
|
+
|
|
1299
1404
|
rbs_parser_advance(parser);
|
|
1300
1405
|
rbs_node_t *intersection = NULL;
|
|
1301
|
-
CHECK_PARSE(parse_intersection(parser, &intersection));
|
|
1406
|
+
CHECK_PARSE(parse_intersection(parser, &intersection, false, self_allowed, classish_allowed));
|
|
1302
1407
|
rbs_node_list_append(union_types, intersection);
|
|
1303
1408
|
}
|
|
1304
1409
|
|
|
1305
1410
|
rg.end = parser->current_token.range.end;
|
|
1306
1411
|
|
|
1307
1412
|
if (union_types->length > 1) {
|
|
1308
|
-
|
|
1309
|
-
*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);
|
|
1310
1414
|
}
|
|
1311
1415
|
|
|
1312
1416
|
return true;
|
|
@@ -1316,9 +1420,9 @@ bool rbs_parse_type(rbs_parser_t *parser, rbs_node_t **type) {
|
|
|
1316
1420
|
type_params ::= {} `[` type_param `,` ... <`]`>
|
|
1317
1421
|
| {<>}
|
|
1318
1422
|
|
|
1319
|
-
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)
|
|
1320
1424
|
|
|
1321
|
-
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)
|
|
1322
1426
|
*/
|
|
1323
1427
|
NODISCARD
|
|
1324
1428
|
static bool parse_type_params(rbs_parser_t *parser, rbs_range_t *rg, bool module_type_params, rbs_node_list_t **params) {
|
|
@@ -1333,8 +1437,9 @@ static bool parse_type_params(rbs_parser_t *parser, rbs_range_t *rg, bool module
|
|
|
1333
1437
|
|
|
1334
1438
|
while (true) {
|
|
1335
1439
|
bool unchecked = false;
|
|
1336
|
-
|
|
1440
|
+
enum rbs_type_param_variance variance = RBS_TYPE_PARAM_VARIANCE_INVARIANT;
|
|
1337
1441
|
rbs_node_t *upper_bound = NULL;
|
|
1442
|
+
rbs_node_t *lower_bound = NULL;
|
|
1338
1443
|
rbs_node_t *default_type = NULL;
|
|
1339
1444
|
|
|
1340
1445
|
rbs_range_t param_range;
|
|
@@ -1352,10 +1457,10 @@ static bool parse_type_params(rbs_parser_t *parser, rbs_range_t *rg, bool module
|
|
|
1352
1457
|
if (parser->next_token.type == kIN || parser->next_token.type == kOUT) {
|
|
1353
1458
|
switch (parser->next_token.type) {
|
|
1354
1459
|
case kIN:
|
|
1355
|
-
variance =
|
|
1460
|
+
variance = RBS_TYPE_PARAM_VARIANCE_CONTRAVARIANT;
|
|
1356
1461
|
break;
|
|
1357
1462
|
case kOUT:
|
|
1358
|
-
variance =
|
|
1463
|
+
variance = RBS_TYPE_PARAM_VARIANCE_COVARIANT;
|
|
1359
1464
|
break;
|
|
1360
1465
|
default:
|
|
1361
1466
|
rbs_parser_set_error(parser, parser->current_token, false, "Unexpected error");
|
|
@@ -1371,18 +1476,44 @@ static bool parse_type_params(rbs_parser_t *parser, rbs_range_t *rg, bool module
|
|
|
1371
1476
|
rbs_range_t name_range = parser->current_token.range;
|
|
1372
1477
|
|
|
1373
1478
|
rbs_string_t string = rbs_parser_peek_current_token(parser);
|
|
1374
|
-
|
|
1479
|
+
rbs_location_range name_symbol_range = rbs_location_range_current_token(parser);
|
|
1375
1480
|
rbs_constant_id_t id = rbs_constant_pool_insert_string(&parser->constant_pool, string);
|
|
1376
|
-
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);
|
|
1377
1482
|
|
|
1378
1483
|
CHECK_PARSE(rbs_parser_insert_typevar(parser, id));
|
|
1379
1484
|
|
|
1380
1485
|
rbs_range_t upper_bound_range = NULL_RANGE;
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
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
|
+
}
|
|
1386
1517
|
}
|
|
1387
1518
|
|
|
1388
1519
|
rbs_range_t default_type_range = NULL_RANGE;
|
|
@@ -1391,7 +1522,7 @@ static bool parse_type_params(rbs_parser_t *parser, rbs_range_t *rg, bool module
|
|
|
1391
1522
|
rbs_parser_advance(parser);
|
|
1392
1523
|
|
|
1393
1524
|
default_type_range.start = parser->current_token.range.start;
|
|
1394
|
-
CHECK_PARSE(rbs_parse_type(parser, &default_type));
|
|
1525
|
+
CHECK_PARSE(rbs_parse_type(parser, &default_type, true, false, false));
|
|
1395
1526
|
default_type_range.end = parser->current_token.range.end;
|
|
1396
1527
|
|
|
1397
1528
|
required_param_allowed = false;
|
|
@@ -1405,24 +1536,22 @@ static bool parse_type_params(rbs_parser_t *parser, rbs_range_t *rg, bool module
|
|
|
1405
1536
|
|
|
1406
1537
|
param_range.end = parser->current_token.range.end;
|
|
1407
1538
|
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
rbs_loc_add_optional_child(loc, INTERN("default"), default_type_range);
|
|
1415
|
-
|
|
1416
|
-
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);
|
|
1417
1545
|
|
|
1418
1546
|
rbs_node_list_append(*params, (rbs_node_t *) param);
|
|
1419
1547
|
|
|
1420
1548
|
if (parser->next_token.type == pCOMMA) {
|
|
1421
1549
|
rbs_parser_advance(parser);
|
|
1422
|
-
}
|
|
1423
|
-
|
|
1424
|
-
if (parser->next_token.type == pRBRACKET) {
|
|
1550
|
+
} else if (parser->next_token.type == pRBRACKET) {
|
|
1425
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;
|
|
1426
1555
|
}
|
|
1427
1556
|
}
|
|
1428
1557
|
|
|
@@ -1459,7 +1588,7 @@ static bool parser_pop_typevar_table(rbs_parser_t *parser) {
|
|
|
1459
1588
|
method_type ::= {} type_params <function>
|
|
1460
1589
|
*/
|
|
1461
1590
|
// TODO: Should this be NODISCARD?
|
|
1462
|
-
bool rbs_parse_method_type(rbs_parser_t *parser, rbs_method_type_t **method_type) {
|
|
1591
|
+
bool rbs_parse_method_type(rbs_parser_t *parser, rbs_method_type_t **method_type, bool require_eof, bool classish_allowed) {
|
|
1463
1592
|
rbs_parser_push_typevar_table(parser, false);
|
|
1464
1593
|
|
|
1465
1594
|
rbs_range_t rg;
|
|
@@ -1473,19 +1602,24 @@ bool rbs_parse_method_type(rbs_parser_t *parser, rbs_method_type_t **method_type
|
|
|
1473
1602
|
type_range.start = parser->next_token.range.start;
|
|
1474
1603
|
|
|
1475
1604
|
parse_function_result *result = rbs_allocator_alloc(ALLOCATOR(), parse_function_result);
|
|
1476
|
-
CHECK_PARSE(parse_function(parser, false, &result));
|
|
1605
|
+
CHECK_PARSE(parse_function(parser, false, true, &result, true, classish_allowed));
|
|
1606
|
+
|
|
1607
|
+
CHECK_PARSE(parser_pop_typevar_table(parser));
|
|
1477
1608
|
|
|
1478
1609
|
rg.end = parser->current_token.range.end;
|
|
1479
1610
|
type_range.end = rg.end;
|
|
1480
1611
|
|
|
1481
|
-
|
|
1612
|
+
if (require_eof) {
|
|
1613
|
+
rbs_parser_advance(parser);
|
|
1614
|
+
if (parser->current_token.type != pEOF) {
|
|
1615
|
+
rbs_parser_set_error(parser, parser->current_token, true, "expected a token `%s`", rbs_token_type_str(pEOF));
|
|
1616
|
+
return false;
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1482
1619
|
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
rbs_loc_add_required_child(loc, INTERN("type"), type_range);
|
|
1486
|
-
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);
|
|
1487
1622
|
|
|
1488
|
-
*method_type = rbs_method_type_new(ALLOCATOR(), loc, type_params, result->function, result->block);
|
|
1489
1623
|
return true;
|
|
1490
1624
|
}
|
|
1491
1625
|
|
|
@@ -1500,23 +1634,17 @@ static bool parse_global_decl(rbs_parser_t *parser, rbs_node_list_t *annotations
|
|
|
1500
1634
|
rbs_ast_comment_t *comment = rbs_parser_get_comment(parser, decl_range.start.line);
|
|
1501
1635
|
|
|
1502
1636
|
rbs_range_t name_range = parser->current_token.range;
|
|
1503
|
-
rbs_location_t *symbolLoc = rbs_location_new(ALLOCATOR(), name_range);
|
|
1504
1637
|
|
|
1505
|
-
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));
|
|
1506
1639
|
|
|
1507
1640
|
ADVANCE_ASSERT(parser, pCOLON);
|
|
1508
1641
|
rbs_range_t colon_range = parser->current_token.range;
|
|
1509
1642
|
|
|
1510
1643
|
rbs_node_t *type;
|
|
1511
|
-
CHECK_PARSE(rbs_parse_type(parser, &type));
|
|
1644
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, false, false, false));
|
|
1512
1645
|
decl_range.end = parser->current_token.range.end;
|
|
1513
1646
|
|
|
1514
|
-
|
|
1515
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 2);
|
|
1516
|
-
rbs_loc_add_required_child(loc, INTERN("name"), name_range);
|
|
1517
|
-
rbs_loc_add_required_child(loc, INTERN("colon"), colon_range);
|
|
1518
|
-
|
|
1519
|
-
*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));
|
|
1520
1648
|
return true;
|
|
1521
1649
|
}
|
|
1522
1650
|
|
|
@@ -1538,16 +1666,11 @@ static bool parse_const_decl(rbs_parser_t *parser, rbs_node_list_t *annotations,
|
|
|
1538
1666
|
rbs_range_t colon_range = parser->current_token.range;
|
|
1539
1667
|
|
|
1540
1668
|
rbs_node_t *type;
|
|
1541
|
-
CHECK_PARSE(rbs_parse_type(parser, &type));
|
|
1669
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, false, false, false));
|
|
1542
1670
|
|
|
1543
1671
|
decl_range.end = parser->current_token.range.end;
|
|
1544
1672
|
|
|
1545
|
-
|
|
1546
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 2);
|
|
1547
|
-
rbs_loc_add_required_child(loc, INTERN("name"), name_range);
|
|
1548
|
-
rbs_loc_add_required_child(loc, INTERN("colon"), colon_range);
|
|
1549
|
-
|
|
1550
|
-
*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));
|
|
1551
1674
|
return true;
|
|
1552
1675
|
}
|
|
1553
1676
|
|
|
@@ -1578,22 +1701,16 @@ static bool parse_type_decl(rbs_parser_t *parser, rbs_position_t comment_pos, rb
|
|
|
1578
1701
|
rbs_range_t eq_range = parser->current_token.range;
|
|
1579
1702
|
|
|
1580
1703
|
rbs_node_t *type;
|
|
1581
|
-
CHECK_PARSE(rbs_parse_type(parser, &type));
|
|
1704
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, false, false, false));
|
|
1582
1705
|
|
|
1583
1706
|
decl_range.end = parser->current_token.range.end;
|
|
1584
1707
|
|
|
1585
|
-
rbs_location_t *loc = rbs_location_new(ALLOCATOR(), decl_range);
|
|
1586
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 4);
|
|
1587
|
-
rbs_loc_add_required_child(loc, INTERN("keyword"), keyword_range);
|
|
1588
|
-
rbs_loc_add_required_child(loc, INTERN("name"), name_range);
|
|
1589
|
-
rbs_loc_add_optional_child(loc, INTERN("type_params"), params_range);
|
|
1590
|
-
rbs_loc_add_required_child(loc, INTERN("eq"), eq_range);
|
|
1591
|
-
|
|
1592
1708
|
CHECK_PARSE(parser_pop_typevar_table(parser));
|
|
1593
1709
|
|
|
1594
1710
|
rbs_ast_comment_t *comment = rbs_parser_get_comment(parser, comment_pos.line);
|
|
1595
1711
|
|
|
1596
|
-
*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);
|
|
1597
1714
|
return true;
|
|
1598
1715
|
}
|
|
1599
1716
|
|
|
@@ -1605,14 +1722,16 @@ static bool parse_annotation(rbs_parser_t *parser, rbs_ast_annotation_t **annota
|
|
|
1605
1722
|
rbs_range_t rg = parser->current_token.range;
|
|
1606
1723
|
|
|
1607
1724
|
size_t offset_bytes =
|
|
1608
|
-
parser->
|
|
1609
|
-
parser->
|
|
1725
|
+
parser->lexer->encoding->char_width((const uint8_t *) "%", (size_t) 1) +
|
|
1726
|
+
parser->lexer->encoding->char_width((const uint8_t *) "a", (size_t) 1);
|
|
1610
1727
|
|
|
1611
1728
|
rbs_string_t str = rbs_string_new(
|
|
1612
|
-
parser->
|
|
1613
|
-
parser->
|
|
1729
|
+
parser->lexer->string.start + rg.start.byte_pos + offset_bytes,
|
|
1730
|
+
parser->lexer->string.end
|
|
1614
1731
|
);
|
|
1615
|
-
|
|
1732
|
+
|
|
1733
|
+
// Assumes the input is ASCII compatible
|
|
1734
|
+
unsigned int open_char = str.start[0];
|
|
1616
1735
|
|
|
1617
1736
|
unsigned int close_char;
|
|
1618
1737
|
|
|
@@ -1637,8 +1756,8 @@ static bool parse_annotation(rbs_parser_t *parser, rbs_ast_annotation_t **annota
|
|
|
1637
1756
|
return false;
|
|
1638
1757
|
}
|
|
1639
1758
|
|
|
1640
|
-
size_t open_bytes = parser->
|
|
1641
|
-
size_t close_bytes = parser->
|
|
1759
|
+
size_t open_bytes = parser->lexer->encoding->char_width((const uint8_t *) &open_char, (size_t) 1);
|
|
1760
|
+
size_t close_bytes = parser->lexer->encoding->char_width((const uint8_t *) &close_char, (size_t) 1);
|
|
1642
1761
|
|
|
1643
1762
|
rbs_string_t current_token = rbs_parser_peek_current_token(parser);
|
|
1644
1763
|
size_t total_offset = offset_bytes + open_bytes;
|
|
@@ -1650,7 +1769,7 @@ static bool parse_annotation(rbs_parser_t *parser, rbs_ast_annotation_t **annota
|
|
|
1650
1769
|
|
|
1651
1770
|
rbs_string_t stripped_annotation_str = rbs_string_strip_whitespace(&annotation_str);
|
|
1652
1771
|
|
|
1653
|
-
*annotation = rbs_ast_annotation_new(ALLOCATOR(),
|
|
1772
|
+
*annotation = rbs_ast_annotation_new(ALLOCATOR(), RBS_RANGE_LEX2AST(rg), stripped_annotation_str);
|
|
1654
1773
|
return true;
|
|
1655
1774
|
}
|
|
1656
1775
|
|
|
@@ -1702,33 +1821,29 @@ static bool parse_method_name(rbs_parser_t *parser, rbs_range_t *range, rbs_ast_
|
|
|
1702
1821
|
|
|
1703
1822
|
rbs_constant_id_t constant_id = rbs_constant_pool_insert_shared_with_encoding(
|
|
1704
1823
|
&parser->constant_pool,
|
|
1705
|
-
(const uint8_t *) parser->
|
|
1824
|
+
(const uint8_t *) parser->lexer->string.start + range->start.byte_pos,
|
|
1706
1825
|
range->end.byte_pos - range->start.byte_pos,
|
|
1707
|
-
parser->
|
|
1826
|
+
parser->lexer->encoding
|
|
1708
1827
|
);
|
|
1709
1828
|
|
|
1710
|
-
|
|
1711
|
-
*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);
|
|
1712
1830
|
} else {
|
|
1713
1831
|
*range = parser->current_token.range;
|
|
1714
|
-
|
|
1715
|
-
*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));
|
|
1716
1833
|
}
|
|
1717
1834
|
return true;
|
|
1718
1835
|
|
|
1719
1836
|
case tBANGIDENT:
|
|
1720
1837
|
case tEQIDENT: {
|
|
1721
1838
|
*range = parser->current_token.range;
|
|
1722
|
-
|
|
1723
|
-
*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));
|
|
1724
1840
|
return true;
|
|
1725
1841
|
}
|
|
1726
1842
|
case tQIDENT: {
|
|
1727
1843
|
rbs_string_t string = rbs_parser_peek_current_token(parser);
|
|
1728
|
-
rbs_string_t unquoted_str = rbs_unquote_string(ALLOCATOR(), string);
|
|
1844
|
+
rbs_string_t unquoted_str = rbs_unquote_string(ALLOCATOR(), string, parser->lexer->encoding);
|
|
1729
1845
|
rbs_constant_id_t constant_id = rbs_constant_pool_insert_string(&parser->constant_pool, unquoted_str);
|
|
1730
|
-
|
|
1731
|
-
*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);
|
|
1732
1847
|
return true;
|
|
1733
1848
|
}
|
|
1734
1849
|
|
|
@@ -1738,11 +1853,11 @@ static bool parse_method_name(rbs_parser_t *parser, rbs_range_t *range, rbs_ast_
|
|
|
1738
1853
|
case pSTAR:
|
|
1739
1854
|
case pSTAR2:
|
|
1740
1855
|
case pLT:
|
|
1856
|
+
case pGT:
|
|
1741
1857
|
case pAREF_OPR:
|
|
1742
1858
|
case tOPERATOR: {
|
|
1743
1859
|
*range = parser->current_token.range;
|
|
1744
|
-
|
|
1745
|
-
*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));
|
|
1746
1861
|
return true;
|
|
1747
1862
|
}
|
|
1748
1863
|
|
|
@@ -1816,25 +1931,25 @@ static bool parse_member_def(rbs_parser_t *parser, bool instance_only, bool acce
|
|
|
1816
1931
|
rbs_ast_comment_t *comment = rbs_parser_get_comment(parser, comment_pos.line);
|
|
1817
1932
|
|
|
1818
1933
|
rbs_range_t visibility_range;
|
|
1819
|
-
|
|
1934
|
+
enum rbs_method_definition_visibility visibility;
|
|
1820
1935
|
switch (parser->current_token.type) {
|
|
1821
1936
|
case kPRIVATE: {
|
|
1822
1937
|
visibility_range = parser->current_token.range;
|
|
1823
|
-
visibility =
|
|
1938
|
+
visibility = RBS_METHOD_DEFINITION_VISIBILITY_PRIVATE;
|
|
1824
1939
|
member_range.start = visibility_range.start;
|
|
1825
1940
|
rbs_parser_advance(parser);
|
|
1826
1941
|
break;
|
|
1827
1942
|
}
|
|
1828
1943
|
case kPUBLIC: {
|
|
1829
1944
|
visibility_range = parser->current_token.range;
|
|
1830
|
-
visibility =
|
|
1945
|
+
visibility = RBS_METHOD_DEFINITION_VISIBILITY_PUBLIC;
|
|
1831
1946
|
member_range.start = visibility_range.start;
|
|
1832
1947
|
rbs_parser_advance(parser);
|
|
1833
1948
|
break;
|
|
1834
1949
|
}
|
|
1835
1950
|
default:
|
|
1836
1951
|
visibility_range = NULL_RANGE;
|
|
1837
|
-
visibility =
|
|
1952
|
+
visibility = RBS_METHOD_DEFINITION_VISIBILITY_UNSPECIFIED;
|
|
1838
1953
|
break;
|
|
1839
1954
|
}
|
|
1840
1955
|
|
|
@@ -1846,7 +1961,7 @@ static bool parse_member_def(rbs_parser_t *parser, bool instance_only, bool acce
|
|
|
1846
1961
|
kind_range = NULL_RANGE;
|
|
1847
1962
|
kind = INSTANCE_KIND;
|
|
1848
1963
|
} else {
|
|
1849
|
-
kind = parse_instance_singleton_kind(parser, visibility ==
|
|
1964
|
+
kind = parse_instance_singleton_kind(parser, visibility == RBS_METHOD_DEFINITION_VISIBILITY_UNSPECIFIED, &kind_range);
|
|
1850
1965
|
}
|
|
1851
1966
|
|
|
1852
1967
|
rbs_range_t name_range;
|
|
@@ -1886,11 +2001,10 @@ static bool parse_member_def(rbs_parser_t *parser, bool instance_only, bool acce
|
|
|
1886
2001
|
case pLBRACKET:
|
|
1887
2002
|
case pQUESTION: {
|
|
1888
2003
|
rbs_method_type_t *method_type = NULL;
|
|
1889
|
-
CHECK_PARSE(rbs_parse_method_type(parser, &method_type));
|
|
2004
|
+
CHECK_PARSE(rbs_parse_method_type(parser, &method_type, false, !instance_only));
|
|
1890
2005
|
|
|
1891
2006
|
overload_range.end = parser->current_token.range.end;
|
|
1892
|
-
|
|
1893
|
-
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);
|
|
1894
2008
|
rbs_node_list_append(overloads, overload);
|
|
1895
2009
|
member_range.end = parser->current_token.range.end;
|
|
1896
2010
|
break;
|
|
@@ -1923,18 +2037,18 @@ static bool parse_member_def(rbs_parser_t *parser, bool instance_only, bool acce
|
|
|
1923
2037
|
|
|
1924
2038
|
CHECK_PARSE(parser_pop_typevar_table(parser));
|
|
1925
2039
|
|
|
1926
|
-
|
|
2040
|
+
enum rbs_method_definition_kind k;
|
|
1927
2041
|
switch (kind) {
|
|
1928
2042
|
case INSTANCE_KIND: {
|
|
1929
|
-
k =
|
|
2043
|
+
k = RBS_METHOD_DEFINITION_KIND_INSTANCE;
|
|
1930
2044
|
break;
|
|
1931
2045
|
}
|
|
1932
2046
|
case SINGLETON_KIND: {
|
|
1933
|
-
k =
|
|
2047
|
+
k = RBS_METHOD_DEFINITION_KIND_SINGLETON;
|
|
1934
2048
|
break;
|
|
1935
2049
|
}
|
|
1936
2050
|
case INSTANCE_SINGLETON_KIND: {
|
|
1937
|
-
k =
|
|
2051
|
+
k = RBS_METHOD_DEFINITION_KIND_SINGLETON_INSTANCE;
|
|
1938
2052
|
break;
|
|
1939
2053
|
}
|
|
1940
2054
|
default:
|
|
@@ -1942,15 +2056,11 @@ static bool parse_member_def(rbs_parser_t *parser, bool instance_only, bool acce
|
|
|
1942
2056
|
return false;
|
|
1943
2057
|
}
|
|
1944
2058
|
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
rbs_loc_add_optional_child(loc, INTERN("kind"), kind_range);
|
|
1950
|
-
rbs_loc_add_optional_child(loc, INTERN("overloading"), overloading_range);
|
|
1951
|
-
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);
|
|
1952
2063
|
|
|
1953
|
-
*method_definition = rbs_ast_members_method_definition_new(ALLOCATOR(), loc, name, k, overloads, annotations, comment, overloading, visibility);
|
|
1954
2064
|
return true;
|
|
1955
2065
|
}
|
|
1956
2066
|
|
|
@@ -1961,7 +2071,7 @@ static bool parse_member_def(rbs_parser_t *parser, bool instance_only, bool acce
|
|
|
1961
2071
|
* @param kind
|
|
1962
2072
|
* */
|
|
1963
2073
|
NODISCARD
|
|
1964
|
-
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) {
|
|
1965
2075
|
rbs_parser_advance(parser);
|
|
1966
2076
|
|
|
1967
2077
|
rbs_type_name_t *type_name = NULL;
|
|
@@ -1971,7 +2081,7 @@ static bool class_instance_name(rbs_parser_t *parser, TypeNameKind kind, rbs_nod
|
|
|
1971
2081
|
if (parser->next_token.type == pLBRACKET) {
|
|
1972
2082
|
rbs_parser_advance(parser);
|
|
1973
2083
|
args_range->start = parser->current_token.range.start;
|
|
1974
|
-
CHECK_PARSE(parse_type_list(parser, pRBRACKET, args));
|
|
2084
|
+
CHECK_PARSE(parse_type_list(parser, pRBRACKET, args, true, false, classish_allowed));
|
|
1975
2085
|
ADVANCE_ASSERT(parser, pRBRACKET);
|
|
1976
2086
|
args_range->end = parser->current_token.range.end;
|
|
1977
2087
|
} else {
|
|
@@ -2028,34 +2138,43 @@ static bool parse_mixin_member(rbs_parser_t *parser, bool from_interface, rbs_po
|
|
|
2028
2138
|
rbs_type_name_t *name = NULL;
|
|
2029
2139
|
CHECK_PARSE(class_instance_name(
|
|
2030
2140
|
parser,
|
|
2031
|
-
from_interface ? INTERFACE_NAME : (INTERFACE_NAME | CLASS_NAME),
|
|
2141
|
+
from_interface ? INTERFACE_NAME : (TypeNameKind) (INTERFACE_NAME | CLASS_NAME),
|
|
2032
2142
|
args,
|
|
2033
2143
|
&name_range,
|
|
2034
2144
|
&args_range,
|
|
2035
|
-
&name
|
|
2145
|
+
&name,
|
|
2146
|
+
!from_interface
|
|
2036
2147
|
));
|
|
2037
2148
|
|
|
2038
2149
|
CHECK_PARSE(parser_pop_typevar_table(parser));
|
|
2039
2150
|
|
|
2040
2151
|
member_range.end = parser->current_token.range.end;
|
|
2041
2152
|
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
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);
|
|
2047
2157
|
|
|
2048
2158
|
rbs_ast_comment_t *comment = rbs_parser_get_comment(parser, comment_pos.line);
|
|
2049
2159
|
switch (type) {
|
|
2050
|
-
case kINCLUDE:
|
|
2051
|
-
*
|
|
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;
|
|
2052
2164
|
return true;
|
|
2053
|
-
|
|
2054
|
-
|
|
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;
|
|
2055
2170
|
return true;
|
|
2056
|
-
|
|
2057
|
-
|
|
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;
|
|
2058
2176
|
return true;
|
|
2177
|
+
}
|
|
2059
2178
|
default:
|
|
2060
2179
|
rbs_parser_set_error(parser, parser->current_token, false, "Unexpected error");
|
|
2061
2180
|
return false;
|
|
@@ -2079,12 +2198,12 @@ static bool parse_alias_member(rbs_parser_t *parser, bool instance_only, rbs_pos
|
|
|
2079
2198
|
comment_pos = rbs_nonnull_pos_or(comment_pos, member_range.start);
|
|
2080
2199
|
rbs_ast_comment_t *comment = rbs_parser_get_comment(parser, comment_pos.line);
|
|
2081
2200
|
|
|
2082
|
-
|
|
2201
|
+
enum rbs_alias_kind kind;
|
|
2083
2202
|
rbs_ast_symbol_t *new_name, *old_name;
|
|
2084
2203
|
rbs_range_t new_kind_range, old_kind_range, new_name_range, old_name_range;
|
|
2085
2204
|
|
|
2086
2205
|
if (!instance_only && parser->next_token.type == kSELF) {
|
|
2087
|
-
kind =
|
|
2206
|
+
kind = RBS_ALIAS_KIND_SINGLETON;
|
|
2088
2207
|
|
|
2089
2208
|
new_kind_range.start = parser->next_token.range.start;
|
|
2090
2209
|
new_kind_range.end = parser->next_token2.range.end;
|
|
@@ -2098,7 +2217,7 @@ static bool parse_alias_member(rbs_parser_t *parser, bool instance_only, rbs_pos
|
|
|
2098
2217
|
ADVANCE_ASSERT(parser, pDOT);
|
|
2099
2218
|
CHECK_PARSE(parse_method_name(parser, &old_name_range, &old_name));
|
|
2100
2219
|
} else {
|
|
2101
|
-
kind =
|
|
2220
|
+
kind = RBS_ALIAS_KIND_INSTANCE;
|
|
2102
2221
|
CHECK_PARSE(parse_method_name(parser, &new_name_range, &new_name));
|
|
2103
2222
|
CHECK_PARSE(parse_method_name(parser, &old_name_range, &old_name));
|
|
2104
2223
|
new_kind_range = NULL_RANGE;
|
|
@@ -2106,15 +2225,13 @@ static bool parse_alias_member(rbs_parser_t *parser, bool instance_only, rbs_pos
|
|
|
2106
2225
|
}
|
|
2107
2226
|
|
|
2108
2227
|
member_range.end = parser->current_token.range.end;
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
*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
|
+
|
|
2118
2235
|
return true;
|
|
2119
2236
|
}
|
|
2120
2237
|
|
|
@@ -2139,29 +2256,26 @@ static bool parse_variable_member(rbs_parser_t *parser, rbs_position_t comment_p
|
|
|
2139
2256
|
case tAIDENT:
|
|
2140
2257
|
case kATRBS: {
|
|
2141
2258
|
rbs_range_t name_range = parser->current_token.range;
|
|
2142
|
-
|
|
2259
|
+
rbs_location_range symbolLoc = RBS_RANGE_LEX2AST(name_range);
|
|
2143
2260
|
rbs_ast_symbol_t *name = rbs_ast_symbol_new(ALLOCATOR(), symbolLoc, &parser->constant_pool, INTERN_TOKEN(parser, parser->current_token));
|
|
2144
2261
|
|
|
2145
2262
|
ADVANCE_ASSERT(parser, pCOLON);
|
|
2146
2263
|
rbs_range_t colon_range = parser->current_token.range;
|
|
2147
2264
|
|
|
2148
2265
|
rbs_node_t *type;
|
|
2149
|
-
CHECK_PARSE(rbs_parse_type(parser, &type));
|
|
2266
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, false, true, true));
|
|
2150
2267
|
member_range.end = parser->current_token.range.end;
|
|
2151
2268
|
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
rbs_loc_add_required_child(loc, INTERN("colon"), colon_range);
|
|
2156
|
-
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));
|
|
2157
2272
|
|
|
2158
|
-
*variable_member = (rbs_node_t *) rbs_ast_members_instance_variable_new(ALLOCATOR(), loc, name, type, comment);
|
|
2159
2273
|
return true;
|
|
2160
2274
|
}
|
|
2161
2275
|
case tA2IDENT: {
|
|
2162
2276
|
rbs_range_t name_range = parser->current_token.range;
|
|
2163
|
-
|
|
2164
|
-
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));
|
|
2165
2279
|
|
|
2166
2280
|
ADVANCE_ASSERT(parser, pCOLON);
|
|
2167
2281
|
rbs_range_t colon_range = parser->current_token.range;
|
|
@@ -2169,19 +2283,16 @@ static bool parse_variable_member(rbs_parser_t *parser, rbs_position_t comment_p
|
|
|
2169
2283
|
rbs_parser_push_typevar_table(parser, true);
|
|
2170
2284
|
|
|
2171
2285
|
rbs_node_t *type;
|
|
2172
|
-
CHECK_PARSE(rbs_parse_type(parser, &type));
|
|
2286
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, false, false, true));
|
|
2173
2287
|
|
|
2174
2288
|
CHECK_PARSE(parser_pop_typevar_table(parser));
|
|
2175
2289
|
|
|
2176
2290
|
member_range.end = parser->current_token.range.end;
|
|
2177
2291
|
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
rbs_loc_add_required_child(loc, INTERN("colon"), colon_range);
|
|
2182
|
-
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));
|
|
2183
2295
|
|
|
2184
|
-
*variable_member = (rbs_node_t *) rbs_ast_members_class_variable_new(ALLOCATOR(), loc, name, type, comment);
|
|
2185
2296
|
return true;
|
|
2186
2297
|
}
|
|
2187
2298
|
case kSELF: {
|
|
@@ -2199,8 +2310,8 @@ static bool parse_variable_member(rbs_parser_t *parser, rbs_position_t comment_p
|
|
|
2199
2310
|
}
|
|
2200
2311
|
|
|
2201
2312
|
rbs_range_t name_range = parser->current_token.range;
|
|
2202
|
-
|
|
2203
|
-
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));
|
|
2204
2315
|
|
|
2205
2316
|
ADVANCE_ASSERT(parser, pCOLON);
|
|
2206
2317
|
rbs_range_t colon_range = parser->current_token.range;
|
|
@@ -2208,19 +2319,19 @@ static bool parse_variable_member(rbs_parser_t *parser, rbs_position_t comment_p
|
|
|
2208
2319
|
rbs_parser_push_typevar_table(parser, true);
|
|
2209
2320
|
|
|
2210
2321
|
rbs_node_t *type;
|
|
2211
|
-
CHECK_PARSE(rbs_parse_type(parser, &type));
|
|
2322
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, false, true, true));
|
|
2212
2323
|
|
|
2213
2324
|
CHECK_PARSE(parser_pop_typevar_table(parser));
|
|
2214
2325
|
|
|
2215
2326
|
member_range.end = parser->current_token.range.end;
|
|
2216
2327
|
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
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;
|
|
2222
2334
|
|
|
2223
|
-
*variable_member = (rbs_node_t *) rbs_ast_members_class_instance_variable_new(ALLOCATOR(), loc, name, type, comment);
|
|
2224
2335
|
return true;
|
|
2225
2336
|
}
|
|
2226
2337
|
default:
|
|
@@ -2240,7 +2351,7 @@ static bool parse_visibility_member(rbs_parser_t *parser, rbs_node_list_t *annot
|
|
|
2240
2351
|
return false;
|
|
2241
2352
|
}
|
|
2242
2353
|
|
|
2243
|
-
|
|
2354
|
+
rbs_location_range location = rbs_location_range_current_token(parser);
|
|
2244
2355
|
|
|
2245
2356
|
switch (parser->current_token.type) {
|
|
2246
2357
|
case kPUBLIC: {
|
|
@@ -2280,22 +2391,23 @@ static bool parse_attribute_member(rbs_parser_t *parser, rbs_position_t comment_
|
|
|
2280
2391
|
rbs_ast_comment_t *comment = rbs_parser_get_comment(parser, comment_pos.line);
|
|
2281
2392
|
|
|
2282
2393
|
rbs_range_t visibility_range;
|
|
2283
|
-
|
|
2394
|
+
enum rbs_attribute_visibility visibility;
|
|
2395
|
+
|
|
2284
2396
|
switch (parser->current_token.type) {
|
|
2285
2397
|
case kPRIVATE: {
|
|
2286
2398
|
visibility_range = parser->current_token.range;
|
|
2287
|
-
visibility =
|
|
2399
|
+
visibility = RBS_ATTRIBUTE_VISIBILITY_PRIVATE;
|
|
2288
2400
|
rbs_parser_advance(parser);
|
|
2289
2401
|
break;
|
|
2290
2402
|
}
|
|
2291
2403
|
case kPUBLIC: {
|
|
2292
2404
|
visibility_range = parser->current_token.range;
|
|
2293
|
-
visibility =
|
|
2405
|
+
visibility = RBS_ATTRIBUTE_VISIBILITY_PUBLIC;
|
|
2294
2406
|
rbs_parser_advance(parser);
|
|
2295
2407
|
break;
|
|
2296
2408
|
}
|
|
2297
2409
|
default:
|
|
2298
|
-
visibility =
|
|
2410
|
+
visibility = RBS_ATTRIBUTE_VISIBILITY_UNSPECIFIED;
|
|
2299
2411
|
visibility_range = NULL_RANGE;
|
|
2300
2412
|
break;
|
|
2301
2413
|
}
|
|
@@ -2306,41 +2418,31 @@ static bool parse_attribute_member(rbs_parser_t *parser, rbs_position_t comment_
|
|
|
2306
2418
|
rbs_range_t kind_range;
|
|
2307
2419
|
InstanceSingletonKind is_kind = parse_instance_singleton_kind(parser, false, &kind_range);
|
|
2308
2420
|
|
|
2309
|
-
|
|
2310
|
-
ALLOCATOR(),
|
|
2311
|
-
rbs_location_new(ALLOCATOR(), keyword_range),
|
|
2312
|
-
INTERN(((is_kind == INSTANCE_KIND) ? "instance" : "singleton"))
|
|
2313
|
-
);
|
|
2421
|
+
enum rbs_attribute_kind kind = (is_kind == INSTANCE_KIND) ? RBS_ATTRIBUTE_KIND_INSTANCE : RBS_ATTRIBUTE_KIND_SINGLETON;
|
|
2314
2422
|
|
|
2315
2423
|
rbs_range_t name_range;
|
|
2316
2424
|
rbs_ast_symbol_t *attr_name;
|
|
2317
2425
|
CHECK_PARSE(parse_method_name(parser, &name_range, &attr_name));
|
|
2318
2426
|
|
|
2319
|
-
|
|
2320
|
-
|
|
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;
|
|
2321
2430
|
if (parser->next_token.type == pLPAREN) {
|
|
2322
2431
|
ADVANCE_ASSERT(parser, pLPAREN);
|
|
2323
|
-
ivar_range.
|
|
2432
|
+
ivar_range.start_char = parser->current_token.range.start.char_pos;
|
|
2433
|
+
ivar_range.start_byte = parser->current_token.range.start.byte_pos;
|
|
2434
|
+
|
|
2435
|
+
ivar_name.tag = RBS_ATTR_IVAR_NAME_TAG_EMPTY;
|
|
2324
2436
|
|
|
2325
2437
|
if (parser_advance_if(parser, tAIDENT) || parser_advance_if(parser, kATRBS)) {
|
|
2326
|
-
|
|
2327
|
-
ivar_name =
|
|
2328
|
-
ivar_name_range = parser
|
|
2329
|
-
} else {
|
|
2330
|
-
rbs_range_t false_range = {
|
|
2331
|
-
.start = parser->current_token.range.start,
|
|
2332
|
-
.end = parser->current_token.range.end
|
|
2333
|
-
};
|
|
2334
|
-
ivar_name = (rbs_node_t *) rbs_ast_bool_new(ALLOCATOR(), rbs_location_new(ALLOCATOR(), false_range), false);
|
|
2335
|
-
ivar_name_range = NULL_RANGE;
|
|
2438
|
+
ivar_name.tag = RBS_ATTR_IVAR_NAME_TAG_NAME;
|
|
2439
|
+
ivar_name.name = INTERN_TOKEN(parser, parser->current_token);
|
|
2440
|
+
ivar_name_range = rbs_location_range_current_token(parser);
|
|
2336
2441
|
}
|
|
2337
2442
|
|
|
2338
2443
|
ADVANCE_ASSERT(parser, pRPAREN);
|
|
2339
|
-
ivar_range.
|
|
2340
|
-
|
|
2341
|
-
ivar_range = NULL_RANGE;
|
|
2342
|
-
ivar_name = NULL;
|
|
2343
|
-
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;
|
|
2344
2446
|
}
|
|
2345
2447
|
|
|
2346
2448
|
ADVANCE_ASSERT(parser, pCOLON);
|
|
@@ -2349,32 +2451,53 @@ static bool parse_attribute_member(rbs_parser_t *parser, rbs_position_t comment_
|
|
|
2349
2451
|
rbs_parser_push_typevar_table(parser, is_kind == SINGLETON_KIND);
|
|
2350
2452
|
|
|
2351
2453
|
rbs_node_t *type;
|
|
2352
|
-
CHECK_PARSE(rbs_parse_type(parser, &type));
|
|
2454
|
+
CHECK_PARSE(rbs_parse_type(parser, &type, false, true, true));
|
|
2353
2455
|
|
|
2354
2456
|
CHECK_PARSE(parser_pop_typevar_table(parser));
|
|
2355
2457
|
|
|
2356
2458
|
member_range.end = parser->current_token.range.end;
|
|
2357
2459
|
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
rbs_loc_add_optional_child(loc, INTERN("ivar"), ivar_range);
|
|
2365
|
-
rbs_loc_add_optional_child(loc, INTERN("ivar_name"), ivar_name_range);
|
|
2366
|
-
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);
|
|
2367
2466
|
|
|
2368
2467
|
switch (attr_type) {
|
|
2369
|
-
case kATTRREADER:
|
|
2370
|
-
*
|
|
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
|
+
|
|
2371
2477
|
return true;
|
|
2372
|
-
|
|
2373
|
-
|
|
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
|
+
|
|
2374
2488
|
return true;
|
|
2375
|
-
|
|
2376
|
-
|
|
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
|
+
|
|
2377
2499
|
return true;
|
|
2500
|
+
}
|
|
2378
2501
|
default:
|
|
2379
2502
|
rbs_parser_set_error(parser, parser->current_token, false, "Unexpected error");
|
|
2380
2503
|
return false;
|
|
@@ -2465,16 +2588,12 @@ static bool parse_interface_decl(rbs_parser_t *parser, rbs_position_t comment_po
|
|
|
2465
2588
|
|
|
2466
2589
|
CHECK_PARSE(parser_pop_typevar_table(parser));
|
|
2467
2590
|
|
|
2468
|
-
|
|
2469
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 4);
|
|
2470
|
-
rbs_loc_add_required_child(loc, INTERN("keyword"), keyword_range);
|
|
2471
|
-
rbs_loc_add_required_child(loc, INTERN("name"), name_range);
|
|
2472
|
-
rbs_loc_add_required_child(loc, INTERN("end"), end_range);
|
|
2473
|
-
rbs_loc_add_optional_child(loc, INTERN("type_params"), type_params_range);
|
|
2474
|
-
|
|
2591
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(member_range);
|
|
2475
2592
|
rbs_ast_comment_t *comment = rbs_parser_get_comment(parser, comment_pos.line);
|
|
2476
2593
|
|
|
2477
|
-
*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
|
+
|
|
2478
2597
|
return true;
|
|
2479
2598
|
}
|
|
2480
2599
|
|
|
@@ -2494,7 +2613,7 @@ static bool parse_module_self_types(rbs_parser_t *parser, rbs_node_list_t *array
|
|
|
2494
2613
|
|
|
2495
2614
|
rbs_range_t name_range;
|
|
2496
2615
|
rbs_type_name_t *module_name = NULL;
|
|
2497
|
-
CHECK_PARSE(parse_type_name(parser, CLASS_NAME | INTERFACE_NAME, &name_range, &module_name));
|
|
2616
|
+
CHECK_PARSE(parse_type_name(parser, (TypeNameKind) (CLASS_NAME | INTERFACE_NAME), &name_range, &module_name));
|
|
2498
2617
|
self_range.end = name_range.end;
|
|
2499
2618
|
|
|
2500
2619
|
rbs_node_list_t *args = rbs_node_list_new(ALLOCATOR());
|
|
@@ -2502,17 +2621,15 @@ static bool parse_module_self_types(rbs_parser_t *parser, rbs_node_list_t *array
|
|
|
2502
2621
|
if (parser->next_token.type == pLBRACKET) {
|
|
2503
2622
|
rbs_parser_advance(parser);
|
|
2504
2623
|
args_range.start = parser->current_token.range.start;
|
|
2505
|
-
CHECK_PARSE(parse_type_list(parser, pRBRACKET, args));
|
|
2624
|
+
CHECK_PARSE(parse_type_list(parser, pRBRACKET, args, true, false, false));
|
|
2506
2625
|
rbs_parser_advance(parser);
|
|
2507
2626
|
self_range.end = args_range.end = parser->current_token.range.end;
|
|
2508
2627
|
}
|
|
2509
2628
|
|
|
2510
|
-
|
|
2511
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 2);
|
|
2512
|
-
rbs_loc_add_required_child(loc, INTERN("name"), name_range);
|
|
2513
|
-
rbs_loc_add_optional_child(loc, INTERN("args"), args_range);
|
|
2629
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(self_range);
|
|
2514
2630
|
|
|
2515
|
-
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);
|
|
2516
2633
|
rbs_node_list_append(array, (rbs_node_t *) self_type);
|
|
2517
2634
|
|
|
2518
2635
|
if (parser->next_token.type == pCOMMA) {
|
|
@@ -2658,18 +2775,14 @@ static bool parse_module_decl0(rbs_parser_t *parser, rbs_range_t keyword_range,
|
|
|
2658
2775
|
rbs_range_t end_range = parser->current_token.range;
|
|
2659
2776
|
decl_range.end = parser->current_token.range.end;
|
|
2660
2777
|
|
|
2661
|
-
rbs_location_t *loc = rbs_location_new(ALLOCATOR(), decl_range);
|
|
2662
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 6);
|
|
2663
|
-
rbs_loc_add_required_child(loc, INTERN("keyword"), keyword_range);
|
|
2664
|
-
rbs_loc_add_required_child(loc, INTERN("name"), name_range);
|
|
2665
|
-
rbs_loc_add_required_child(loc, INTERN("end"), end_range);
|
|
2666
|
-
rbs_loc_add_optional_child(loc, INTERN("type_params"), type_params_range);
|
|
2667
|
-
rbs_loc_add_optional_child(loc, INTERN("colon"), colon_range);
|
|
2668
|
-
rbs_loc_add_optional_child(loc, INTERN("self_types"), self_types_range);
|
|
2669
|
-
|
|
2670
2778
|
CHECK_PARSE(parser_pop_typevar_table(parser));
|
|
2671
2779
|
|
|
2672
|
-
|
|
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);
|
|
2673
2786
|
return true;
|
|
2674
2787
|
}
|
|
2675
2788
|
|
|
@@ -2705,14 +2818,9 @@ static bool parse_module_decl(rbs_parser_t *parser, rbs_position_t comment_pos,
|
|
|
2705
2818
|
.end = old_name_range.end
|
|
2706
2819
|
};
|
|
2707
2820
|
|
|
2708
|
-
|
|
2709
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 4);
|
|
2710
|
-
rbs_loc_add_required_child(loc, INTERN("keyword"), keyword_range);
|
|
2711
|
-
rbs_loc_add_required_child(loc, INTERN("new_name"), module_name_range);
|
|
2712
|
-
rbs_loc_add_required_child(loc, INTERN("eq"), eq_range);
|
|
2713
|
-
rbs_loc_add_optional_child(loc, INTERN("old_name"), old_name_range);
|
|
2821
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(decl_range);
|
|
2714
2822
|
|
|
2715
|
-
*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));
|
|
2716
2824
|
} else {
|
|
2717
2825
|
rbs_ast_declarations_module_t *module_decl0 = NULL;
|
|
2718
2826
|
CHECK_PARSE(parse_module_decl0(parser, keyword_range, module_name, module_name_range, comment, annotations, &module_decl0));
|
|
@@ -2737,16 +2845,13 @@ static bool parse_class_decl_super(rbs_parser_t *parser, rbs_range_t *lt_range,
|
|
|
2737
2845
|
rbs_node_list_t *args = rbs_node_list_new(ALLOCATOR());
|
|
2738
2846
|
rbs_type_name_t *name = NULL;
|
|
2739
2847
|
rbs_range_t name_range, args_range;
|
|
2740
|
-
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));
|
|
2741
2849
|
|
|
2742
2850
|
super_range.end = parser->current_token.range.end;
|
|
2743
2851
|
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
rbs_loc_add_optional_child(loc, INTERN("args"), args_range);
|
|
2748
|
-
|
|
2749
|
-
*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);
|
|
2750
2855
|
} else {
|
|
2751
2856
|
*lt_range = NULL_RANGE;
|
|
2752
2857
|
}
|
|
@@ -2783,15 +2888,12 @@ static bool parse_class_decl0(rbs_parser_t *parser, rbs_range_t keyword_range, r
|
|
|
2783
2888
|
|
|
2784
2889
|
CHECK_PARSE(parser_pop_typevar_table(parser));
|
|
2785
2890
|
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
rbs_loc_add_optional_child(loc, INTERN("type_params"), type_params_range);
|
|
2792
|
-
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);
|
|
2793
2896
|
|
|
2794
|
-
*class_decl = rbs_ast_declarations_class_new(ALLOCATOR(), loc, name, type_params, super, members, annotations, comment);
|
|
2795
2897
|
return true;
|
|
2796
2898
|
}
|
|
2797
2899
|
|
|
@@ -2825,14 +2927,9 @@ static bool parse_class_decl(rbs_parser_t *parser, rbs_position_t comment_pos, r
|
|
|
2825
2927
|
.end = old_name_range.end,
|
|
2826
2928
|
};
|
|
2827
2929
|
|
|
2828
|
-
|
|
2829
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 4);
|
|
2830
|
-
rbs_loc_add_required_child(loc, INTERN("keyword"), keyword_range);
|
|
2831
|
-
rbs_loc_add_required_child(loc, INTERN("new_name"), class_name_range);
|
|
2832
|
-
rbs_loc_add_required_child(loc, INTERN("eq"), eq_range);
|
|
2833
|
-
rbs_loc_add_optional_child(loc, INTERN("old_name"), old_name_range);
|
|
2930
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(decl_range);
|
|
2834
2931
|
|
|
2835
|
-
*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));
|
|
2836
2933
|
} else {
|
|
2837
2934
|
rbs_ast_declarations_class_t *class_decl0 = NULL;
|
|
2838
2935
|
CHECK_PARSE(parse_class_decl0(parser, keyword_range, class_name, class_name_range, comment, annotations, &class_decl0));
|
|
@@ -2958,7 +3055,7 @@ static bool parse_decl(rbs_parser_t *parser, rbs_node_t **decl) {
|
|
|
2958
3055
|
| {} <> (empty -- returns empty namespace)
|
|
2959
3056
|
*/
|
|
2960
3057
|
NODISCARD
|
|
2961
|
-
static bool parse_namespace(rbs_parser_t *parser, rbs_range_t *rg, rbs_namespace_t **
|
|
3058
|
+
static bool parse_namespace(rbs_parser_t *parser, rbs_range_t *rg, rbs_namespace_t **out_ns) {
|
|
2962
3059
|
bool is_absolute = false;
|
|
2963
3060
|
|
|
2964
3061
|
if (parser->next_token.type == pCOLON2) {
|
|
@@ -2975,8 +3072,8 @@ static bool parse_namespace(rbs_parser_t *parser, rbs_range_t *rg, rbs_namespace
|
|
|
2975
3072
|
|
|
2976
3073
|
while (true) {
|
|
2977
3074
|
if (parser->next_token.type == tUIDENT && parser->next_token2.type == pCOLON2) {
|
|
2978
|
-
|
|
2979
|
-
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));
|
|
2980
3077
|
rbs_node_list_append(path, (rbs_node_t *) symbol);
|
|
2981
3078
|
if (rbs_null_position_p(rg->start)) {
|
|
2982
3079
|
rg->start = parser->next_token.range.start;
|
|
@@ -2989,7 +3086,7 @@ static bool parse_namespace(rbs_parser_t *parser, rbs_range_t *rg, rbs_namespace
|
|
|
2989
3086
|
}
|
|
2990
3087
|
}
|
|
2991
3088
|
|
|
2992
|
-
*
|
|
3089
|
+
*out_ns = rbs_namespace_new(ALLOCATOR(), RBS_RANGE_LEX2AST(*rg), path, is_absolute);
|
|
2993
3090
|
return true;
|
|
2994
3091
|
}
|
|
2995
3092
|
|
|
@@ -3004,8 +3101,8 @@ NODISCARD
|
|
|
3004
3101
|
static bool parse_use_clauses(rbs_parser_t *parser, rbs_node_list_t *clauses) {
|
|
3005
3102
|
while (true) {
|
|
3006
3103
|
rbs_range_t namespace_range = NULL_RANGE;
|
|
3007
|
-
rbs_namespace_t *
|
|
3008
|
-
CHECK_PARSE(parse_namespace(parser, &namespace_range, &
|
|
3104
|
+
rbs_namespace_t *ns = NULL;
|
|
3105
|
+
CHECK_PARSE(parse_namespace(parser, &namespace_range, &ns));
|
|
3009
3106
|
|
|
3010
3107
|
switch (parser->next_token.type) {
|
|
3011
3108
|
case tLIDENT:
|
|
@@ -3017,9 +3114,9 @@ static bool parse_use_clauses(rbs_parser_t *parser, rbs_node_list_t *clauses) {
|
|
|
3017
3114
|
|
|
3018
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 };
|
|
3019
3116
|
|
|
3020
|
-
|
|
3021
|
-
rbs_ast_symbol_t *symbol = rbs_ast_symbol_new(ALLOCATOR(),
|
|
3022
|
-
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);
|
|
3023
3120
|
|
|
3024
3121
|
rbs_range_t keyword_range = NULL_RANGE;
|
|
3025
3122
|
rbs_range_t new_name_range = NULL_RANGE;
|
|
@@ -3033,19 +3130,18 @@ static bool parse_use_clauses(rbs_parser_t *parser, rbs_node_list_t *clauses) {
|
|
|
3033
3130
|
if (ident_type == tLIDENT) ADVANCE_ASSERT(parser, tLIDENT);
|
|
3034
3131
|
if (ident_type == tULIDENT) ADVANCE_ASSERT(parser, tULIDENT);
|
|
3035
3132
|
|
|
3036
|
-
|
|
3037
|
-
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));
|
|
3038
3135
|
new_name_range = parser->current_token.range;
|
|
3039
3136
|
clause_range.end = new_name_range.end;
|
|
3040
3137
|
}
|
|
3041
3138
|
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
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);
|
|
3047
3144
|
|
|
3048
|
-
rbs_ast_directives_use_single_clause_t *clause = rbs_ast_directives_use_single_clause_new(ALLOCATOR(), loc, type_name, new_name);
|
|
3049
3145
|
rbs_node_list_append(clauses, (rbs_node_t *) clause);
|
|
3050
3146
|
|
|
3051
3147
|
break;
|
|
@@ -3057,12 +3153,9 @@ static bool parse_use_clauses(rbs_parser_t *parser, rbs_node_list_t *clauses) {
|
|
|
3057
3153
|
rbs_range_t star_range = parser->current_token.range;
|
|
3058
3154
|
clause_range.end = star_range.end;
|
|
3059
3155
|
|
|
3060
|
-
|
|
3061
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 2);
|
|
3062
|
-
rbs_loc_add_required_child(loc, INTERN("namespace"), namespace_range);
|
|
3063
|
-
rbs_loc_add_required_child(loc, INTERN("star"), star_range);
|
|
3156
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(clause_range);
|
|
3064
3157
|
|
|
3065
|
-
rbs_ast_directives_use_wildcard_clause_t *clause = rbs_ast_directives_use_wildcard_clause_new(ALLOCATOR(), loc,
|
|
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));
|
|
3066
3159
|
rbs_node_list_append(clauses, (rbs_node_t *) clause);
|
|
3067
3160
|
|
|
3068
3161
|
break;
|
|
@@ -3098,34 +3191,34 @@ static bool parse_use_directive(rbs_parser_t *parser, rbs_ast_directives_use_t *
|
|
|
3098
3191
|
rbs_range_t directive_range = keyword_range;
|
|
3099
3192
|
directive_range.end = parser->current_token.range.end;
|
|
3100
3193
|
|
|
3101
|
-
|
|
3102
|
-
rbs_loc_alloc_children(ALLOCATOR(), loc, 1);
|
|
3103
|
-
rbs_loc_add_required_child(loc, INTERN("keyword"), keyword_range);
|
|
3194
|
+
rbs_location_range loc = RBS_RANGE_LEX2AST(directive_range);
|
|
3104
3195
|
|
|
3105
|
-
*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));
|
|
3106
3197
|
}
|
|
3107
3198
|
|
|
3108
3199
|
return true;
|
|
3109
3200
|
}
|
|
3110
3201
|
|
|
3111
3202
|
static rbs_ast_comment_t *parse_comment_lines(rbs_parser_t *parser, rbs_comment_t *com) {
|
|
3112
|
-
size_t hash_bytes = parser->
|
|
3113
|
-
size_t space_bytes = parser->
|
|
3203
|
+
size_t hash_bytes = parser->lexer->encoding->char_width((const uint8_t *) "#", (size_t) 1);
|
|
3204
|
+
size_t space_bytes = parser->lexer->encoding->char_width((const uint8_t *) " ", (size_t) 1);
|
|
3114
3205
|
|
|
3115
3206
|
rbs_buffer_t rbs_buffer;
|
|
3116
3207
|
rbs_buffer_init(ALLOCATOR(), &rbs_buffer);
|
|
3117
3208
|
|
|
3118
|
-
for (size_t i = 0; i < com->
|
|
3119
|
-
rbs_token_t tok = com->
|
|
3209
|
+
for (size_t i = 0; i < com->line_tokens_count; i++) {
|
|
3210
|
+
rbs_token_t tok = com->line_tokens[i];
|
|
3120
3211
|
|
|
3121
|
-
const char *comment_start = parser->
|
|
3212
|
+
const char *comment_start = parser->lexer->string.start + tok.range.start.byte_pos + hash_bytes;
|
|
3122
3213
|
size_t comment_bytes = RBS_RANGE_BYTES(tok.range) - hash_bytes;
|
|
3123
3214
|
|
|
3124
3215
|
rbs_string_t str = rbs_string_new(
|
|
3125
3216
|
comment_start,
|
|
3126
|
-
parser->
|
|
3217
|
+
parser->lexer->string.end
|
|
3127
3218
|
);
|
|
3128
|
-
|
|
3219
|
+
|
|
3220
|
+
// Assumes the input is ASCII compatible
|
|
3221
|
+
unsigned char c = str.start[0];
|
|
3129
3222
|
|
|
3130
3223
|
if (c == ' ') {
|
|
3131
3224
|
comment_start += space_bytes;
|
|
@@ -3138,7 +3231,12 @@ static rbs_ast_comment_t *parse_comment_lines(rbs_parser_t *parser, rbs_comment_
|
|
|
3138
3231
|
|
|
3139
3232
|
return rbs_ast_comment_new(
|
|
3140
3233
|
ALLOCATOR(),
|
|
3141
|
-
|
|
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
|
+
},
|
|
3142
3240
|
rbs_buffer_to_string(&rbs_buffer)
|
|
3143
3241
|
);
|
|
3144
3242
|
}
|
|
@@ -3160,42 +3258,43 @@ static rbs_comment_t *comment_get_comment(rbs_comment_t *com, int line) {
|
|
|
3160
3258
|
}
|
|
3161
3259
|
|
|
3162
3260
|
static void comment_insert_new_line(rbs_allocator_t *allocator, rbs_comment_t *com, rbs_token_t comment_token) {
|
|
3163
|
-
if (com->
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
com->
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
rbs_token_t *
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
com->tokens = rbs_allocator_calloc(allocator, com->line_size, rbs_token_t);
|
|
3176
|
-
}
|
|
3261
|
+
if (com->line_tokens_count == com->line_tokens_capacity) {
|
|
3262
|
+
size_t old_size = com->line_tokens_capacity;
|
|
3263
|
+
size_t new_size = old_size * 2;
|
|
3264
|
+
com->line_tokens_capacity = new_size;
|
|
3265
|
+
|
|
3266
|
+
com->line_tokens = rbs_allocator_realloc(
|
|
3267
|
+
allocator,
|
|
3268
|
+
com->line_tokens,
|
|
3269
|
+
sizeof(rbs_token_t) * old_size,
|
|
3270
|
+
sizeof(rbs_token_t) * new_size,
|
|
3271
|
+
rbs_token_t
|
|
3272
|
+
);
|
|
3177
3273
|
}
|
|
3178
3274
|
|
|
3179
|
-
com->
|
|
3275
|
+
com->line_tokens[com->line_tokens_count++] = comment_token;
|
|
3180
3276
|
com->end = comment_token.range.end;
|
|
3181
3277
|
}
|
|
3182
3278
|
|
|
3183
3279
|
static rbs_comment_t *alloc_comment(rbs_allocator_t *allocator, rbs_token_t comment_token, rbs_comment_t *last_comment) {
|
|
3184
3280
|
rbs_comment_t *new_comment = rbs_allocator_alloc(allocator, rbs_comment_t);
|
|
3185
3281
|
|
|
3282
|
+
size_t initial_line_capacity = 10;
|
|
3283
|
+
|
|
3284
|
+
rbs_token_t *tokens = rbs_allocator_calloc(allocator, initial_line_capacity, rbs_token_t);
|
|
3285
|
+
tokens[0] = comment_token;
|
|
3286
|
+
|
|
3186
3287
|
*new_comment = (rbs_comment_t) {
|
|
3187
3288
|
.start = comment_token.range.start,
|
|
3188
3289
|
.end = comment_token.range.end,
|
|
3189
3290
|
|
|
3190
|
-
.
|
|
3191
|
-
.
|
|
3192
|
-
.
|
|
3291
|
+
.line_tokens_capacity = initial_line_capacity,
|
|
3292
|
+
.line_tokens_count = 1,
|
|
3293
|
+
.line_tokens = tokens,
|
|
3193
3294
|
|
|
3194
3295
|
.next_comment = last_comment,
|
|
3195
3296
|
};
|
|
3196
3297
|
|
|
3197
|
-
comment_insert_new_line(allocator, new_comment, comment_token);
|
|
3198
|
-
|
|
3199
3298
|
return new_comment;
|
|
3200
3299
|
}
|
|
3201
3300
|
|
|
@@ -3239,7 +3338,7 @@ bool rbs_parse_signature(rbs_parser_t *parser, rbs_signature_t **signature) {
|
|
|
3239
3338
|
}
|
|
3240
3339
|
|
|
3241
3340
|
signature_range.end = parser->current_token.range.end;
|
|
3242
|
-
*signature = rbs_signature_new(ALLOCATOR(),
|
|
3341
|
+
*signature = rbs_signature_new(ALLOCATOR(), RBS_RANGE_LEX2AST(signature_range), dirs, decls);
|
|
3243
3342
|
return true;
|
|
3244
3343
|
}
|
|
3245
3344
|
|
|
@@ -3340,7 +3439,7 @@ void rbs_parser_advance(rbs_parser_t *parser) {
|
|
|
3340
3439
|
break;
|
|
3341
3440
|
}
|
|
3342
3441
|
|
|
3343
|
-
parser->next_token3 = rbs_lexer_next_token(parser->
|
|
3442
|
+
parser->next_token3 = rbs_lexer_next_token(parser->lexer);
|
|
3344
3443
|
|
|
3345
3444
|
if (parser->next_token3.type == tCOMMENT) {
|
|
3346
3445
|
// skip
|
|
@@ -3363,6 +3462,14 @@ void rbs_print_token(rbs_token_t tok) {
|
|
|
3363
3462
|
);
|
|
3364
3463
|
}
|
|
3365
3464
|
|
|
3465
|
+
void rbs_print_lexer(rbs_lexer_t *lexer) {
|
|
3466
|
+
printf("Lexer: (range = %d...%d, encoding = %s\n", lexer->start_pos, lexer->end_pos, lexer->encoding->name);
|
|
3467
|
+
printf(" start = { char_pos = %d, byte_pos = %d }\n", lexer->start.char_pos, lexer->start.byte_pos);
|
|
3468
|
+
printf(" current = { char_pos = %d, byte_pos = %d }\n", lexer->current.char_pos, lexer->current.byte_pos);
|
|
3469
|
+
printf(" character = { code_point = %d (%c), bytes = %zu }\n", lexer->current_code_point, lexer->current_code_point < 256 ? lexer->current_code_point : '?', lexer->current_character_bytes);
|
|
3470
|
+
printf(" first_token_of_line = %s\n", lexer->first_token_of_line ? "true" : "false");
|
|
3471
|
+
}
|
|
3472
|
+
|
|
3366
3473
|
rbs_ast_comment_t *rbs_parser_get_comment(rbs_parser_t *parser, int subject_line) {
|
|
3367
3474
|
int comment_line = subject_line - 1;
|
|
3368
3475
|
|
|
@@ -3391,14 +3498,30 @@ rbs_lexer_t *rbs_lexer_new(rbs_allocator_t *allocator, rbs_string_t string, cons
|
|
|
3391
3498
|
.end_pos = end_pos,
|
|
3392
3499
|
.current = start_position,
|
|
3393
3500
|
.start = { 0 },
|
|
3394
|
-
.first_token_of_line =
|
|
3395
|
-
.
|
|
3501
|
+
.first_token_of_line = true,
|
|
3502
|
+
.current_character_bytes = 0,
|
|
3503
|
+
.current_code_point = '\0',
|
|
3396
3504
|
.encoding = encoding,
|
|
3397
3505
|
};
|
|
3398
3506
|
|
|
3399
|
-
|
|
3507
|
+
unsigned int codepoint;
|
|
3508
|
+
size_t bytes;
|
|
3509
|
+
|
|
3510
|
+
if (rbs_next_char(lexer, &codepoint, &bytes)) {
|
|
3511
|
+
lexer->current_code_point = codepoint;
|
|
3512
|
+
lexer->current_character_bytes = bytes;
|
|
3513
|
+
} else {
|
|
3514
|
+
lexer->current_code_point = '\0';
|
|
3515
|
+
lexer->current_character_bytes = 1;
|
|
3516
|
+
}
|
|
3517
|
+
|
|
3518
|
+
if (start_pos > 0) {
|
|
3519
|
+
while (lexer->current.byte_pos < start_pos) {
|
|
3520
|
+
rbs_skip(lexer);
|
|
3521
|
+
}
|
|
3522
|
+
}
|
|
3523
|
+
|
|
3400
3524
|
lexer->start = lexer->current;
|
|
3401
|
-
lexer->first_token_of_line = lexer->current.column == 0;
|
|
3402
3525
|
|
|
3403
3526
|
return lexer;
|
|
3404
3527
|
}
|
|
@@ -3410,7 +3533,7 @@ rbs_parser_t *rbs_parser_new(rbs_string_t string, const rbs_encoding_t *encoding
|
|
|
3410
3533
|
rbs_parser_t *parser = rbs_allocator_alloc(allocator, rbs_parser_t);
|
|
3411
3534
|
|
|
3412
3535
|
*parser = (rbs_parser_t) {
|
|
3413
|
-
.
|
|
3536
|
+
.lexer = lexer,
|
|
3414
3537
|
|
|
3415
3538
|
.current_token = NullToken,
|
|
3416
3539
|
.next_token = NullToken,
|
|
@@ -3491,16 +3614,17 @@ static bool parse_method_overload(rbs_parser_t *parser, rbs_node_list_t *annotat
|
|
|
3491
3614
|
return false;
|
|
3492
3615
|
}
|
|
3493
3616
|
|
|
3494
|
-
return rbs_parse_method_type(parser, method_type);
|
|
3617
|
+
return rbs_parse_method_type(parser, method_type, false, true);
|
|
3495
3618
|
}
|
|
3496
3619
|
|
|
3497
3620
|
/*
|
|
3498
|
-
inline_method_overloads ::= {} <overload>
|
|
3621
|
+
inline_method_overloads ::= {} <overload> -- returns true
|
|
3499
3622
|
| {} overload `|` ... `|` overload -- returns true
|
|
3623
|
+
| {} overload `|` ... `|` `...` -- returns true (dot3_location is set)
|
|
3500
3624
|
| {<>} -- returns false
|
|
3501
3625
|
*/
|
|
3502
3626
|
NODISCARD
|
|
3503
|
-
static bool parse_inline_method_overloads(rbs_parser_t *parser, rbs_node_list_t *overloads,
|
|
3627
|
+
static bool parse_inline_method_overloads(rbs_parser_t *parser, rbs_node_list_t *overloads, rbs_location_range_list_t *bar_locations, rbs_location_range *dot3_location) {
|
|
3504
3628
|
while (true) {
|
|
3505
3629
|
rbs_node_list_t *annotations = rbs_node_list_new(ALLOCATOR());
|
|
3506
3630
|
rbs_method_type_t *method_type = NULL;
|
|
@@ -3509,7 +3633,7 @@ static bool parse_inline_method_overloads(rbs_parser_t *parser, rbs_node_list_t
|
|
|
3509
3633
|
return false;
|
|
3510
3634
|
}
|
|
3511
3635
|
|
|
3512
|
-
|
|
3636
|
+
rbs_location_range location = rbs_location_range_current_token(parser);
|
|
3513
3637
|
rbs_ast_members_method_definition_overload_t *overload = rbs_ast_members_method_definition_overload_new(
|
|
3514
3638
|
ALLOCATOR(),
|
|
3515
3639
|
location,
|
|
@@ -3519,11 +3643,17 @@ static bool parse_inline_method_overloads(rbs_parser_t *parser, rbs_node_list_t
|
|
|
3519
3643
|
rbs_node_list_append(overloads, (rbs_node_t *) overload);
|
|
3520
3644
|
|
|
3521
3645
|
if (parser->next_token.type == pBAR) {
|
|
3522
|
-
|
|
3646
|
+
rbs_location_range bar_range = RBS_RANGE_LEX2AST(parser->next_token.range);
|
|
3523
3647
|
|
|
3524
3648
|
rbs_parser_advance(parser);
|
|
3525
3649
|
|
|
3526
|
-
|
|
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
|
+
}
|
|
3527
3657
|
|
|
3528
3658
|
continue;
|
|
3529
3659
|
}
|
|
@@ -3533,16 +3663,55 @@ static bool parse_inline_method_overloads(rbs_parser_t *parser, rbs_node_list_t
|
|
|
3533
3663
|
}
|
|
3534
3664
|
|
|
3535
3665
|
NODISCARD
|
|
3536
|
-
static bool parse_inline_comment(rbs_parser_t *parser,
|
|
3666
|
+
static bool parse_inline_comment(rbs_parser_t *parser, rbs_location_range *comment_range) {
|
|
3537
3667
|
if (parser->next_token.type != tINLINECOMMENT) {
|
|
3538
|
-
*
|
|
3668
|
+
*comment_range = RBS_LOCATION_NULL_RANGE;
|
|
3539
3669
|
return true;
|
|
3540
3670
|
}
|
|
3541
3671
|
|
|
3542
|
-
|
|
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) {
|
|
3543
3680
|
rbs_parser_advance(parser);
|
|
3544
3681
|
|
|
3545
|
-
|
|
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
|
+
|
|
3546
3715
|
return true;
|
|
3547
3716
|
}
|
|
3548
3717
|
|
|
@@ -3565,13 +3734,12 @@ static bool parse_inline_leading_annotation(rbs_parser_t *parser, rbs_ast_ruby_a
|
|
|
3565
3734
|
.end = parser->current_token.range.end
|
|
3566
3735
|
};
|
|
3567
3736
|
|
|
3568
|
-
|
|
3569
|
-
rbs_location_t *colon_loc = rbs_location_new(ALLOCATOR(), colon_range);
|
|
3737
|
+
rbs_location_range full_loc = RBS_RANGE_LEX2AST(full_range);
|
|
3570
3738
|
|
|
3571
3739
|
*annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_colon_method_type_annotation_new(
|
|
3572
3740
|
ALLOCATOR(),
|
|
3573
3741
|
full_loc,
|
|
3574
|
-
|
|
3742
|
+
RBS_RANGE_LEX2AST(colon_range),
|
|
3575
3743
|
annotations,
|
|
3576
3744
|
(rbs_node_t *) method_type
|
|
3577
3745
|
);
|
|
@@ -3582,14 +3750,39 @@ static bool parse_inline_leading_annotation(rbs_parser_t *parser, rbs_ast_ruby_a
|
|
|
3582
3750
|
rbs_parser_advance(parser);
|
|
3583
3751
|
|
|
3584
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
|
+
}
|
|
3585
3777
|
case pLPAREN:
|
|
3586
3778
|
case pLBRACKET:
|
|
3587
3779
|
case pLBRACE:
|
|
3588
3780
|
case tANNOTATION: {
|
|
3589
3781
|
rbs_node_list_t *overloads = rbs_node_list_new(ALLOCATOR());
|
|
3590
|
-
|
|
3782
|
+
rbs_location_range_list_t *bar_locations = rbs_location_range_list_new(ALLOCATOR());
|
|
3783
|
+
rbs_location_range dot3_location = RBS_LOCATION_NULL_RANGE;
|
|
3591
3784
|
|
|
3592
|
-
if (!parse_inline_method_overloads(parser, overloads, bar_locations)) {
|
|
3785
|
+
if (!parse_inline_method_overloads(parser, overloads, bar_locations, &dot3_location)) {
|
|
3593
3786
|
return false;
|
|
3594
3787
|
}
|
|
3595
3788
|
|
|
@@ -3598,25 +3791,63 @@ static bool parse_inline_leading_annotation(rbs_parser_t *parser, rbs_ast_ruby_a
|
|
|
3598
3791
|
.end = parser->current_token.range.end
|
|
3599
3792
|
};
|
|
3600
3793
|
|
|
3601
|
-
|
|
3602
|
-
rbs_location_t *rbs_loc = rbs_location_new(ALLOCATOR(), rbs_range);
|
|
3794
|
+
rbs_location_range full_loc = RBS_RANGE_LEX2AST(full_range);
|
|
3603
3795
|
|
|
3604
3796
|
*annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_method_types_annotation_new(
|
|
3605
3797
|
ALLOCATOR(),
|
|
3606
3798
|
full_loc,
|
|
3607
|
-
|
|
3799
|
+
RBS_RANGE_LEX2AST(rbs_range),
|
|
3608
3800
|
overloads,
|
|
3609
|
-
bar_locations
|
|
3801
|
+
bar_locations,
|
|
3802
|
+
dot3_location
|
|
3610
3803
|
);
|
|
3611
3804
|
return true;
|
|
3612
3805
|
}
|
|
3613
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: {
|
|
3614
3837
|
rbs_parser_advance(parser);
|
|
3615
3838
|
|
|
3616
|
-
rbs_range_t
|
|
3617
|
-
|
|
3839
|
+
rbs_range_t return_range = parser->current_token.range;
|
|
3840
|
+
|
|
3841
|
+
ADVANCE_ASSERT(parser, pCOLON);
|
|
3618
3842
|
|
|
3619
|
-
|
|
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;
|
|
3620
3851
|
if (!parse_inline_comment(parser, &comment_loc)) {
|
|
3621
3852
|
return false;
|
|
3622
3853
|
}
|
|
@@ -3626,35 +3857,41 @@ static bool parse_inline_leading_annotation(rbs_parser_t *parser, rbs_ast_ruby_a
|
|
|
3626
3857
|
.end = parser->current_token.range.end
|
|
3627
3858
|
};
|
|
3628
3859
|
|
|
3629
|
-
|
|
3630
|
-
rbs_location_t *rbs_loc = rbs_location_new(ALLOCATOR(), rbs_range);
|
|
3860
|
+
rbs_location_range full_loc = RBS_RANGE_LEX2AST(full_range);
|
|
3631
3861
|
|
|
3632
|
-
*annotation = (rbs_ast_ruby_annotations_t *)
|
|
3862
|
+
*annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_return_type_annotation_new(
|
|
3633
3863
|
ALLOCATOR(),
|
|
3634
3864
|
full_loc,
|
|
3635
|
-
|
|
3636
|
-
|
|
3865
|
+
RBS_RANGE_LEX2AST(rbs_range),
|
|
3866
|
+
RBS_RANGE_LEX2AST(return_range),
|
|
3867
|
+
RBS_RANGE_LEX2AST(colon_range),
|
|
3868
|
+
return_type,
|
|
3637
3869
|
comment_loc
|
|
3638
3870
|
);
|
|
3639
3871
|
return true;
|
|
3640
3872
|
}
|
|
3641
|
-
case
|
|
3873
|
+
case tAIDENT: {
|
|
3874
|
+
// Parse instance variable annotation: @rbs @name: Type
|
|
3642
3875
|
rbs_parser_advance(parser);
|
|
3643
3876
|
|
|
3644
|
-
rbs_range_t
|
|
3645
|
-
|
|
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);
|
|
3646
3884
|
|
|
3647
3885
|
ADVANCE_ASSERT(parser, pCOLON);
|
|
3648
3886
|
|
|
3649
3887
|
rbs_range_t colon_range = parser->current_token.range;
|
|
3650
|
-
rbs_location_t *colon_loc = rbs_location_new(ALLOCATOR(), colon_range);
|
|
3651
3888
|
|
|
3652
|
-
rbs_node_t *
|
|
3653
|
-
if (!rbs_parse_type(parser, &
|
|
3889
|
+
rbs_node_t *type = NULL;
|
|
3890
|
+
if (!rbs_parse_type(parser, &type, false, true, true)) {
|
|
3654
3891
|
return false;
|
|
3655
3892
|
}
|
|
3656
3893
|
|
|
3657
|
-
|
|
3894
|
+
rbs_location_range comment_loc = RBS_LOCATION_NULL_RANGE;
|
|
3658
3895
|
if (!parse_inline_comment(parser, &comment_loc)) {
|
|
3659
3896
|
return false;
|
|
3660
3897
|
}
|
|
@@ -3664,16 +3901,153 @@ static bool parse_inline_leading_annotation(rbs_parser_t *parser, rbs_ast_ruby_a
|
|
|
3664
3901
|
.end = parser->current_token.range.end
|
|
3665
3902
|
};
|
|
3666
3903
|
|
|
3667
|
-
|
|
3668
|
-
rbs_location_t *rbs_loc = rbs_location_new(ALLOCATOR(), rbs_range);
|
|
3904
|
+
rbs_location_range full_loc = RBS_RANGE_LEX2AST(full_range);
|
|
3669
3905
|
|
|
3670
|
-
*annotation = (rbs_ast_ruby_annotations_t *)
|
|
3906
|
+
*annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_instance_variable_annotation_new(
|
|
3671
3907
|
ALLOCATOR(),
|
|
3672
3908
|
full_loc,
|
|
3673
|
-
|
|
3674
|
-
|
|
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,
|
|
3675
3956
|
colon_loc,
|
|
3676
|
-
|
|
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,
|
|
3677
4051
|
comment_loc
|
|
3678
4052
|
);
|
|
3679
4053
|
return true;
|
|
@@ -3699,8 +4073,61 @@ static bool parse_inline_trailing_annotation(rbs_parser_t *parser, rbs_ast_ruby_
|
|
|
3699
4073
|
case pCOLON: {
|
|
3700
4074
|
rbs_parser_advance(parser);
|
|
3701
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
|
|
3702
4129
|
rbs_node_t *type = NULL;
|
|
3703
|
-
if (!rbs_parse_type(parser, &type)) {
|
|
4130
|
+
if (!rbs_parse_type(parser, &type, true, true, true)) {
|
|
3704
4131
|
return false;
|
|
3705
4132
|
}
|
|
3706
4133
|
|
|
@@ -3709,17 +4136,51 @@ static bool parse_inline_trailing_annotation(rbs_parser_t *parser, rbs_ast_ruby_
|
|
|
3709
4136
|
.end = parser->current_token.range.end
|
|
3710
4137
|
};
|
|
3711
4138
|
|
|
3712
|
-
|
|
3713
|
-
rbs_location_t *prefix_loc = rbs_location_new(ALLOCATOR(), prefix_range);
|
|
4139
|
+
rbs_location_range full_loc = RBS_RANGE_LEX2AST(full_range);
|
|
3714
4140
|
|
|
3715
4141
|
*annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_node_type_assertion_new(
|
|
3716
4142
|
ALLOCATOR(),
|
|
3717
4143
|
full_loc,
|
|
3718
|
-
|
|
4144
|
+
RBS_RANGE_LEX2AST(prefix_range),
|
|
3719
4145
|
type
|
|
3720
4146
|
);
|
|
3721
4147
|
return true;
|
|
3722
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
|
+
}
|
|
3723
4184
|
default: {
|
|
3724
4185
|
rbs_parser_set_error(parser, parser->next_token, true, "unexpected token for inline trailing annotation");
|
|
3725
4186
|
return false;
|