diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-04-13 18:44:33 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-04-13 21:51:34 +0900 |
commit | 67bcac879a2e0ddfb4e7bbd7cb5e5401422de76a (patch) | |
tree | bb20963fbf8158a8f6b1e7b6b8a9d4dc07d4772f | |
parent | 5dc6080cb8bebdc7109bd6048e28aee656c3bb4f (diff) | |
download | ruby-67bcac879a2e0ddfb4e7bbd7cb5e5401422de76a.tar.gz |
Allow simple R-assign in endless def
-rw-r--r-- | parse.y | 20 | ||||
-rw-r--r-- | test/ruby/test_syntax.rb | 1 |
2 files changed, 18 insertions, 3 deletions
@@ -1104,7 +1104,7 @@ static int looking_at_eol_p(struct parser_params *p); %type <node> string_contents xstring_contents regexp_contents string_content %type <node> words symbols symbol_list qwords qsymbols word_list qword_list qsym_list word %type <node> literal numeric simple_numeric ssym dsym symbol cpath def_name defn_head defs_head -%type <node> top_compstmt top_stmts top_stmt begin_block rassign +%type <node> top_compstmt top_stmts top_stmt begin_block rassign arg_rassign %type <node> bodystmt compstmt stmts stmt_or_begin stmt expr arg primary command command_call method_call %type <node> expr_value expr_value_do arg_value primary_value fcall rel_expr %type <node> if_tail opt_else case_body case_args cases opt_rescue exc_list exc_var opt_ensure @@ -1195,6 +1195,7 @@ static int looking_at_eol_p(struct parser_params *p); %nonassoc tLOWEST %nonassoc tLBRACE_ARG +%left tASSOC %nonassoc modifier_if modifier_unless modifier_while modifier_until keyword_in %left keyword_or keyword_and @@ -1536,6 +1537,19 @@ rassign : arg_value tASSOC lhs } ; +arg_rassign : arg tASSOC lhs %prec tLOWEST + { + /*%%%*/ + $$ = node_assign(p, $3, $1, &@$); + /*% %*/ + /*% ripper: assign!($3, $1) %*/ + } + | arg %prec tLOWEST + { + $$ = $1; + } + ; + command_asgn : lhs '=' command_rhs { /*%%%*/ @@ -2449,7 +2463,7 @@ arg : lhs '=' arg_rhs /*% %*/ /*% ripper: ifop!($1, $3, $6) %*/ } - | defn_head f_arglist_opt '=' arg + | defn_head f_arglist_opt '=' arg_rassign { restore_defun(p, $<node>1->nd_defn); /*%%%*/ @@ -2458,7 +2472,7 @@ arg : lhs '=' arg_rhs /*% ripper: def!(get_value($1), $2, $4) %*/ local_pop(p); } - | defs_head f_arglist_opt '=' arg + | defs_head f_arglist_opt '=' arg_rassign { restore_defun(p, $<node>1->nd_defn); /*%%%*/ diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index 29813cebd5..b0d9e82f28 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -1419,6 +1419,7 @@ eom assert_valid_syntax('private def inc(x) = x + 1') assert_valid_syntax('private def obj.foo = 42') assert_valid_syntax('private def obj.inc(x) = x + 1') + assert_valid_syntax('private def obj.inc(x) = x + 1 => @x') end def test_methoddef_in_cond |