From a06940daa9d4c3d9e213f2a8b679a7c2397c9ccb Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Fri, 12 Aug 2016 10:14:35 +0900 Subject: parse.y: simplify 90e8ce5 simplify tOP_ASGN rules by command_rhs and arg_rhs rules with %prec. --- mrbgems/mruby-compiler/core/parse.y | 119 ++++++++++-------------------------- 1 file 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 literal numeric cpath symbol %type top_compstmt top_stmts top_stmt %type bodystmt compstmt stmts stmt expr arg primary command command_call method_call -%type expr_value arg_value primary_value +%type expr_value arg_value arg_rhs primary_value %type if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure %type args call_args opt_call_args %type paren_args opt_paren_args variable %type command_args aref_args opt_block_arg block_arg var_ref var_lhs -%type command_asgn mrhs superclass block_call block_command +%type command_asgn command_rhs mrhs superclass block_call block_command %type f_block_optarg f_block_opt %type f_arglist f_args f_arg f_arg_item f_optarg f_marg f_marg_list f_margs %type 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; -- cgit v1.2.3