From bc49bc7c6b6a16d725cd1279e9021465b1307f3d Mon Sep 17 00:00:00 2001 From: matz Date: Fri, 20 Dec 2002 08:33:17 +0000 Subject: * parse.y (do_block): split "do" block and tLBRACE_ARG block. * parse.y (cmd_brace_block): new tLBRACE_ARG block rule * parse.y (command): can take optional cmd_brace_block; use %prec to resolve shift/reduce conflict. (ruby-bugs-ja PR#372) * eval.c (ruby_finalize): trace_func should be cleared here (after executing exit procs and finalizers). * eval.c (rb_define_alloc_func): new allocation framework, based on Nobu's work [ruby-dev:19116]. "allocate" method is no longer used for object allocation. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3188 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- parse.y | 78 +++++++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 59 insertions(+), 19 deletions(-) (limited to 'parse.y') diff --git a/parse.y b/parse.y index b1d2bfe8f8..5db815e122 100644 --- a/parse.y +++ b/parse.y @@ -248,7 +248,7 @@ static void top_local_setup(); %type mrhs mrhs_basic superclass block_call block_command %type f_arglist f_args f_optarg f_opt f_block_arg opt_f_block_arg %type assoc_list assocs assoc undef_list backref string_dvar -%type block_var opt_block_var brace_block do_block lhs none +%type block_var opt_block_var brace_block cmd_brace_block do_block lhs none %type mlhs mlhs_head mlhs_basic mlhs_entry mlhs_item mlhs_node %type fitem variable sym symbol operation operation2 operation3 %type cname fname op f_rest_arg @@ -286,6 +286,9 @@ static void top_local_setup(); * precedence table */ +%nonassoc LOWEST +%nonassoc tLBRACE_ARG + %left kIF_MOD kUNLESS_MOD kWHILE_MOD kUNTIL_MOD %left kOR kAND %right kNOT @@ -613,21 +616,72 @@ block_command : block_call } ; -command : operation command_args +cmd_brace_block : tLBRACE_ARG + { + $$ = dyna_push(); + $1 = ruby_sourceline; + } + opt_block_var + compstmt + '}' + { + $$ = NEW_ITER($3, 0, $4); + nd_set_line($$, $1); + dyna_pop($2); + } + ; + +command : operation command_args %prec LOWEST + { + $$ = new_fcall($1, $2); + fixpos($$, $2); + } + | operation command_args cmd_brace_block { $$ = new_fcall($1, $2); + if ($3) { + if (nd_type($$) == NODE_BLOCK_PASS) { + rb_compile_error("both block arg and actual block given"); + } + $3->nd_iter = $$; + $$ = $3; + } fixpos($$, $2); } - | primary_value '.' operation2 command_args + | primary_value '.' operation2 command_args %prec LOWEST { $$ = new_call($1, $3, $4); fixpos($$, $1); } - | primary_value tCOLON2 operation2 command_args + | primary_value '.' operation2 command_args cmd_brace_block + { + $$ = new_call($1, $3, $4); + if ($5) { + if (nd_type($$) == NODE_BLOCK_PASS) { + rb_compile_error("both block arg and actual block given"); + } + $5->nd_iter = $$; + $$ = $5; + } + fixpos($$, $1); + } + | primary_value tCOLON2 operation2 command_args %prec LOWEST { $$ = new_call($1, $3, $4); fixpos($$, $1); } + | primary_value tCOLON2 operation2 command_args cmd_brace_block + { + $$ = new_call($1, $3, $4); + if ($5) { + if (nd_type($$) == NODE_BLOCK_PASS) { + rb_compile_error("both block arg and actual block given"); + } + $5->nd_iter = $$; + $$ = $5; + } + fixpos($$, $1); + } | kSUPER command_args { $$ = new_super($2); @@ -1606,20 +1660,6 @@ do_block : kDO_BLOCK nd_set_line($$, $1); dyna_pop($2); } - | tLBRACE_ARG - { - $$ = dyna_push(); - $1 = ruby_sourceline; - } - opt_block_var - compstmt - '}' - { - $$ = NEW_ITER($3, 0, $4); - nd_set_line($$, $1); - dyna_pop($2); - } - ; block_call : command do_block @@ -1629,7 +1669,7 @@ block_call : command do_block } $2->nd_iter = $1; $$ = $2; - fixpos($$, $2); + fixpos($$, $1); } | block_call '.' operation2 opt_paren_args { -- cgit v1.2.3