Skip to content

Commit d64f6e9

Browse files
committed
Move require_eof handling to C API
1 parent 3c4b30a commit d64f6e9

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

ext/rbs_extension/main.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,10 @@ static VALUE parse_method_type_try(VALUE a) {
208208
}
209209

210210
rbs_method_type_t *method_type = NULL;
211-
rbs_parse_method_type(parser, &method_type);
211+
rbs_parse_method_type(parser, &method_type, RB_TEST(arg->require_eof));
212212

213213
raise_error_if_any(parser, arg->buffer);
214214

215-
if (RB_TEST(arg->require_eof)) {
216-
rbs_parser_advance(parser);
217-
if (parser->current_token.type != pEOF) {
218-
rbs_parser_set_error(parser, parser->current_token, true, "expected a token `%s`", rbs_token_type_str(pEOF));
219-
raise_error(parser->error, arg->buffer);
220-
}
221-
}
222-
223215
rbs_translation_context_t ctx = rbs_translation_context_create(
224216
&parser->constant_pool,
225217
arg->buffer,

include/rbs/parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ rbs_ast_comment_t *rbs_parser_get_comment(rbs_parser_t *parser, int subject_line
127127
void rbs_parser_set_error(rbs_parser_t *parser, rbs_token_t tok, bool syntax_error, const char *fmt, ...) RBS_ATTRIBUTE_FORMAT(4, 5);
128128

129129
bool rbs_parse_type(rbs_parser_t *parser, rbs_node_t **type, bool void_allowed, bool self_allowed);
130-
bool rbs_parse_method_type(rbs_parser_t *parser, rbs_method_type_t **method_type);
130+
bool rbs_parse_method_type(rbs_parser_t *parser, rbs_method_type_t **method_type, bool require_eof);
131131
bool rbs_parse_signature(rbs_parser_t *parser, rbs_signature_t **signature);
132132

133133
bool rbs_parse_type_params(rbs_parser_t *parser, bool module_type_params, rbs_node_list_t **params);

src/parser.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,7 +1551,7 @@ static bool parser_pop_typevar_table(rbs_parser_t *parser) {
15511551
method_type ::= {} type_params <function>
15521552
*/
15531553
// TODO: Should this be NODISCARD?
1554-
bool rbs_parse_method_type(rbs_parser_t *parser, rbs_method_type_t **method_type) {
1554+
bool rbs_parse_method_type(rbs_parser_t *parser, rbs_method_type_t **method_type, bool require_eof) {
15551555
rbs_parser_push_typevar_table(parser, false);
15561556

15571557
rbs_range_t rg;
@@ -1567,10 +1567,18 @@ bool rbs_parse_method_type(rbs_parser_t *parser, rbs_method_type_t **method_type
15671567
parse_function_result *result = rbs_allocator_alloc(ALLOCATOR(), parse_function_result);
15681568
CHECK_PARSE(parse_function(parser, false, &result, true));
15691569

1570+
CHECK_PARSE(parser_pop_typevar_table(parser));
1571+
15701572
rg.end = parser->current_token.range.end;
15711573
type_range.end = rg.end;
15721574

1573-
CHECK_PARSE(parser_pop_typevar_table(parser));
1575+
if (require_eof) {
1576+
rbs_parser_advance(parser);
1577+
if (parser->current_token.type != pEOF) {
1578+
rbs_parser_set_error(parser, parser->current_token, true, "expected a token `%s`", rbs_token_type_str(pEOF));
1579+
return false;
1580+
}
1581+
}
15741582

15751583
rbs_location_t *loc = rbs_location_new(ALLOCATOR(), rg);
15761584
rbs_loc_alloc_children(ALLOCATOR(), loc, 2);
@@ -1979,7 +1987,7 @@ static bool parse_member_def(rbs_parser_t *parser, bool instance_only, bool acce
19791987
case pLBRACKET:
19801988
case pQUESTION: {
19811989
rbs_method_type_t *method_type = NULL;
1982-
CHECK_PARSE(rbs_parse_method_type(parser, &method_type));
1990+
CHECK_PARSE(rbs_parse_method_type(parser, &method_type, false));
19831991

19841992
overload_range.end = parser->current_token.range.end;
19851993
rbs_location_t *loc = rbs_location_new(ALLOCATOR(), overload_range);
@@ -3607,7 +3615,7 @@ static bool parse_method_overload(rbs_parser_t *parser, rbs_node_list_t *annotat
36073615
return false;
36083616
}
36093617

3610-
return rbs_parse_method_type(parser, method_type);
3618+
return rbs_parse_method_type(parser, method_type, false);
36113619
}
36123620

36133621
/*

0 commit comments

Comments
 (0)