diff options
author | Kevin Newton <kddnewton@gmail.com> | 2023-08-28 09:06:19 -0400 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-08-29 19:33:31 +0000 |
commit | 5161c6c4cdf989ee63dbbe0baa81317f8e8ae491 (patch) | |
tree | 6cee5fb693c54815d999b612ce2c1a92777a556b | |
parent | 7a5df9d0ed7cbd0660803074b34623a1f1dc0768 (diff) | |
download | ruby-5161c6c4cdf989ee63dbbe0baa81317f8e8ae491.tar.gz |
[ruby/yarp] Statements inside ensure blocks can accept blocks
https://github.com/ruby/yarp/commit/be84ea5343
-rw-r--r-- | test/yarp/fixtures/begin_ensure.txt | 7 | ||||
-rw-r--r-- | test/yarp/snapshots/begin_ensure.txt | 97 | ||||
-rw-r--r-- | yarp/yarp.c | 14 |
3 files changed, 116 insertions, 2 deletions
diff --git a/test/yarp/fixtures/begin_ensure.txt b/test/yarp/fixtures/begin_ensure.txt index 1c6f9dac35..6cfb627453 100644 --- a/test/yarp/fixtures/begin_ensure.txt +++ b/test/yarp/fixtures/begin_ensure.txt @@ -12,3 +12,10 @@ begin a begin a; ensure b; end +begin begin:s.l begin ensure Module.new do + begin + break + ensure Module.new do + end + end +end end end end diff --git a/test/yarp/snapshots/begin_ensure.txt b/test/yarp/snapshots/begin_ensure.txt index e04a1236df..8e9873122b 100644 --- a/test/yarp/snapshots/begin_ensure.txt +++ b/test/yarp/snapshots/begin_ensure.txt @@ -1,6 +1,6 @@ -ProgramNode(0...94)( +ProgramNode(0...211)( [], - StatementsNode(0...94)( + StatementsNode(0...211)( [BeginNode(0...20)( (0...5), StatementsNode(6...7)( @@ -64,6 +64,99 @@ ProgramNode(0...94)( (91...94) ), (91...94) + ), + BeginNode(96...211)( + (96...101), + StatementsNode(102...207)( + [BeginNode(102...207)( + (102...107), + StatementsNode(107...203)( + [CallNode(107...203)( + SymbolNode(107...109)((107...108), (108...109), nil, "s"), + (109...110), + (110...111), + nil, + ArgumentsNode(112...203)( + [BeginNode(112...203)( + (112...117), + nil, + nil, + nil, + EnsureNode(118...203)( + (118...124), + StatementsNode(125...199)( + [CallNode(125...199)( + ConstantReadNode(125...131)(), + (131...132), + (132...135), + nil, + nil, + nil, + BlockNode(136...199)( + [], + nil, + StatementsNode(141...195)( + [BeginNode(141...195)( + (141...146), + StatementsNode(151...156)( + [BreakNode(151...156)(nil, (151...156))] + ), + nil, + nil, + EnsureNode(161...195)( + (161...167), + StatementsNode(168...189)( + [CallNode(168...189)( + ConstantReadNode(168...174)(), + (174...175), + (175...178), + nil, + nil, + nil, + BlockNode(179...189)( + [], + nil, + nil, + (179...181), + (186...189) + ), + 0, + "new" + )] + ), + (192...195) + ), + (192...195) + )] + ), + (136...138), + (196...199) + ), + 0, + "new" + )] + ), + (200...203) + ), + (200...203) + )] + ), + nil, + nil, + 0, + "l" + )] + ), + nil, + nil, + nil, + (204...207) + )] + ), + nil, + nil, + nil, + (208...211) )] ) ) diff --git a/yarp/yarp.c b/yarp/yarp.c index 8cd2c2007b..78c0a03cfe 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -9049,10 +9049,12 @@ parse_rescues(yp_parser_t *parser, yp_begin_node_t *parent_node) { } if (!match_any_type_p(parser, 3, YP_TOKEN_KEYWORD_ELSE, YP_TOKEN_KEYWORD_ENSURE, YP_TOKEN_KEYWORD_END)) { + yp_accepts_block_stack_push(parser, true); yp_statements_node_t *statements = parse_statements(parser, YP_CONTEXT_RESCUE); if (statements) { yp_rescue_node_statements_set(rescue, statements); } + yp_accepts_block_stack_pop(parser); accept_any(parser, 2, YP_TOKEN_NEWLINE, YP_TOKEN_SEMICOLON); } @@ -9083,7 +9085,9 @@ parse_rescues(yp_parser_t *parser, yp_begin_node_t *parent_node) { yp_statements_node_t *else_statements = NULL; if (!match_any_type_p(parser, 2, YP_TOKEN_KEYWORD_END, YP_TOKEN_KEYWORD_ENSURE)) { + yp_accepts_block_stack_push(parser, true); else_statements = parse_statements(parser, YP_CONTEXT_RESCUE_ELSE); + yp_accepts_block_stack_pop(parser); accept_any(parser, 2, YP_TOKEN_NEWLINE, YP_TOKEN_SEMICOLON); } @@ -9097,7 +9101,9 @@ parse_rescues(yp_parser_t *parser, yp_begin_node_t *parent_node) { yp_statements_node_t *ensure_statements = NULL; if (!match_type_p(parser, YP_TOKEN_KEYWORD_END)) { + yp_accepts_block_stack_push(parser, true); ensure_statements = parse_statements(parser, YP_CONTEXT_ENSURE); + yp_accepts_block_stack_pop(parser); accept_any(parser, 2, YP_TOKEN_NEWLINE, YP_TOKEN_SEMICOLON); } @@ -9207,7 +9213,9 @@ parse_block(yp_parser_t *parser) { } else { if (!match_type_p(parser, YP_TOKEN_KEYWORD_END)) { if (!match_any_type_p(parser, 3, YP_TOKEN_KEYWORD_RESCUE, YP_TOKEN_KEYWORD_ELSE, YP_TOKEN_KEYWORD_ENSURE)) { + yp_accepts_block_stack_push(parser, true); statements = (yp_node_t *) parse_statements(parser, YP_CONTEXT_BLOCK_KEYWORDS); + yp_accepts_block_stack_pop(parser); } if (match_any_type_p(parser, 2, YP_TOKEN_KEYWORD_RESCUE, YP_TOKEN_KEYWORD_ENSURE)) { @@ -11368,7 +11376,9 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) { yp_node_t *statements = NULL; if (!match_any_type_p(parser, 3, YP_TOKEN_KEYWORD_RESCUE, YP_TOKEN_KEYWORD_ENSURE, YP_TOKEN_KEYWORD_END)) { + yp_accepts_block_stack_push(parser, true); statements = (yp_node_t *) parse_statements(parser, YP_CONTEXT_SCLASS); + yp_accepts_block_stack_pop(parser); } if (match_any_type_p(parser, 2, YP_TOKEN_KEYWORD_RESCUE, YP_TOKEN_KEYWORD_ENSURE)) { @@ -11649,7 +11659,9 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) { yp_do_loop_stack_push(parser, false); if (!match_any_type_p(parser, 3, YP_TOKEN_KEYWORD_RESCUE, YP_TOKEN_KEYWORD_ENSURE, YP_TOKEN_KEYWORD_END)) { + yp_accepts_block_stack_push(parser, true); statements = (yp_node_t *) parse_statements(parser, YP_CONTEXT_DEF); + yp_accepts_block_stack_pop(parser); } if (match_any_type_p(parser, 2, YP_TOKEN_KEYWORD_RESCUE, YP_TOKEN_KEYWORD_ENSURE)) { @@ -12506,7 +12518,9 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) { opening = parser->previous; if (!match_any_type_p(parser, 3, YP_TOKEN_KEYWORD_END, YP_TOKEN_KEYWORD_RESCUE, YP_TOKEN_KEYWORD_ENSURE)) { + yp_accepts_block_stack_push(parser, true); body = (yp_node_t *) parse_statements(parser, YP_CONTEXT_LAMBDA_DO_END); + yp_accepts_block_stack_pop(parser); } if (match_any_type_p(parser, 2, YP_TOKEN_KEYWORD_RESCUE, YP_TOKEN_KEYWORD_ENSURE)) { |