Skip to content

Commit ff50a14

Browse files
authored
Merge pull request #3222 from haldun/haldun/fix-nl-in-kwd-args
Ignore newlines in labelled lambda arguments
2 parents 1b450de + 4ce6bcf commit ff50a14

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
@@ -14474,6 +14474,7 @@ parse_parameters(
1447414474
bool allows_trailing_comma,
1447514475
bool allows_forwarding_parameters,
1447614476
bool accepts_blocks_in_defaults,
14477+
bool in_block,
1447714478
uint16_t depth
1447814479
) {
1447914480
pm_do_loop_stack_push(parser, false);
@@ -14638,7 +14639,7 @@ parse_parameters(
1463814639
break;
1463914640
}
1464014641
case PM_TOKEN_LABEL: {
14641-
if (!uses_parentheses) parser->in_keyword_arg = true;
14642+
if (!uses_parentheses && !in_block) parser->in_keyword_arg = true;
1464214643
update_parameter_state(parser, &parser->current, &order);
1464314644

1464414645
context_push(parser, PM_CONTEXT_DEFAULT_PARAMS);
@@ -15202,6 +15203,7 @@ parse_block_parameters(
1520215203
allows_trailing_comma,
1520315204
false,
1520415205
accepts_blocks_in_defaults,
15206+
true,
1520515207
(uint16_t) (depth + 1)
1520615208
);
1520715209
}
@@ -19355,7 +19357,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
1935519357
if (match1(parser, PM_TOKEN_PARENTHESIS_RIGHT)) {
1935619358
params = NULL;
1935719359
} else {
19358-
params = parse_parameters(parser, PM_BINDING_POWER_DEFINED, true, false, true, true, (uint16_t) (depth + 1));
19360+
params = parse_parameters(parser, PM_BINDING_POWER_DEFINED, true, false, true, true, false, (uint16_t) (depth + 1));
1935919361
}
1936019362

1936119363
lex_state_set(parser, PM_LEX_STATE_BEG);
@@ -19380,7 +19382,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
1938019382

1938119383
lparen = not_provided(parser);
1938219384
rparen = not_provided(parser);
19383-
params = parse_parameters(parser, PM_BINDING_POWER_DEFINED, false, false, true, true, (uint16_t) (depth + 1));
19385+
params = parse_parameters(parser, PM_BINDING_POWER_DEFINED, false, false, true, true, false, (uint16_t) (depth + 1));
1938419386

1938519387
context_pop(parser);
1938619388
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)