summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-06-20 07:11:44 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-06-20 07:11:44 +0000
commitf289fddace1c84075e6794e24a3d46aee6b35d69 (patch)
treed84ee3ea9c21646d38e396bb875c4bcc591a81f4 /parse.y
parent65ba3eba645a61ae9995f9f1e88cab6150c858a7 (diff)
* parse.y (new_yield): distinguish "yield 1,2" and "yield [1,2]".
[ruby-dev:20360] * eval.c (rb_eval): support new_yield() change. * variable.c (rb_const_get_0): warn for Foo::BAR when BAR is a toplevel constant (i.e. a constant defined under Object). [ruby-list:36935] * parse.y (no_blockarg): separate no block argument check and ret_args argument processing. * range.c (rb_range_beg_len): out_of_range check after adjusting end point. [ruby-dev:20370] * parse.y (call_args): the first argument to arg_cancat() should be NODE_LIST. [ruby-core:01151] * eval.c (rb_eval): should dispatch based on ID type. * eval.c (rb_yield_0): should restore scope_vmode during yield. [ruby-dev:20361] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3967 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y51
1 files changed, 41 insertions, 10 deletions
diff --git a/parse.y b/parse.y
index c09522d..e87bcfe 100644
--- a/parse.y
+++ b/parse.y
@@ -145,6 +145,7 @@ static NODE *arg_blk_pass();
static NODE *new_call();
static NODE *new_fcall();
static NODE *new_super();
+static NODE *new_yield();
static NODE *gettable();
static NODE *assignable();
@@ -714,7 +715,7 @@ command : operation command_args %prec tLOWEST
}
| kYIELD command_args
{
- $$ = NEW_YIELD(ret_args($2));
+ $$ = new_yield($2);
fixpos($$, $2);
}
;
@@ -1287,7 +1288,7 @@ call_args2 : arg_value ',' args opt_block_arg
}
| arg_value ',' args ',' tSTAR arg_value opt_block_arg
{
- $$ = arg_concat(list_concat($1,$3), $6);
+ $$ = arg_concat(list_concat(NEW_LIST($1),$3), $6);
$$ = arg_blk_pass($$, $7);
}
| assocs opt_block_arg
@@ -1454,15 +1455,15 @@ primary : literal
}
| kYIELD '(' call_args ')'
{
- $$ = NEW_YIELD(ret_args($3));
+ $$ = new_yield($3);
}
| kYIELD '(' ')'
{
- $$ = NEW_YIELD(0);
+ $$ = NEW_YIELD(0, Qfalse);
}
| kYIELD
{
- $$ = NEW_YIELD(0);
+ $$ = NEW_YIELD(0, Qfalse);
}
| kDEFINED opt_nl '(' {in_defined = 1;} expr ')'
{
@@ -5366,22 +5367,52 @@ cond_negative(nodep)
return 0;
}
+static void
+no_blockarg(node)
+ NODE *node;
+{
+ if (node && nd_type(node) == NODE_BLOCK_PASS) {
+ rb_compile_error("block argument should not be given");
+ }
+}
+
static NODE *
ret_args(node)
NODE *node;
{
if (node) {
- if (nd_type(node) == NODE_BLOCK_PASS) {
- rb_compile_error("block argument should not be given");
+ no_blockarg(node);
+ if (nd_type(node) == NODE_ARRAY && node->nd_next == 0) {
+ node = node->nd_head;
+ }
+ if (nd_type(node) == NODE_RESTARY) {
+ nd_set_type(node, NODE_SPLAT);
}
+ }
+ return node;
+}
+
+static NODE *
+new_yield(node)
+ NODE *node;
+{
+ long state = Qtrue;
+
+ if (node) {
+ no_blockarg(node);
if (nd_type(node) == NODE_ARRAY && node->nd_next == 0) {
node = node->nd_head;
+ state = Qfalse;
+ }
+ if (nd_type(node) == NODE_RESTARY) {
+ nd_set_type(node, NODE_SPLAT);
+ state = Qfalse;
}
}
- if (node && nd_type(node) == NODE_RESTARY) {
- nd_set_type(node, NODE_SPLAT);
+ else {
+ state = Qfalse;
}
- return node;
+ return NEW_YIELD(node, state);
}
static NODE*