From ce769284a1917aaf92510519634d1965d0a44ab5 Mon Sep 17 00:00:00 2001 From: mame Date: Tue, 16 Jan 2018 05:27:20 +0000 Subject: [PATCH] parse.y (expr_value_do): factor out COND_PUSH->expr_value->do->COND_POP git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61868 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- parse.y | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/parse.y b/parse.y index 616cad7b0d..739746ca22 100644 --- a/parse.y +++ b/parse.y @@ -869,7 +869,7 @@ static void token_info_pop(struct parser_params*, const char *token, const rb_co %type literal numeric simple_numeric dsym cpath %type top_compstmt top_stmts top_stmt begin_block %type bodystmt compstmt stmts stmt_or_begin stmt expr arg primary command command_call method_call -%type expr_value arg_value primary_value fcall rel_expr +%type expr_value expr_value_do arg_value primary_value fcall rel_expr %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 args_tail opt_args_tail block_args_tail opt_block_args_tail @@ -1368,6 +1368,12 @@ expr_value : expr } ; +expr_value_do : {COND_PUSH(1);} expr_value do {COND_POP();} + { + $$ = $2; + } + + command_call : command | block_command ; @@ -2512,26 +2518,26 @@ primary : literal $$ = dispatch3(unless, $2, $4, escape_Qundef($5)); %*/ } - | k_while {COND_PUSH(1);} expr_value do {COND_POP();} + | k_while expr_value_do compstmt k_end { /*%%%*/ - $$ = NEW_WHILE(cond(p, $3, &@3), $6, 1, &@$); - fixpos($$, $3); + $$ = NEW_WHILE(cond(p, $2, &@2), $3, 1, &@$); + fixpos($$, $2); /*% - $$ = dispatch2(while, $3, $6); + $$ = dispatch2(while, $2, $3); %*/ } - | k_until {COND_PUSH(1);} expr_value do {COND_POP();} + | k_until expr_value_do compstmt k_end { /*%%%*/ - $$ = NEW_UNTIL(cond(p, $3, &@3), $6, 1, &@$); - fixpos($$, $3); + $$ = NEW_UNTIL(cond(p, $2, &@2), $3, 1, &@$); + fixpos($$, $2); /*% - $$ = dispatch2(until, $3, $6); + $$ = dispatch2(until, $2, $3); %*/ } | k_case expr_value opt_terms @@ -2553,10 +2559,7 @@ primary : literal $$ = dispatch2(case, Qnil, $3); %*/ } - | k_for for_var keyword_in - {COND_PUSH(1);} - expr_value do - {COND_POP();} + | k_for for_var keyword_in expr_value_do compstmt k_end { @@ -2597,12 +2600,12 @@ primary : literal } } add_mark_object(p, (VALUE)rb_imemo_alloc_new((VALUE)tbl, 0, 0, 0)); - scope = NEW_NODE(NODE_SCOPE, tbl, $8, args, &@$); + scope = NEW_NODE(NODE_SCOPE, tbl, $5, args, &@$); tbl[0] = 1; tbl[1] = id; - $$ = NEW_FOR(0, $5, scope, &@$); + $$ = NEW_FOR(0, $4, scope, &@$); fixpos($$, $2); /*% - $$ = dispatch3(for, $2, $5, $8); + $$ = dispatch3(for, $2, $4, $5); %*/ } | k_class cpath superclass