diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-03-23 01:09:57 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-03-23 01:09:57 +0000 |
commit | f3fbf1dfadea80646c68719d439da699d527b0dc (patch) | |
tree | 15d823137407d5a897556f3621179642b7313b43 /parse.y | |
parent | 140512d2225e6fd046ba1bdbcd1a27450f55c233 (diff) |
parse.y: k_else in bodystmt
* parse.y (bodystmt): expand opt_else to show the error message at
the right place.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62902 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r-- | parse.y | 47 |
1 files changed, 33 insertions, 14 deletions
@@ -408,6 +408,7 @@ static NODE *new_op_assign(struct parser_params *p, NODE *lhs, ID op, NODE *rhs, static NODE *new_ary_op_assign(struct parser_params *p, NODE *ary, NODE *args, ID op, NODE *rhs, const YYLTYPE *args_loc, const YYLTYPE *loc); static NODE *new_attr_op_assign(struct parser_params *p, NODE *lhs, ID atype, ID attr, ID op, NODE *rhs, const YYLTYPE *loc); static NODE *new_const_op_assign(struct parser_params *p, NODE *lhs, ID op, NODE *rhs, const YYLTYPE *loc); +static NODE *new_bodystmt(struct parser_params *p, NODE *head, NODE *rescue, NODE *rescue_else, NODE *ensure, const YYLTYPE *loc); static NODE *const_decl(struct parser_params *p, NODE* path, const YYLTYPE *loc); @@ -991,24 +992,23 @@ begin_block : '{' top_compstmt '}' bodystmt : compstmt opt_rescue - opt_else + k_else {if (!$2) {yyerror1(&@3, "else without rescue is useless");}} + compstmt opt_ensure { /*%%%*/ - $$ = $1; - if ($2) { - $$ = NEW_RESCUE($1, $2, $3, &@$); - } - else if ($3) { - compile_error(p, "else without rescue is useless"); - $$ = block_append(p, $$, $3); - } - if ($4) { - $$ = NEW_ENSURE($$, $4, &@$); - } - fixpos($$, $1); + $$ = new_bodystmt(p, $1, $2, $5, $6, &@$); /*% %*/ - /*% ripper: bodystmt!(escape_Qundef($1), escape_Qundef($2), escape_Qundef($3), escape_Qundef($4)) %*/ + /*% ripper: bodystmt!(escape_Qundef($1), escape_Qundef($2), escape_Qundef($5), escape_Qundef($6)) %*/ + } + | compstmt + opt_rescue + opt_ensure + { + /*%%%*/ + $$ = new_bodystmt(p, $1, $2, 0, $3, &@$); + /*% %*/ + /*% ripper: bodystmt!(escape_Qundef($1), escape_Qundef($2), Qnil, escape_Qundef($3)) %*/ } ; @@ -10201,6 +10201,25 @@ var_field(struct parser_params *p, VALUE a) } #endif +#ifndef RIPPER +static NODE * +new_bodystmt(struct parser_params *p, NODE *head, NODE *rescue, NODE *rescue_else, NODE *ensure, const YYLTYPE *loc) +{ + NODE *result = head; + if (rescue) { + result = NEW_RESCUE(head, rescue, rescue_else, loc); + } + else if (rescue_else) { + result = block_append(p, result, rescue_else); + } + if (ensure) { + result = NEW_ENSURE(result, ensure, loc); + } + fixpos(result, head); + return result; +} +#endif + static void warn_unused_var(struct parser_params *p, struct local_vars *local) { |