diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-10-31 19:45:17 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-11-02 15:14:36 +0900 |
| commit | dc886873bcc294e41242016ce1aa30406a98853b (patch) | |
| tree | b8b5e2b1b514bdb8a43e9110d5e0601672bf890f /mrbgems/mruby-compiler/core/parse.y | |
| parent | 70ee9363671ff5aead633807b9579dab22f94cf3 (diff) | |
| download | mruby-dc886873bcc294e41242016ce1aa30406a98853b.tar.gz mruby-dc886873bcc294e41242016ce1aa30406a98853b.zip | |
Replace `R-assignment` by `single-line pattern matching`.
Since `R-assignment` in CRuby is abandoned. Single-line pattern matching
in `mruby` only matches single local variable at the moment. Currently
it works as a right assignment to a local variable. It will be enhanced
in the future.
Diffstat (limited to 'mrbgems/mruby-compiler/core/parse.y')
| -rw-r--r-- | mrbgems/mruby-compiler/core/parse.y | 26 |
1 files changed, 6 insertions, 20 deletions
diff --git a/mrbgems/mruby-compiler/core/parse.y b/mrbgems/mruby-compiler/core/parse.y index 299675091..31f983149 100644 --- a/mrbgems/mruby-compiler/core/parse.y +++ b/mrbgems/mruby-compiler/core/parse.y @@ -1442,7 +1442,7 @@ heredoc_end(parser_state *p) %type <nd> singleton string string_fragment string_rep string_interp xstring regexp %type <nd> literal numeric cpath symbol defn_head defs_head -%type <nd> top_compstmt top_stmts top_stmt rassign +%type <nd> top_compstmt top_stmts top_stmt %type <nd> bodystmt compstmt stmts stmt expr arg primary command command_call method_call %type <nd> expr_value arg_rhs primary_value %type <nd> if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure @@ -1685,28 +1685,14 @@ stmt : keyword_alias fsym {p->lstate = EXPR_FNAME;} fsym { $$ = new_masgn(p, $1, new_array(p, $3)); } - | rassign - | expr - ; - -rassign : arg tASSOC lhs - { - void_expr_error(p, $1); - $$ = new_asgn(p, $3, $1); - } - | arg tASSOC mlhs + | arg tASSOC tIDENTIFIER { + node *lhs = new_lvar(p, $3); void_expr_error(p, $1); - $$ = new_masgn(p, $3, $1); - } - | rassign tASSOC lhs - { - $$ = new_asgn(p, $3, $1); - } - | rassign tASSOC mlhs - { - $$ = new_masgn(p, $3, $1); + assignable(p, lhs); + $$ = new_asgn(p, lhs, $1); } + | expr ; command_asgn : lhs '=' command_rhs |
