Skip to content

Commit 64cacae

Browse files
committed
Expose a C method to parse type parameters.
This is useful to parse a "class signature" such as this: ```rb \#: [in A, B = String, out < Object] class Foo; end ``` Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
1 parent f032275 commit 64cacae

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

include/rbs/parser.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ bool rbs_parse_type(rbs_parser_t *parser, rbs_node_t **type);
130130
bool rbs_parse_method_type(rbs_parser_t *parser, rbs_method_type_t **method_type);
131131
bool rbs_parse_signature(rbs_parser_t *parser, rbs_signature_t **signature);
132132

133+
bool rbs_parse_type_params(rbs_parser_t *parser, bool module_type_params, rbs_node_list_t **params);
134+
133135
/**
134136
* Parse an inline leading annotation from a string.
135137
*

src/parser.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3258,6 +3258,19 @@ bool rbs_parse_signature(rbs_parser_t *parser, rbs_signature_t **signature) {
32583258
return true;
32593259
}
32603260

3261+
bool rbs_parse_type_params(rbs_parser_t *parser, bool module_type_params, rbs_node_list_t **params) {
3262+
if (parser->next_token.type != pLBRACKET) {
3263+
rbs_parser_set_error(parser, parser->next_token, true, "expected a token `pLBRACKET`");
3264+
return false;
3265+
}
3266+
3267+
rbs_range_t rg = NULL_RANGE;
3268+
rbs_parser_push_typevar_table(parser, true);
3269+
bool res = parse_type_params(parser, &rg, module_type_params, params);
3270+
rbs_parser_push_typevar_table(parser, false);
3271+
return res;
3272+
}
3273+
32613274
id_table *alloc_empty_table(rbs_allocator_t *allocator) {
32623275
id_table *table = rbs_allocator_alloc(allocator, id_table);
32633276

0 commit comments

Comments
 (0)