Skip to content

Commit

Permalink
Merge pull request #3416 from ruby/rescue-then
Browse files Browse the repository at this point in the history
Track then keyword on rescue nodes
  • Loading branch information
kddnewton authored Jan 16, 2025
2 parents d4c5007 + bde8ccc commit 9794bf2
Show file tree
Hide file tree
Showing 37 changed files with 93 additions and 3 deletions.
2 changes: 2 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4084,6 +4084,8 @@ nodes:
- on error: BackReferenceReadNode # => begin; rescue => $&; end
- on error: NumberedReferenceReadNode # => begin; rescue => $1; end
- on error: MissingNode # begin; rescue =>; end
- name: then_keyword_loc
type: location?
- name: statements
type: node?
kind: StatementsNode
Expand Down
10 changes: 7 additions & 3 deletions src/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -6675,6 +6675,7 @@ pm_rescue_node_create(pm_parser_t *parser, const pm_token_t *keyword) {
},
.keyword_loc = PM_LOCATION_TOKEN_VALUE(keyword),
.operator_loc = PM_OPTIONAL_LOCATION_NOT_PROVIDED_VALUE,
.then_keyword_loc = PM_OPTIONAL_LOCATION_NOT_PROVIDED_VALUE,
.reference = NULL,
.statements = NULL,
.subsequent = NULL,
Expand Down Expand Up @@ -15060,8 +15061,8 @@ parse_rescues(pm_parser_t *parser, size_t opening_newline_index, const pm_token_
case PM_TOKEN_NEWLINE:
case PM_TOKEN_SEMICOLON:
case PM_TOKEN_KEYWORD_THEN:
// Here we have a terminator for the rescue keyword, in which case we're
// going to just continue on.
// Here we have a terminator for the rescue keyword, in which
// case we're going to just continue on.
break;
default: {
if (token_begins_expression_p(parser->current.type) || match1(parser, PM_TOKEN_USTAR)) {
Expand Down Expand Up @@ -15093,9 +15094,12 @@ parse_rescues(pm_parser_t *parser, size_t opening_newline_index, const pm_token_
}

if (accept2(parser, PM_TOKEN_NEWLINE, PM_TOKEN_SEMICOLON)) {
accept1(parser, PM_TOKEN_KEYWORD_THEN);
if (accept1(parser, PM_TOKEN_KEYWORD_THEN)) {
rescue->then_keyword_loc = PM_OPTIONAL_LOCATION_TOKEN_VALUE(&parser->previous);
}
} else {
expect1(parser, PM_TOKEN_KEYWORD_THEN, PM_ERR_RESCUE_TERM);
rescue->then_keyword_loc = PM_OPTIONAL_LOCATION_TOKEN_VALUE(&parser->previous);
}

if (!match3(parser, PM_TOKEN_KEYWORD_ELSE, PM_TOKEN_KEYWORD_ENSURE, PM_TOKEN_KEYWORD_END)) {
Expand Down
2 changes: 2 additions & 0 deletions test/prism/snapshots/arrays.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions test/prism/snapshots/begin_rescue.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/prism/snapshots/blocks.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions test/prism/snapshots/classes.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/prism/snapshots/keywords.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/prism/snapshots/methods.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/prism/snapshots/modules.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/prism/snapshots/procs.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions test/prism/snapshots/rescue.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/prism/snapshots/seattlerb/defn_oneliner_rescue.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/prism/snapshots/seattlerb/defs_oneliner_rescue.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions test/prism/snapshots/seattlerb/parse_line_rescue.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/prism/snapshots/seattlerb/rescue_do_end_no_raise.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/prism/snapshots/seattlerb/rescue_do_end_rescued.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/prism/snapshots/seattlerb/rescue_in_block.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9794bf2

Please sign in to comment.