parse.y: allow "command" syntax in endless method definition.

This change allows `def hello = puts "Hello"` without parentheses.
This syntax has been introduced since Ruby3.1.
parent d50c83cc
......@@ -1754,6 +1754,44 @@ command_asgn : lhs '=' command_rhs
{
$$ = new_op_asgn(p, new_call(p, $1, $3, 0, tCOLON2), $4, $5);
}
| defn_head f_opt_arglist_paren '=' command
{
$$ = $1;
endless_method_name(p, $1);
void_expr_error(p, $4);
defn_setup(p, $$, $2, $4);
nvars_unnest(p);
p->in_def--;
}
| defn_head f_opt_arglist_paren '=' command modifier_rescue arg
{
$$ = $1;
endless_method_name(p, $1);
void_expr_error(p, $4);
void_expr_error(p, $6);
defn_setup(p, $$, $2, new_mod_rescue(p, $4, $6));
nvars_unnest(p);
p->in_def--;
}
| defs_head f_opt_arglist_paren '=' command
{
$$ = $1;
void_expr_error(p, $4);
defs_setup(p, $$, $2, $4);
nvars_unnest(p);
p->in_def--;
p->in_single--;
}
| defs_head f_opt_arglist_paren '=' command modifier_rescue arg
{
$$ = $1;
void_expr_error(p, $4);
void_expr_error(p, $6);
defs_setup(p, $$, $2, new_mod_rescue(p, $4, $6));
nvars_unnest(p);
p->in_def--;
p->in_single--;
}
| backref tOP_ASGN command_rhs
{
backref_error(p, $1);
......
This diff is collapsed.
......@@ -706,3 +706,20 @@ assert('argument forwarding') do
o.a(1,2,3){}
o.b(1,2,3){}
end
assert('endless def') do
Class.new do
def m1 = 42
def m2() = 42
def m3(x) = x+1
def self.s1 = 42
def self.s2() = 42
def self.s3(x) = x + 1
def c1 = 42
def cm2() = p 42
def cm3(x) = p x+1
def self.cs1 = p 42
def self.cs2() = p 42
def self.cs3(x) = p x + 1
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment