summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-compiler/core/parse.y
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2021-05-18 16:26:36 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2021-05-18 16:26:36 +0900
commit07c847027875a955ba64d3c84f8f456e96155b31 (patch)
tree6495026956e7e00d54ada56b1467883ac07960df /mrbgems/mruby-compiler/core/parse.y
parentd50c83cca72f5686292427f5b6606482fd3ad380 (diff)
downloadmruby-07c847027875a955ba64d3c84f8f456e96155b31.tar.gz
mruby-07c847027875a955ba64d3c84f8f456e96155b31.zip
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.
Diffstat (limited to 'mrbgems/mruby-compiler/core/parse.y')
-rw-r--r--mrbgems/mruby-compiler/core/parse.y38
1 files changed, 38 insertions, 0 deletions
diff --git a/mrbgems/mruby-compiler/core/parse.y b/mrbgems/mruby-compiler/core/parse.y
index 54f5262be..8e68fa21a 100644
--- a/mrbgems/mruby-compiler/core/parse.y
+++ b/mrbgems/mruby-compiler/core/parse.y
@@ -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);