Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -15290,6 +15290,12 @@ parse_block(pm_parser_t *parser, uint16_t depth) {
statements = UP(parse_statements(parser, PM_CONTEXT_BLOCK_BRACES, (uint16_t) (depth + 1)));
}

/* Pop before consuming the closing `}` so the following token (e.g. a
* `do`) is lexed in the enclosing context rather than as a block
* belonging to this block's interior. Otherwise a `do` block would
* wrongly bind to a command whose argument ends in a brace block, as in
* `foo(m a { } do end)`. */
pm_accepts_block_stack_pop(parser);
expect1_opening(parser, PM_TOKEN_BRACE_RIGHT, PM_ERR_BLOCK_TERM_BRACE, &opening);
} else {
if (!match1(parser, PM_TOKEN_KEYWORD_END)) {
Expand All @@ -15305,6 +15311,8 @@ parse_block(pm_parser_t *parser, uint16_t depth) {
}
}

/* As with the brace case above, pop before consuming `end`. */
pm_accepts_block_stack_pop(parser);
expect1_opening(parser, PM_TOKEN_KEYWORD_END, PM_ERR_BLOCK_TERM_END, &opening);
}

Expand All @@ -15313,7 +15321,6 @@ parse_block(pm_parser_t *parser, uint16_t depth) {
pm_node_t *parameters = parse_blocklike_parameters(parser, UP(block_parameters), &opening, &parser->previous);

pm_parser_scope_pop(parser);
pm_accepts_block_stack_pop(parser);

return pm_block_node_create(parser, &locals, &opening, parameters, statements, &parser->previous);
}
Expand Down
14 changes: 14 additions & 0 deletions test/prism/errors/do_block_after_command_block.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
foo(m a { } do end)
^~ unexpected 'do'; expected a `)` to close the arguments
^~ unexpected 'do', expecting end-of-input
^~ unexpected 'do', ignoring it
^~~ unexpected 'end', ignoring it
^ unexpected ')', ignoring it

foo(m a.b { } do end)
^~ unexpected 'do'; expected a `)` to close the arguments
^~ unexpected 'do', expecting end-of-input
^~ unexpected 'do', ignoring it
^~~ unexpected 'end', ignoring it
^ unexpected ')', ignoring it

Loading