From: nobu@... Date: 2006-06-25T18:42:58+09:00 Subject: [ruby-dev:28844] Re: when *a なかだです。 At Sat, 24 Jun 2006 23:53:27 +0900, Yukihiro Matsumoto wrote in [ruby-dev:28829]: > |At Sat, 24 Jun 2006 14:14:15 +0900, > |Minero Aoki wrote in [ruby-dev:28822]: > |> 次のように、when *a が動作しなくなっています。 > | > |こんなとこでしょうか。 > > コミットしてください。 これだと when /b/, *[/a/] のような場合に動作してませんでした。 現状ではargsをそのまま使うようになっていますが、「ひとつひとつ 評価してはマッチさせる」という動作には不向きです。when_argsを復 活させたほうがいいような気がします。 Index: eval.c =================================================================== RCS file: /cvs/ruby/src/ruby/eval.c,v retrieving revision 1.903 diff -p -U2 -r1.903 eval.c --- eval.c 23 Jun 2006 08:28:04 -0000 1.903 +++ eval.c 25 Jun 2006 08:01:46 -0000 @@ -2855,5 +2868,5 @@ rb_eval(VALUE self, NODE *n) ruby_frame->this_func, ruby_frame->this_class); - if (tag->nd_head && nd_type(tag->nd_head) == NODE_WHEN) { + if (tag->nd_head && nd_type(tag->nd_head) == NODE_SPLAT) { VALUE v = rb_eval(self, tag->nd_head->nd_head); long i; Index: parse.y =================================================================== RCS file: /cvs/ruby/src/ruby/parse.y,v retrieving revision 1.443 diff -p -U2 -r1.443 parse.y --- parse.y 21 Jun 2006 08:08:34 -0000 1.443 +++ parse.y 25 Jun 2006 07:56:00 -0000 @@ -533,5 +536,5 @@ static void ripper_compile_error(struct %type expr_value arg_value primary_value %type if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure -%type args call_args call_args2 opt_call_args +%type args when_args call_args call_args2 opt_call_args %type open_args paren_args opt_paren_args %type command_args aref_args opt_block_arg block_arg var_ref var_lhs @@ -3377,5 +3385,5 @@ brace_block : '{' ; -case_body : kWHEN args then +case_body : kWHEN when_args then compstmt cases @@ -3389,4 +3397,38 @@ case_body : kWHEN args then ; +when_args : arg_value + { + /*%%%*/ + $$ = NEW_LIST($1); + /*% + $$ = arg_add(arg_new(), $1); + %*/ + } + | tSTAR arg_value + { + /*%%%*/ + $$ = NEW_LIST(NEW_SPLAT($2)); + /*% + $$ = arg_add_star(arg_new(), $2); + %*/ + } + | when_args ',' arg_value + { + /*%%%*/ + $$ = list_append($1, $3); + /*% + $$ = arg_add($1, $3); + %*/ + } + | when_args ',' tSTAR arg_value + { + /*%%%*/ + $$ = list_append($1, NEW_SPLAT($4)); + /*% + $$ = arg_add_star($1, $4); + %*/ + } + ; + cases : opt_else | case_body -- --- 僕の前にBugはない。 --- 僕の後ろにBugはできる。 中田 伸悦