Skip to content

Commit 0b88dde

Browse files
soutaroclaude
andcommitted
Include the trailing ? in a keyword key's symbol location
`parse_keyword_key` handles keys like `foo?:`, where the `?` is part of the method-name-ish key: it interns `foo?` as the constant, but built the symbol node's location from `current_token` alone, so the location covered `foo` and stopped short of the `?`. Extend the range to the end of the `?` token so the location matches the name it is the location of. This is not observable from Ruby -- `rbs_ast_symbol_t` is translated with `ID2SYM` and the wasm serializer writes only the `constant_id`, both of which drop the location. It matters for consumers that read the C AST directly, such as the Rust crate's owned AST. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent aa48bf2 commit 0b88dde

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/parser.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,18 +405,21 @@ NODISCARD
405405
static bool parse_keyword_key(rbs_parser_t *parser, rbs_ast_symbol_t **key) {
406406
rbs_parser_advance(parser);
407407

408-
rbs_location_range symbol_range = rbs_location_range_current_token(parser);
408+
rbs_range_t symbol_range = parser->current_token.range;
409409

410410
if (parser->next_token.type == pQUESTION) {
411+
// The `?` is part of the key, so it is part of the location too.
412+
symbol_range.end = parser->next_token.range.end;
413+
411414
*key = rbs_ast_symbol_new(
412415
ALLOCATOR(),
413-
symbol_range,
416+
RBS_RANGE_LEX2AST(symbol_range),
414417
&parser->constant_pool,
415418
intern_token_start_end(parser, parser->current_token, parser->next_token)
416419
);
417420
rbs_parser_advance(parser);
418421
} else {
419-
*key = rbs_ast_symbol_new(ALLOCATOR(), symbol_range, &parser->constant_pool, INTERN_TOKEN(parser, parser->current_token));
422+
*key = rbs_ast_symbol_new(ALLOCATOR(), RBS_RANGE_LEX2AST(symbol_range), &parser->constant_pool, INTERN_TOKEN(parser, parser->current_token));
420423
}
421424

422425
return true;

0 commit comments

Comments
 (0)