ruby-changes:44123
From: nobu <ko1@a...>
Date: Wed, 21 Sep 2016 13:32:16 +0900 (JST)
Subject: [ruby-changes:44123] nobu:r56195 (trunk): parse.y: block bodies
nobu 2016-09-21 13:32:03 +0900 (Wed, 21 Sep 2016) New Revision: 56195 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56195 Log: parse.y: block bodies * parse.y (brace_body, do_body): extract block bodies. Modified files: trunk/ChangeLog trunk/parse.y Index: ChangeLog =================================================================== --- ChangeLog (revision 56194) +++ ChangeLog (revision 56195) @@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Sep 21 13:32:00 2016 Nobuyoshi Nakada <nobu@r...> + + * parse.y (brace_body, do_body): extract block bodies. + Tue Sep 20 23:02:50 2016 Nobuyoshi Nakada <nobu@r...> * gc.c (gc_start_internal): [DOC] add ObjectSpace.garbage_collect Index: parse.y =================================================================== --- parse.y (revision 56194) +++ parse.y (revision 56195) @@ -508,6 +508,9 @@ static NODE *new_xstring_gen(struct pars https://github.com/ruby/ruby/blob/trunk/parse.y#L508 #define new_xstring(node) new_xstring_gen(parser, node) #define new_string1(str) (str) +#define new_brace_body(param, stmt) NEW_ITER(param, stmt) +#define new_do_body(param, stmt) NEW_ITER(param, stmt) + static NODE *match_op_gen(struct parser_params*,NODE*,NODE*); #define match_op(node1,node2) match_op_gen(parser, (node1), (node2)) @@ -572,6 +575,9 @@ static VALUE new_xstring_gen(struct pars https://github.com/ruby/ruby/blob/trunk/parse.y#L575 #define new_xstring(str) new_xstring_gen(parser, str) #define new_string1(str) dispatch1(string_literal, str) +#define new_brace_body(param, stmt) dispatch2(brace_block, escape_Qundef(param), stmt) +#define new_do_body(param, stmt) dispatch2(do_block, escape_Qundef(param), stmt) + #define const_path_field(w, n) dispatch2(const_path_field, (w), (n)) #define top_const_field(n) dispatch1(top_const_field, (n)) static VALUE const_decl_gen(struct parser_params *parser, VALUE path); @@ -903,7 +909,7 @@ static void token_info_pop_gen(struct pa https://github.com/ruby/ruby/blob/trunk/parse.y#L909 %type <node> block_param opt_block_param block_param_def f_opt %type <node> f_kwarg f_kw f_block_kwarg f_block_kw %type <node> bv_decls opt_bv_decl bvar -%type <node> lambda f_larglist lambda_body +%type <node> lambda f_larglist lambda_body brace_body do_body %type <node> brace_block cmd_brace_block do_block lhs none fitem %type <node> mlhs mlhs_head mlhs_basic mlhs_item mlhs_node mlhs_post mlhs_inner %type <id> fsym keyword_variable user_variable sym symbol operation operation2 operation3 @@ -1460,23 +1466,17 @@ block_command : block_call https://github.com/ruby/ruby/blob/trunk/parse.y#L1466 cmd_brace_block : tLBRACE_ARG { - $<vars>1 = dyna_push(); /*%%%*/ $<num>$ = ruby_sourceline; /*% %*/ } - opt_block_param - compstmt - '}' + brace_body '}' { - /*%%%*/ - $$ = NEW_ITER($3,$4); + $$ = $3; + /*%%%*/ nd_set_line($$, $<num>2); - /*% - $$ = dispatch2(brace_block, escape_Qundef($3), $4); - %*/ - dyna_pop($<vars>1); + /*% %*/ } ; @@ -3554,22 +3554,16 @@ lambda_body : tLAMBEG compstmt '}' https://github.com/ruby/ruby/blob/trunk/parse.y#L3554 do_block : keyword_do_block { - $<vars>1 = dyna_push(); /*%%%*/ $<num>$ = ruby_sourceline; /*% %*/ } - opt_block_param - compstmt - keyword_end + do_body keyword_end { - /*%%%*/ - $$ = NEW_ITER($3,$4); + $$ = $3; + /*%%%*/ nd_set_line($$, $<num>2); - /*% - $$ = dispatch2(do_block, escape_Qundef($3), $4); - %*/ - dyna_pop($<vars>1); + /*% %*/ } ; @@ -3738,44 +3732,42 @@ method_call : fcall paren_args https://github.com/ruby/ruby/blob/trunk/parse.y#L3732 brace_block : '{' { - $<vars>1 = dyna_push(); /*%%%*/ $<num>$ = ruby_sourceline; - /*% - %*/ + /*% %*/ } - opt_block_param - compstmt '}' + brace_body '}' { + $$ = $3; /*%%%*/ - $$ = NEW_ITER($3,$4); nd_set_line($$, $<num>2); - /*% - $$ = dispatch2(brace_block, escape_Qundef($3), $4); - %*/ - dyna_pop($<vars>1); + /*% %*/ } | keyword_do { - $<vars>1 = dyna_push(); /*%%%*/ $<num>$ = ruby_sourceline; - /*% - %*/ + /*% %*/ } - opt_block_param - compstmt keyword_end + do_body keyword_end { + $$ = $3; /*%%%*/ - $$ = NEW_ITER($3,$4); nd_set_line($$, $<num>2); - /*% - $$ = dispatch2(do_block, escape_Qundef($3), $4); - %*/ - dyna_pop($<vars>1); + /*% %*/ } ; +brace_body : {$<vars>$ = dyna_push();} + opt_block_param compstmt + {$$ = new_brace_body($2, $3); dyna_pop($<vars>1);} + ; + +do_body : {$<vars>$ = dyna_push();} + opt_block_param compstmt + {$$ = new_do_body($2, $3); dyna_pop($<vars>1);} + ; + case_body : keyword_when args then compstmt cases -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/