Skip to content
Merged
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
27 changes: 19 additions & 8 deletions parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,13 @@ set_line_body(NODE *body, int line)
}
}

static void
set_embraced_location(NODE *node, const rb_code_location_t *beg, const rb_code_location_t *end)
{
node->nd_body->nd_loc = code_loc_gen(beg, end);
nd_set_line(node, beg->end_pos.lineno);
}

#define yyparse ruby_yyparse

static NODE* cond(struct parser_params *p, NODE *node, const YYLTYPE *loc);
Expand Down Expand Up @@ -2250,8 +2257,7 @@ cmd_brace_block : tLBRACE_ARG brace_body '}'
{
$$ = $2;
/*%%%*/
$$->nd_body->nd_loc = code_loc_gen(&@1, &@3);
nd_set_line($$, @1.end_pos.lineno);
set_embraced_location($$, &@1, &@3);
/*% %*/
}
;
Expand Down Expand Up @@ -2314,6 +2320,14 @@ command : fcall command_args %prec tLOWEST
/*% %*/
/*% ripper: method_add_block!(command_call!($1, $2, $3, $4), $5) %*/
}
| primary_value tCOLON2 tCONSTANT '{' brace_body '}'
{
/*%%%*/
set_embraced_location($5, &@4, &@6);
$$ = new_command_qcall(p, ID2VAL(idCOLON2), $1, $3, Qnull, $5, &@3, &@$);
/*% %*/
/*% ripper: method_add_block!(command_call!($1, $2, $3, Qnull), $5) %*/
}
| keyword_super command_args
{
/*%%%*/
Expand Down Expand Up @@ -4274,8 +4288,7 @@ do_block : k_do_block do_body k_end
{
$$ = $2;
/*%%%*/
$$->nd_body->nd_loc = code_loc_gen(&@1, &@3);
nd_set_line($$, @1.end_pos.lineno);
set_embraced_location($$, &@1, &@3);
/*% %*/
}
;
Expand Down Expand Up @@ -4393,16 +4406,14 @@ brace_block : '{' brace_body '}'
{
$$ = $2;
/*%%%*/
$$->nd_body->nd_loc = code_loc_gen(&@1, &@3);
nd_set_line($$, @1.end_pos.lineno);
set_embraced_location($$, &@1, &@3);
/*% %*/
}
| k_do do_body k_end
{
$$ = $2;
/*%%%*/
$$->nd_body->nd_loc = code_loc_gen(&@1, &@3);
nd_set_line($$, @1.end_pos.lineno);
set_embraced_location($$, &@1, &@3);
/*% %*/
}
;
Expand Down
8 changes: 8 additions & 0 deletions test/ruby/test_syntax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1640,6 +1640,14 @@ def test_classdef_in_cond
def test_command_with_cmd_brace_block
assert_valid_syntax('obj.foo (1) {}')
assert_valid_syntax('obj::foo (1) {}')
assert_valid_syntax('bar {}')
assert_valid_syntax('Bar {}')
assert_valid_syntax('bar() {}')
assert_valid_syntax('Bar() {}')
assert_valid_syntax('Foo::bar {}')
assert_valid_syntax('Foo::Bar {}')
assert_valid_syntax('Foo::bar() {}')
assert_valid_syntax('Foo::Bar() {}')
end

def test_numbered_parameter
Expand Down