[ruby/yarp] Allow for block statements after elsif and else

https://github.com/ruby/yarp/commit/4560cab235
This commit is contained in:
Jemma Issroff 2023-06-21 12:59:22 -04:00 committed by Takashi Kokubun
parent 7fad7d345a
commit e8fb84265c
3 changed files with 129 additions and 2 deletions

View File

@ -29,3 +29,14 @@ end
if type in 1
elsif type in B
end
if 1
lambda do |_|
end
elsif 2
lambda do |_|
end
else
lambda do |_|
end
end

View File

@ -1,6 +1,6 @@
ProgramNode(0...293)(
ProgramNode(0...382)(
[],
StatementsNode(0...293)(
StatementsNode(0...382)(
[IfNode(0...15)(
(0...2),
TrueNode(3...7)(),
@ -225,6 +225,116 @@ ProgramNode(0...293)(
nil
),
(290...293)
),
IfNode(295...382)(
(295...297),
IntegerNode(298...299)(),
StatementsNode(302...321)(
[CallNode(302...321)(
nil,
nil,
(302...308),
nil,
nil,
nil,
BlockNode(309...321)(
[:_],
BlockParametersNode(312...315)(
ParametersNode(313...314)(
[RequiredParameterNode(313...314)(:_)],
[],
[],
nil,
[],
nil,
nil
),
[],
(312...313),
(314...315)
),
nil,
(309...311),
(318...321)
),
0,
"lambda"
)]
),
IfNode(322...382)(
(322...327),
IntegerNode(328...329)(),
StatementsNode(332...351)(
[CallNode(332...351)(
nil,
nil,
(332...338),
nil,
nil,
nil,
BlockNode(339...351)(
[:_],
BlockParametersNode(342...345)(
ParametersNode(343...344)(
[RequiredParameterNode(343...344)(:_)],
[],
[],
nil,
[],
nil,
nil
),
[],
(342...343),
(344...345)
),
nil,
(339...341),
(348...351)
),
0,
"lambda"
)]
),
ElseNode(352...382)(
(352...356),
StatementsNode(359...378)(
[CallNode(359...378)(
nil,
nil,
(359...365),
nil,
nil,
nil,
BlockNode(366...378)(
[:_],
BlockParametersNode(369...372)(
ParametersNode(370...371)(
[RequiredParameterNode(370...371)(:_)],
[],
[],
nil,
[],
nil,
nil
),
[],
(369...370),
(371...372)
),
nil,
(366...368),
(375...378)
),
0,
"lambda"
)]
),
(379...382)
),
(379...382)
),
(379...382)
)]
)
)

View File

@ -8701,7 +8701,10 @@ parse_conditional(yp_parser_t *parser, yp_context_t context) {
accept_any(parser, 2, YP_TOKEN_NEWLINE, YP_TOKEN_SEMICOLON);
accept(parser, YP_TOKEN_KEYWORD_THEN);
yp_accepts_block_stack_push(parser, true);
yp_statements_node_t *statements = parse_statements(parser, YP_CONTEXT_ELSIF);
yp_accepts_block_stack_pop(parser);
accept_any(parser, 2, YP_TOKEN_NEWLINE, YP_TOKEN_SEMICOLON);
yp_node_t *elsif = (yp_node_t *) yp_if_node_create(parser, &elsif_keyword, predicate, statements, NULL, &end_keyword);
@ -8713,7 +8716,10 @@ parse_conditional(yp_parser_t *parser, yp_context_t context) {
if (match_type_p(parser, YP_TOKEN_KEYWORD_ELSE)) {
parser_lex(parser);
yp_token_t else_keyword = parser->previous;
yp_accepts_block_stack_push(parser, true);
yp_statements_node_t *else_statements = parse_statements(parser, YP_CONTEXT_ELSE);
yp_accepts_block_stack_pop(parser);
accept_any(parser, 2, YP_TOKEN_NEWLINE, YP_TOKEN_SEMICOLON);
expect(parser, YP_TOKEN_KEYWORD_END, "Expected `end` to close `else` clause.");