aboutsummaryrefslogtreecommitdiffstats
path: root/parse.y
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-10 13:37:03 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-10 13:37:03 +0000
commitea54cb9507b9c7e6657df1a52f7f51aa87c8019e (patch)
treefe7b90f2a5eb86a511ddf8ff9d1b0dffecc2dfcc /parse.y
parenta7159d2cff49ddfbc1c353ee15fff47ddf1d2829 (diff)
downloadruby-ea54cb9507b9c7e6657df1a52f7f51aa87c8019e.tar.gz
parse.y: rhs with rescue modifier
* parse.y (command_rhs, arg_rhs): introduce new rules to reduce repeated rules with rescue modifier. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55853 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y74
1 files changed, 33 insertions, 41 deletions
diff --git a/parse.y b/parse.y
index 94518ab780..70d246a32c 100644
--- a/parse.y
+++ b/parse.y
@@ -862,6 +862,7 @@ static void token_info_pop_gen(struct parser_params*, const char *token, size_t
%type <node> args call_args opt_call_args
%type <node> paren_args opt_paren_args args_tail opt_args_tail block_args_tail opt_block_args_tail
%type <node> command_args aref_args opt_block_arg block_arg var_ref var_lhs
+%type <node> command_rhs arg_rhs
%type <node> command_asgn mrhs mrhs_arg superclass block_call block_command
%type <node> f_block_optarg f_block_opt
%type <node> f_arglist f_args f_arg f_arg_item f_optarg f_marg f_marg_list f_margs
@@ -1348,7 +1349,7 @@ stmt : keyword_alias fitem {SET_LEX_STATE(EXPR_FNAME|EXPR_FITEM);} fitem
| expr
;
-command_asgn : lhs '=' command_call
+command_asgn : lhs '=' command_rhs
{
/*%%%*/
value_expr($3);
@@ -1357,30 +1358,28 @@ command_asgn : lhs '=' command_call
$$ = dispatch2(assign, $1, $3);
%*/
}
- | lhs '=' command_call modifier_rescue stmt
+ ;
+
+command_rhs : command_call %prec tOP_ASGN
{
/*%%%*/
- NODE *resq = NEW_RESBODY(0, remove_begin($5), 0);
- value_expr($3);
- resq = NEW_RESCUE($3, resq, 0);
- $$ = node_assign($1, resq);
+ value_expr($1);
+ $$ = $1;
/*%
- $3 = dispatch2(rescue_mod, $3, $5);
- $$ = dispatch2(assign, $1, $3);
%*/
}
- | lhs '=' command_asgn
+ | command_call modifier_rescue stmt
{
/*%%%*/
- value_expr($3);
- $$ = node_assign($1, $3);
+ value_expr($1);
+ $$ = NEW_RESCUE($1, NEW_RESBODY(0, remove_begin($3), 0), 0);
/*%
- $$ = dispatch2(assign, $1, $3);
+ $$ = dispatch2(rescue_mod, $1, $3);
%*/
}
+ | command_asgn
;
-
expr : command_call
| expr keyword_and expr
{
@@ -2047,38 +2046,12 @@ reswords : keyword__LINE__ | keyword__FILE__ | keyword__ENCODING__
| keyword_while | keyword_until
;
-arg : lhs '=' arg
+arg : lhs '=' arg_rhs
{
- /*%%%*/
- value_expr($3);
- $$ = node_assign($1, $3);
- /*%
- $$ = dispatch2(assign, $1, $3);
- %*/
- }
- | lhs '=' arg modifier_rescue arg
- {
- /*%%%*/
- value_expr($3);
- $3 = NEW_RESCUE($3, NEW_RESBODY(0,$5,0), 0);
$$ = node_assign($1, $3);
- /*%
- $$ = dispatch2(assign, $1, dispatch2(rescue_mod, $3, $5));
- %*/
}
- | var_lhs tOP_ASGN arg
+ | var_lhs tOP_ASGN arg_rhs
{
- value_expr($3);
- $$ = new_op_assign($1, $2, $3);
- }
- | var_lhs tOP_ASGN arg modifier_rescue arg
- {
- /*%%%*/
- value_expr($3);
- $3 = NEW_RESCUE($3, NEW_RESBODY(0,$5,0), 0);
- /*%
- $3 = dispatch2(rescue_mod, $3, $5);
- %*/
$$ = new_op_assign($1, $2, $3);
}
| primary_value '[' opt_call_args rbracket tOP_ASGN arg
@@ -2473,6 +2446,25 @@ aref_args : none
}
;
+arg_rhs : arg %prec tOP_ASGN
+ {
+ /*%%%*/
+ value_expr($1);
+ $$ = $1;
+ /*%
+ %*/
+ }
+ | arg modifier_rescue arg
+ {
+ /*%%%*/
+ value_expr($1);
+ $$ = NEW_RESCUE($1, NEW_RESBODY(0, remove_begin($3), 0), 0);
+ /*%
+ $$ = dispatch2(rescue_mod, $1, $3);
+ %*/
+ }
+ ;
+
paren_args : '(' opt_call_args rparen
{
/*%%%*/