Skip to content

Commit 4ce6bcf

Browse files
committed
Ignore newlines in labelled lambda arguments
1 parent 4959908 commit 4ce6bcf

File tree

3 files changed

+191
-27
lines changed

3 files changed

+191
-27
lines changed

src/prism.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14460,6 +14460,7 @@ parse_parameters(
1446014460
bool allows_trailing_comma,
1446114461
bool allows_forwarding_parameters,
1446214462
bool accepts_blocks_in_defaults,
14463+
bool in_block,
1446314464
uint16_t depth
1446414465
) {
1446514466
pm_do_loop_stack_push(parser, false);
@@ -14624,7 +14625,7 @@ parse_parameters(
1462414625
break;
1462514626
}
1462614627
case PM_TOKEN_LABEL: {
14627-
if (!uses_parentheses) parser->in_keyword_arg = true;
14628+
if (!uses_parentheses && !in_block) parser->in_keyword_arg = true;
1462814629
update_parameter_state(parser, &parser->current, &order);
1462914630

1463014631
context_push(parser, PM_CONTEXT_DEFAULT_PARAMS);
@@ -15188,6 +15189,7 @@ parse_block_parameters(
1518815189
allows_trailing_comma,
1518915190
false,
1519015191
accepts_blocks_in_defaults,
15192+
true,
1519115193
(uint16_t) (depth + 1)
1519215194
);
1519315195
}
@@ -19341,7 +19343,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
1934119343
if (match1(parser, PM_TOKEN_PARENTHESIS_RIGHT)) {
1934219344
params = NULL;
1934319345
} else {
19344-
params = parse_parameters(parser, PM_BINDING_POWER_DEFINED, true, false, true, true, (uint16_t) (depth + 1));
19346+
params = parse_parameters(parser, PM_BINDING_POWER_DEFINED, true, false, true, true, false, (uint16_t) (depth + 1));
1934519347
}
1934619348

1934719349
lex_state_set(parser, PM_LEX_STATE_BEG);
@@ -19366,7 +19368,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
1936619368

1936719369
lparen = not_provided(parser);
1936819370
rparen = not_provided(parser);
19369-
params = parse_parameters(parser, PM_BINDING_POWER_DEFINED, false, false, true, true, (uint16_t) (depth + 1));
19371+
params = parse_parameters(parser, PM_BINDING_POWER_DEFINED, false, false, true, true, false, (uint16_t) (depth + 1));
1937019372

1937119373
context_pop(parser);
1937219374
break;

test/prism/fixtures/lambda.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,15 @@
99
-> foo = bar do end
1010

1111
-> foo: bar do end
12+
13+
p{|a:
14+
b|}
15+
16+
->(a:
17+
b){}
18+
19+
->a:
20+
b{}
21+
22+
->a:
23+
{}

test/prism/snapshots/lambda.txt

Lines changed: 174 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)