[Bug #19281] Allow semicolon in parenthesis at the first argument of command call

Allow compstmt in the first argument of command call wrapped with parenthesis
like following arguments with parenthesis.
This commit is contained in:
yui-knk 2023-08-31 21:35:55 +09:00 committed by Yuichiro Kaneko
parent df4c77608e
commit 45cd011d73
Notes: git 2023-09-01 03:55:30 +00:00
2 changed files with 16 additions and 8 deletions

View file

@ -3362,14 +3362,7 @@ primary : literal
/*% %*/ /*% %*/
/*% ripper: begin!($3) %*/ /*% ripper: begin!($3) %*/
} }
| tLPAREN_ARG {SET_LEX_STATE(EXPR_ENDARG);} rparen | tLPAREN_ARG compstmt {SET_LEX_STATE(EXPR_ENDARG);} ')'
{
/*%%%*/
$$ = NEW_BEGIN(0, &@$);
/*% %*/
/*% ripper: paren!(0) %*/
}
| tLPAREN_ARG stmt {SET_LEX_STATE(EXPR_ENDARG);} rparen
{ {
/*%%%*/ /*%%%*/
if (nd_type_p($2, NODE_SELF)) $2->nd_state = 0; if (nd_type_p($2, NODE_SELF)) $2->nd_state = 0;

View file

@ -1650,6 +1650,21 @@ eom
assert_valid_syntax('Foo::Bar() {}') assert_valid_syntax('Foo::Bar() {}')
end end
def test_command_newline_in_tlparen_args
assert_valid_syntax("p (1\n2\n),(3),(4)")
assert_valid_syntax("p (\n),(),()")
assert_valid_syntax("a.b (1\n2\n),(3),(4)")
assert_valid_syntax("a.b (\n),(),()")
end
def test_command_semicolon_in_tlparen_at_the_first_arg
bug19281 = '[ruby-core:111499] [Bug #19281]'
assert_valid_syntax('p (1;2),(3),(4)', bug19281)
assert_valid_syntax('p (;),(),()', bug19281)
assert_valid_syntax('a.b (1;2),(3),(4)', bug19281)
assert_valid_syntax('a.b (;),(),()', bug19281)
end
def test_numbered_parameter def test_numbered_parameter
assert_valid_syntax('proc {_1}') assert_valid_syntax('proc {_1}')
assert_equal(3, eval('[1,2].then {_1+_2}')) assert_equal(3, eval('[1,2].then {_1+_2}'))