diff options
author | Nobuyoshi Nakada <[email protected]> | 2023-09-01 03:15:47 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2023-09-01 04:26:31 +0900 |
commit | 9930363aab6ac4b8d7034baff85cd86c17953dc9 (patch) | |
tree | b0291fcbab04e6b19906fa2b8de2f8e5acb0a2e2 | |
parent | 945945dad434dd2c014a4d310dc7dc51e6d4321e (diff) |
[Bug-18878] Parse qualified const with brace block as method call
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/8343
-rw-r--r-- | parse.y | 27 | ||||
-rw-r--r-- | test/ruby/test_syntax.rb | 8 |
2 files changed, 27 insertions, 8 deletions
@@ -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); @@ -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); /*% %*/ } ; @@ -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 { /*%%%*/ @@ -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); /*% %*/ } ; @@ -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); /*% %*/ } ; diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index bcc37e7bbb..c65d7af4c2 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -1640,6 +1640,14 @@ eom 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 |