diff options
| author | Nobuyoshi Nakada <[email protected]> | 2016-08-12 10:14:35 +0900 |
|---|---|---|
| committer | Nobuyoshi Nakada <[email protected]> | 2016-08-12 10:14:35 +0900 |
| commit | a06940daa9d4c3d9e213f2a8b679a7c2397c9ccb (patch) | |
| tree | 2a2457b05e0cf5852a8fe5c9a650efdef5010124 | |
| parent | 90e8ce5c30465e3b7db782900424c8f6ea117776 (diff) | |
| download | mruby-a06940daa9d4c3d9e213f2a8b679a7c2397c9ccb.tar.gz mruby-a06940daa9d4c3d9e213f2a8b679a7c2397c9ccb.zip | |
parse.y: simplify 90e8ce5
simplify tOP_ASGN rules by command_rhs and arg_rhs rules with
%prec.
| -rw-r--r-- | mrbgems/mruby-compiler/core/parse.y | 119 |
1 files changed, 31 insertions, 88 deletions
diff --git a/mrbgems/mruby-compiler/core/parse.y b/mrbgems/mruby-compiler/core/parse.y index b474295ed..ec3d10682 100644 --- a/mrbgems/mruby-compiler/core/parse.y +++ b/mrbgems/mruby-compiler/core/parse.y @@ -1097,12 +1097,12 @@ heredoc_end(parser_state *p) %type <nd> literal numeric cpath symbol %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_value primary_value +%type <nd> expr_value arg_value arg_rhs primary_value %type <nd> if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure %type <nd> args call_args opt_call_args %type <nd> paren_args opt_paren_args variable %type <nd> command_args aref_args opt_block_arg block_arg var_ref var_lhs -%type <nd> command_asgn mrhs superclass block_call block_command +%type <nd> command_asgn command_rhs mrhs superclass block_call block_command %type <nd> f_block_optarg f_block_opt %type <nd> f_arglist f_args f_arg f_arg_item f_optarg f_marg f_marg_list f_margs %type <nd> assoc_list assocs assoc undef_list backref for_var @@ -1318,57 +1318,32 @@ stmt : keyword_alias fsym {p->lstate = EXPR_FNAME;} fsym { $$ = new_masgn(p, $1, $3); } - | var_lhs tOP_ASGN command_call + | var_lhs tOP_ASGN command_rhs { $$ = new_op_asgn(p, $1, $2, $3); } - | var_lhs tOP_ASGN command_call modifier_rescue stmt - { - $$ = new_op_asgn(p, $1, $2, new_mod_rescue(p, $3, $5)); - } - | primary_value '[' opt_call_args rbracket tOP_ASGN command_call + | primary_value '[' opt_call_args rbracket tOP_ASGN command_rhs { $$ = new_op_asgn(p, new_call(p, $1, intern("[]",2), $3, '.'), $5, $6); } - | primary_value '[' opt_call_args rbracket tOP_ASGN command_call modifier_rescue stmt - { - $$ = new_op_asgn(p, new_call(p, $1, intern("[]",2), $3, '.'), $5, new_mod_rescue(p, $6, $8)); - } - | primary_value call_op tIDENTIFIER tOP_ASGN command_call + | primary_value call_op tIDENTIFIER tOP_ASGN command_rhs { $$ = new_op_asgn(p, new_call(p, $1, $3, 0, $2), $4, $5); } - | primary_value call_op tIDENTIFIER tOP_ASGN command_call modifier_rescue stmt - { - $$ = new_op_asgn(p, new_call(p, $1, $3, 0, $2), $4, new_mod_rescue(p, $5, $7)); - } - | primary_value call_op tCONSTANT tOP_ASGN command_call + | primary_value call_op tCONSTANT tOP_ASGN command_rhs { $$ = new_op_asgn(p, new_call(p, $1, $3, 0, $2), $4, $5); } - | primary_value call_op tCONSTANT tOP_ASGN command_call modifier_rescue stmt - { - $$ = new_op_asgn(p, new_call(p, $1, $3, 0, $2), $4, new_mod_rescue(p, $5, $7)); - } | primary_value tCOLON2 tCONSTANT tOP_ASGN command_call { yyerror(p, "constant re-assignment"); $$ = 0; } - | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_call + | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_rhs { $$ = new_op_asgn(p, new_call(p, $1, $3, 0, tCOLON2), $4, $5); } - | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_call modifier_rescue stmt - { - $$ = new_op_asgn(p, new_call(p, $1, $3, 0, tCOLON2), $4, new_mod_rescue(p, $5, $7)); - } - | backref tOP_ASGN command_call - { - backref_error(p, $1); - $$ = new_begin(p, 0); - } - | backref tOP_ASGN command_call modifier_rescue stmt + | backref tOP_ASGN command_rhs { backref_error(p, $1); $$ = new_begin(p, 0); @@ -1388,18 +1363,18 @@ stmt : keyword_alias fsym {p->lstate = EXPR_FNAME;} fsym | expr ; -command_asgn : lhs '=' command_call +command_asgn : lhs '=' command_rhs { $$ = new_asgn(p, $1, $3); } - | lhs '=' command_call modifier_rescue stmt - { - $$ = new_asgn(p, $1, new_mod_rescue(p, $3, $5)); - } - | lhs '=' command_asgn + ; + +command_rhs : command_call %prec tOP_ASGN + | command_call modifier_rescue stmt { - $$ = new_asgn(p, $1, $3); + $$ = new_mod_rescue(p, $1, $3); } + | command_asgn ; @@ -1759,80 +1734,41 @@ reswords : keyword__LINE__ | keyword__FILE__ | keyword__ENCODING__ | keyword_while | keyword_until ; -arg : lhs '=' arg +arg : lhs '=' arg_rhs { $$ = new_asgn(p, $1, $3); } - | lhs '=' arg modifier_rescue arg - { - $$ = new_asgn(p, $1, new_mod_rescue(p, $3, $5)); - } - | var_lhs tOP_ASGN arg + | var_lhs tOP_ASGN arg_rhs { $$ = new_op_asgn(p, $1, $2, $3); } - | var_lhs tOP_ASGN arg modifier_rescue arg - { - $$ = new_op_asgn(p, $1, $2, new_mod_rescue(p, $3, $5)); - } - | primary_value '[' opt_call_args rbracket tOP_ASGN arg + | primary_value '[' opt_call_args rbracket tOP_ASGN arg_rhs { $$ = new_op_asgn(p, new_call(p, $1, intern("[]",2), $3, '.'), $5, $6); } - | primary_value '[' opt_call_args rbracket tOP_ASGN arg modifier_rescue arg - { - $$ = new_op_asgn(p, new_call(p, $1, intern("[]",2), $3, '.'), $5, new_mod_rescue(p, $6, $8)); - } - | primary_value call_op tIDENTIFIER tOP_ASGN arg + | primary_value call_op tIDENTIFIER tOP_ASGN arg_rhs { $$ = new_op_asgn(p, new_call(p, $1, $3, 0, $2), $4, $5); } - | primary_value call_op tIDENTIFIER tOP_ASGN arg modifier_rescue arg - { - $$ = new_op_asgn(p, new_call(p, $1, $3, 0, $2), $4, new_mod_rescue(p, $5, $7)); - } - | primary_value call_op tCONSTANT tOP_ASGN arg + | primary_value call_op tCONSTANT tOP_ASGN arg_rhs { $$ = new_op_asgn(p, new_call(p, $1, $3, 0, $2), $4, $5); } - | primary_value call_op tCONSTANT tOP_ASGN arg modifier_rescue arg - { - $$ = new_op_asgn(p, new_call(p, $1, $3, 0, $2), $4, new_mod_rescue(p, $5, $7)); - } - | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg + | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg_rhs { $$ = new_op_asgn(p, new_call(p, $1, $3, 0, tCOLON2), $4, $5); } - | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg modifier_rescue arg - { - $$ = new_op_asgn(p, new_call(p, $1, $3, 0, tCOLON2), $4, new_mod_rescue(p, $5, $7)); - } - | primary_value tCOLON2 tCONSTANT tOP_ASGN arg - { - yyerror(p, "constant re-assignment"); - $$ = new_begin(p, 0); - } - | primary_value tCOLON2 tCONSTANT tOP_ASGN arg modifier_rescue arg - { - yyerror(p, "constant re-assignment"); - $$ = new_begin(p, 0); - } - | tCOLON3 tCONSTANT tOP_ASGN arg + | primary_value tCOLON2 tCONSTANT tOP_ASGN arg_rhs { yyerror(p, "constant re-assignment"); $$ = new_begin(p, 0); } - | tCOLON3 tCONSTANT tOP_ASGN arg modifier_rescue arg + | tCOLON3 tCONSTANT tOP_ASGN arg_rhs { yyerror(p, "constant re-assignment"); $$ = new_begin(p, 0); } - | backref tOP_ASGN arg - { - backref_error(p, $1); - $$ = new_begin(p, 0); - } - | backref tOP_ASGN arg modifier_rescue arg + | backref tOP_ASGN arg_rhs { backref_error(p, $1); $$ = new_begin(p, 0); @@ -1995,6 +1931,13 @@ aref_args : none } ; +arg_rhs : arg %prec tOP_ASGN + | arg modifier_rescue arg + { + $$ = new_mod_rescue(p, $1, $3); + } + ; + paren_args : '(' opt_call_args rparen { $$ = $2; |
