ruby-changes:14870
From: knu <ko1@a...>
Date: Wed, 24 Feb 2010 00:46:04 +0900 (JST)
Subject: [ruby-changes:14870] Ruby:r26737 (ruby_1_8): * parse.y: Revert r26609, r26160, r25658 and r24695. The loose
knu 2010-02-24 00:45:50 +0900 (Wed, 24 Feb 2010) New Revision: 26737 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=26737 Log: * parse.y: Revert r26609, r26160, r25658 and r24695. The loose args patch caused a lot of problem and we just could not fix them all in a timely manner. Modified files: branches/ruby_1_8/ChangeLog branches/ruby_1_8/parse.y Index: ruby_1_8/parse.y =================================================================== --- ruby_1_8/parse.y (revision 26736) +++ ruby_1_8/parse.y (revision 26737) @@ -126,10 +126,7 @@ static int command_start = Qtrue; static NODE *deferred_nodes; -static NODE *NEW_POSTARG(); -static NODE *new_args(); - static NODE *cond(); static NODE *logop(); static int cond_negative(); @@ -147,12 +144,10 @@ static NODE *block_append(); static NODE *list_append(); static NODE *list_concat(); -static NODE *arg_append(); static NODE *arg_concat(); static NODE *literal_concat(); static NODE *new_evstr(); static NODE *evstr2dstr(); -static NODE *splat_array(); static NODE *call_op(); static int in_defined = 0; @@ -284,15 +279,14 @@ %type <node> bodystmt compstmt stmts stmt expr arg primary command command_call method_call %type <node> expr_value arg_value primary_value %type <node> if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure -%type <node> args args2 call_args call_args2 opt_call_args -%type <node> open_args paren_args opt_paren_args +%type <node> args when_args call_args call_args2 open_args paren_args opt_paren_args %type <node> command_args aref_args opt_block_arg block_arg var_ref var_lhs %type <node> mrhs superclass block_call block_command %type <node> f_arglist f_args f_optarg f_opt f_rest_arg f_block_arg opt_f_block_arg %type <node> assoc_list assocs assoc undef_list backref string_dvar %type <node> for_var block_var opt_block_var block_par %type <node> brace_block cmd_brace_block do_block lhs none fitem -%type <node> mlhs mlhs_head mlhs_basic mlhs_entry mlhs_item mlhs_node mlhs_post +%type <node> mlhs mlhs_head mlhs_basic mlhs_entry mlhs_item mlhs_node %type <id> fsym variable sym symbol operation operation2 operation3 %type <id> cname fname op %type <num> f_norm_arg f_arg @@ -552,11 +546,12 @@ $$ = 0; } } - | primary_value '[' opt_call_args ']' tOP_ASGN command_call + | primary_value '[' aref_args ']' tOP_ASGN command_call { - NODE *args = $3; + NODE *args; value_expr($6); + if (!$3) $3 = NEW_ZARRAY(); args = arg_concat($6, $3); if ($5 == tOROP) { $5 = 0; @@ -783,34 +778,18 @@ { $$ = NEW_MASGN($1, $3); } - | mlhs_head tSTAR mlhs_node ',' mlhs_post - { - $$ = NEW_MASGN($1, NEW_POSTARG($3,$5)); - } | mlhs_head tSTAR { $$ = NEW_MASGN($1, -1); } - | mlhs_head tSTAR ',' mlhs_post - { - $$ = NEW_MASGN($1, NEW_POSTARG((NODE *)-1, $4)); - } | tSTAR mlhs_node { $$ = NEW_MASGN(0, $2); } - | tSTAR mlhs_node ',' mlhs_post - { - $$ = NEW_MASGN(0, NEW_POSTARG($2,$4)); - } | tSTAR { $$ = NEW_MASGN(0, -1); } - | tSTAR ',' mlhs_post - { - $$ = NEW_MASGN(0, NEW_POSTARG((NODE *)-1, $3)); - } ; mlhs_item : mlhs_node @@ -830,21 +809,11 @@ } ; -mlhs_post : mlhs_item - { - $$ = NEW_LIST($1); - } - | mlhs_post ',' mlhs_item - { - $$ = list_append($1, $3); - } - ; - mlhs_node : variable { $$ = assignable($1, 0); } - | primary_value '[' opt_call_args ']' + | primary_value '[' aref_args ']' { $$ = aryset($1, $3); } @@ -883,7 +852,7 @@ { $$ = assignable($1, 0); } - | primary_value '[' opt_call_args ']' + | primary_value '[' aref_args ']' { $$ = aryset($1, $3); } @@ -1045,7 +1014,7 @@ $$ = 0; } } - | primary_value '[' opt_call_args ']' tOP_ASGN arg + | primary_value '[' aref_args ']' tOP_ASGN arg { NODE *args; @@ -1277,58 +1246,90 @@ ; aref_args : none + | command opt_nl + { + $$ = NEW_LIST($1); + } | args trailer { $$ = $1; } - | args ',' assocs trailer + | args ',' tSTAR arg opt_nl { - $$ = arg_append($1, NEW_HASH($3)); + value_expr($4); + $$ = arg_concat($1, $4); } | assocs trailer { $$ = NEW_LIST(NEW_HASH($1)); } + | tSTAR arg opt_nl + { + value_expr($2); + $$ = NEW_NEWLINE(NEW_SPLAT($2)); + } ; -paren_args : '(' opt_call_args ')' +paren_args : '(' none ')' { $$ = $2; } - ; - -opt_paren_args : none - | paren_args - ; - -opt_call_args : opt_nl + | '(' call_args opt_nl ')' { - $$ = 0; + $$ = $2; } - | call_args opt_nl + | '(' block_call opt_nl ')' { - $$ = $1; + $$ = NEW_LIST($2); } + | '(' args ',' block_call opt_nl ')' + { + $$ = list_append($2, $4); + } ; +opt_paren_args : none + | paren_args + ; + call_args : command { $$ = NEW_LIST($1); } - | args2 opt_block_arg + | args opt_block_arg { $$ = arg_blk_pass($1, $2); } + | args ',' tSTAR arg_value opt_block_arg + { + $$ = arg_concat($1, $4); + $$ = arg_blk_pass($$, $5); + } | assocs opt_block_arg { $$ = NEW_LIST(NEW_HASH($1)); $$ = arg_blk_pass($$, $2); } - | args2 ',' assocs opt_block_arg + | assocs ',' tSTAR arg_value opt_block_arg { + $$ = arg_concat(NEW_LIST(NEW_HASH($1)), $4); + $$ = arg_blk_pass($$, $5); + } + | args ',' assocs opt_block_arg + { $$ = list_append($1, NEW_HASH($3)); $$ = arg_blk_pass($$, $4); } + | args ',' assocs ',' tSTAR arg opt_block_arg + { + value_expr($6); + $$ = arg_concat(list_append($1, NEW_HASH($3)), $6); + $$ = arg_blk_pass($$, $7); + } + | tSTAR arg_value opt_block_arg + { + $$ = arg_blk_pass(NEW_SPLAT($2), $3); + } | block_arg ; @@ -1340,11 +1341,26 @@ { $$ = arg_blk_pass($1, $3); } + | arg_value ',' tSTAR arg_value opt_block_arg + { + $$ = arg_concat(NEW_LIST($1), $4); + $$ = arg_blk_pass($$, $5); + } + | arg_value ',' args ',' tSTAR arg_value opt_block_arg + { + $$ = arg_concat(list_concat(NEW_LIST($1),$3), $6); + $$ = arg_blk_pass($$, $7); + } | assocs opt_block_arg { $$ = NEW_LIST(NEW_HASH($1)); $$ = arg_blk_pass($$, $2); } + | assocs ',' tSTAR arg_value opt_block_arg + { + $$ = arg_concat(NEW_LIST(NEW_HASH($1)), $4); + $$ = arg_blk_pass($$, $5); + } | arg_value ',' assocs opt_block_arg { $$ = list_append(NEW_LIST($1), NEW_HASH($3)); @@ -1355,6 +1371,20 @@ $$ = list_append(list_concat(NEW_LIST($1),$3), NEW_HASH($5)); $$ = arg_blk_pass($$, $6); } + | arg_value ',' assocs ',' tSTAR arg_value opt_block_arg + { + $$ = arg_concat(list_append(NEW_LIST($1), NEW_HASH($3)), $6); + $$ = arg_blk_pass($$, $7); + } + | arg_value ',' args ',' assocs ',' tSTAR arg_value opt_block_arg + { + $$ = arg_concat(list_append(list_concat(NEW_LIST($1), $3), NEW_HASH($5)), $8); + $$ = arg_blk_pass($$, $9); + } + | tSTAR arg_value opt_block_arg + { + $$ = arg_blk_pass(NEW_SPLAT($2), $3); + } | block_arg ; @@ -1396,54 +1426,16 @@ | none ; -args : arg_value +args : arg_value { $$ = NEW_LIST($1); } - | tSTAR arg_value - { - if (!($$ = splat_array($2))) $$ = NEW_SPLAT($2); - } | args ',' arg_value { $$ = list_append($1, $3); } - | args ',' tSTAR arg_value - { - NODE *n1; - if ((nd_type($4) == NODE_ARRAY) && (n1 = splat_array($1)) != 0) { - $$ = list_concat(n1, $4); - } - else { - $$ = arg_concat($1, $4); - } - } ; -args2 : arg_value - { - $$ = NEW_LIST($1); - } - | tSTAR arg_value - { - $$ = NEW_SPLAT($2); - } - | args2 ',' arg_value - { - $$ = list_append($1, $3); - } - | args2 ',' tSTAR arg_value - { - NODE *n1; - if ((nd_type($4) == NODE_ARRAY) && (n1 = splat_array($1)) != 0) { - $$ = list_concat(n1, $4); - } - else { - $$ = arg_concat($1, $4); - } - } - ; - mrhs : args ',' arg_value { $$ = list_append($1, $3); @@ -1501,15 +1493,22 @@ { $$ = NEW_COLON3($2); } - | tLBRACK {$<num>$ = ruby_sourceline;} aref_args ']' + | primary_value '[' aref_args ']' { - if ($3 == 0) { + if ($1 && nd_type($1) == NODE_SELF) + $$ = NEW_FCALL(tAREF, $3); + else + $$ = NEW_CALL($1, tAREF, $3); + fixpos($$, $1); + } + | tLBRACK aref_args ']' + { + if ($2 == 0) { $$ = NEW_ZARRAY(); /* zero length array*/ } else { - $$ = $3; + $$ = $2; } - nd_set_line($$, $<num>2); } | tLBRACE assoc_list '}' { @@ -1909,14 +1908,6 @@ { $$ = NEW_ZSUPER(); } - | primary_value '[' opt_call_args ']' - { - if ($1 && nd_type($1) == NODE_SELF) - $$ = NEW_FCALL(tAREF, $3); - else - $$ = NEW_CALL($1, tAREF, $3); - fixpos($$, $1); - } ; brace_block : '{' @@ -1945,13 +1936,23 @@ } ; -case_body : kWHEN args then +case_body : kWHEN when_args then compstmt cases { $$ = NEW_WHEN($2, $4, $5); } ; +when_args : args + | args ',' tSTAR arg_value + { + $$ = list_append($1, NEW_WHEN($4, 0, 0)); + } + | tSTAR arg_value + { + $$ = NEW_LIST(NEW_WHEN($2, 0, 0)); + } + ; cases : opt_else | case_body @@ -2305,63 +2306,39 @@ f_args : f_arg ',' f_optarg ',' f_rest_arg opt_f_block_arg { - $$ = new_args($1, $3, $5, 0, $6); + $$ = block_append(NEW_ARGS($1, $3, $5), $6); } - | f_arg ',' f_optarg ',' f_rest_arg ',' f_arg opt_f_block_arg - { - $$ = new_args($1, $3, $5, $7, $8); - } | f_arg ',' f_optarg opt_f_block_arg { - $$ = new_args($1, $3, 0, 0, $4); + $$ = block_append(NEW_ARGS($1, $3, 0), $4); } - | f_arg ',' f_optarg ',' f_arg opt_f_block_arg - { - $$ = new_args($1, $3, 0, $5, $6); - } | f_arg ',' f_rest_arg opt_f_block_arg { - $$ = new_args($1, 0, $3, 0, $4); + $$ = block_append(NEW_ARGS($1, 0, $3), $4); } - | f_arg ',' f_rest_arg ',' f_arg opt_f_block_arg - { - $$ = new_args($1, 0, $3, $5, $6); - } | f_arg opt_f_block_arg { - $$ = new_args($1, 0, 0, 0, $2); + $$ = block_append(NEW_ARGS($1, 0, 0), $2); } | f_optarg ',' f_rest_arg opt_f_block_arg { - $$ = new_args(0, $1, $3, 0, $4); + $$ = block_append(NEW_ARGS(0, $1, $3), $4); } - | f_optarg ',' f_rest_arg ',' f_arg opt_f_block_arg - { - $$ = new_args(0, $1, $3, $5, $6); - } | f_optarg opt_f_block_arg { - $$ = new_args(0, $1, 0, 0, $2); + $$ = block_append(NEW_ARGS(0, $1, 0), $2); } - | f_optarg ',' f_arg opt_f_block_arg - { - $$ = new_args(0, $1, 0, $3, $4); - } | f_rest_arg opt_f_block_arg { - $$ = new_args(0, 0, $1, 0, $2); + $$ = block_append(NEW_ARGS(0, 0, $1), $2); } - | f_rest_arg ',' f_arg opt_f_block_arg - { - $$ = new_args(0, 0, $1, $3, $4); - } | f_block_arg { - $$ = new_args(0, 0, 0, 0, $1); + $$ = block_append(NEW_ARGS(0, 0, 0), $1); } | /* none */ { - $$ = new_args(0, 0, 0, 0, 0); + $$ = NEW_ARGS(0, 0, 0); } ; @@ -2524,7 +2501,11 @@ } | tLABEL arg_value { + /*%%%*/ $$ = list_append(NEW_LIST(NEW_LIT(ID2SYM($1))), $2); + /*% + $$ = dispatch2(assoc_new, $1, $2); + %*/ } ; @@ -4859,23 +4840,6 @@ return head; } -static NODE* -new_args(m, o, r, p, b) - NODE *m, *o, *p, *b; - ID r; -{ - if (p) { - ID i = rb_intern("raise"); - VALUE e = rb_eSyntaxError; /* or maybe a subclass of it? */ - VALUE s = rb_str_new2("Unsupported 1.9-ism: loose formal opt/rest args"); - NODE *n = NEW_FCALL(i, list_append(NEW_LIST(NEW_LIT(e)), NEW_LIT(s))); - NODE *b = NEW_BLOCK(n); - b->nd_end = b; - return b; - } - return block_append(NEW_ARGS(m, o, r), b); -} - static NODE * evstr2dstr(node) NODE *node; @@ -4905,25 +4869,7 @@ return NEW_EVSTR(head); } -static VALUE -new_postarg_internal_raise(argc, argv) - int argc; - VALUE *argv; -{ - rb_raise(rb_eSyntaxError, "Unsupported 1.9-ism: loose multiple assignment (LHS)"); - return Qundef; /* NOTREACHED */ -} - static NODE * -NEW_POSTARG(n1, n2) - NODE *n1, *n2; -{ - VALUE obj = rb_obj_alloc(rb_cObject); - rb_define_singleton_method(obj, "raise", new_postarg_internal_raise, -1); - return NEW_CALL(NEW_LIT(obj), rb_intern("raise"), NEW_LIST(0)); -} - -static NODE * call_op(recv, id, narg, arg1) NODE *recv; ID id; @@ -5137,15 +5083,6 @@ } static NODE * -arg_append(node1, node2) - NODE *node1; - NODE *node2; -{ - if (!node1) return NEW_LIST(node2); - return NEW_ARGSPUSH(node1, node2); -} - -static NODE * arg_concat(node1, node2) NODE *node1; NODE *node2; @@ -5168,16 +5105,6 @@ } } -static NODE * -splat_array(node) - NODE* node; -{ - if (nd_type(node) == NODE_NEWLINE) node = node->nd_next; - if (nd_type(node) == NODE_SPLAT) node = node->nd_head; - if (nd_type(node) == NODE_ARRAY) return node; - return 0; -} - static NODE* node_assign(lhs, rhs) NODE *lhs, *rhs; Index: ruby_1_8/ChangeLog =================================================================== --- ruby_1_8/ChangeLog (revision 26736) +++ ruby_1_8/ChangeLog (revision 26737) @@ -1,3 +1,9 @@ +Wed Feb 24 00:40:58 2010 Akinori MUSHA <knu@i...> + + * parse.y: Revert r26609, r26160, r25658 and r24695. The loose + args patch caused a lot of problem and we just could not fix + them all in a timely manner. + Fri Feb 19 12:15:21 2010 NARUSE, Yui <naruse@r...> * ext/readline/readline.c (Init_readline): initialize -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/