diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-06-11 22:57:33 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-04-10 15:03:58 +0900 |
commit | 1b2d351b216661e03d497dfdce216e0d51474664 (patch) | |
tree | 4151ebb30b8789a9ee87afad79fb8c8a32481ae3 /parse.y | |
parent | d94960f22ec2de3a3855305cb51343806d2b46c7 (diff) |
Rightward-assign by ASSOC
[Feature #15921]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3012
Diffstat (limited to 'parse.y')
-rw-r--r-- | parse.y | 40 |
1 files changed, 38 insertions, 2 deletions
@@ -1083,7 +1083,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 -%type <node> top_compstmt top_stmts top_stmt begin_block +%type <node> top_compstmt top_stmts top_stmt begin_block 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 @@ -1481,9 +1481,44 @@ stmt : keyword_alias fitem {SET_LEX_STATE(EXPR_FNAME|EXPR_FITEM);} fitem /*% %*/ /*% ripper: massign!($1, $3) %*/ } + | rassign | expr ; +rassign : primary tASSOC lhs + { + /*%%%*/ + value_expr($1); + $$ = node_assign(p, $3, $1, &@$); + /*% %*/ + /*% ripper: assign!($3, $1) %*/ + } + | primary tASSOC mlhs + { + /*%%%*/ + value_expr($1); + $$ = node_assign(p, $3, $1, &@$); + /*% %*/ + /*% ripper: massign!($3, $1) %*/ + } + | rassign tASSOC lhs + { + /*%%%*/ + value_expr($1); + $$ = node_assign(p, $3, $1, &@$); + /*% %*/ + /*% ripper: assign!($3, $1) %*/ + } + | rassign tASSOC mlhs + { + /*%%%*/ + value_expr($1); + $$ = node_assign(p, $3, $1, &@$); + /*% %*/ + /*% ripper: massign!($3, $1) %*/ + } + ; + command_asgn : lhs '=' command_rhs { /*%%%*/ @@ -8866,10 +8901,11 @@ parser_yylex(struct parser_params *p) pushback(p, c); if (space_seen) dispatch_scan_event(p, tSP); goto retry; + case '=': case '&': case '.': { dispatch_delayed_token(p, tIGNORED_NL); - if (peek(p, '.') == (c == '&')) { + if (c == '=' ? peek(p, '>') : (peek(p, '.') == (c == '&'))) { pushback(p, c); dispatch_scan_event(p, tSP); goto retry; |