Skip to content

Commit 8746b6c

Browse files
committed
Allow skip as the param name
1 parent 3e50e9f commit 8746b6c

2 files changed

Lines changed: 40 additions & 25 deletions

File tree

src/parser.c

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3684,32 +3684,36 @@ static bool parse_inline_leading_annotation(rbs_parser_t *parser, rbs_ast_ruby_a
36843684
return true;
36853685
}
36863686
case kSKIP: {
3687-
rbs_parser_advance(parser);
3688-
3689-
rbs_range_t skip_range = parser->current_token.range;
3690-
rbs_location_t *skip_loc = rbs_location_new(ALLOCATOR(), skip_range);
3691-
3692-
rbs_location_t *comment_loc = NULL;
3693-
if (!parse_inline_comment(parser, &comment_loc)) {
3694-
return false;
3687+
if (parser->next_token2.type == pCOLON) {
3688+
return parse_inline_param_type_annotation(parser, annotation, rbs_range);
3689+
} else {
3690+
rbs_parser_advance(parser);
3691+
3692+
rbs_range_t skip_range = parser->current_token.range;
3693+
rbs_location_t *skip_loc = rbs_location_new(ALLOCATOR(), skip_range);
3694+
3695+
rbs_location_t *comment_loc = NULL;
3696+
if (!parse_inline_comment(parser, &comment_loc)) {
3697+
return false;
3698+
}
3699+
3700+
rbs_range_t full_range = {
3701+
.start = rbs_range.start,
3702+
.end = parser->current_token.range.end
3703+
};
3704+
3705+
rbs_location_t *full_loc = rbs_location_new(ALLOCATOR(), full_range);
3706+
rbs_location_t *rbs_loc = rbs_location_new(ALLOCATOR(), rbs_range);
3707+
3708+
*annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_skip_annotation_new(
3709+
ALLOCATOR(),
3710+
full_loc,
3711+
rbs_loc,
3712+
skip_loc,
3713+
comment_loc
3714+
);
3715+
return true;
36953716
}
3696-
3697-
rbs_range_t full_range = {
3698-
.start = rbs_range.start,
3699-
.end = parser->current_token.range.end
3700-
};
3701-
3702-
rbs_location_t *full_loc = rbs_location_new(ALLOCATOR(), full_range);
3703-
rbs_location_t *rbs_loc = rbs_location_new(ALLOCATOR(), rbs_range);
3704-
3705-
*annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_skip_annotation_new(
3706-
ALLOCATOR(),
3707-
full_loc,
3708-
rbs_loc,
3709-
skip_loc,
3710-
comment_loc
3711-
);
3712-
return true;
37133717
}
37143718
case kRETURN: {
37153719
rbs_parser_advance(parser);

test/rbs/inline_annotation_parsing_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,15 @@ def test_parse__param_type
135135
assert_equal "-- some comment here", annot.comment_location.source
136136
end
137137
end
138+
139+
def test_parse__param_type__skip
140+
Parser.parse_inline_leading_annotation("@rbs skip: untyped", 0...).tap do |annot|
141+
assert_instance_of AST::Ruby::Annotations::ParamTypeAnnotation, annot
142+
assert_equal "@rbs skip: untyped", annot.location.source
143+
assert_equal "skip", annot.name_location.source
144+
assert_equal ":", annot.colon_location.source
145+
assert_equal "untyped", annot.param_type.location.source
146+
assert_nil annot.comment_location
147+
end
148+
end
138149
end

0 commit comments

Comments
 (0)