1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* parse.y (block_call): syntax restructure.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1142 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2001-01-20 14:02:28 +00:00
parent 77b8745d4a
commit 6aa451b9dd
2 changed files with 54 additions and 53 deletions

View file

@ -4,6 +4,8 @@ Sat Jan 20 03:54:00 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
preceding was too high. a block in `foo bar do .. end' should preceding was too high. a block in `foo bar do .. end' should
be passed to `foo', not `bar'. be passed to `foo', not `bar'.
* parse.y (block_call): syntax restructure.
Thu Jan 18 04:28:14 2001 Yukihiro Matsumoto <matz@ruby-lang.org> Thu Jan 18 04:28:14 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (rb_io_s_read): new method to call IO#read from * io.c (rb_io_s_read): new method to call IO#read from

105
parse.y
View file

@ -184,11 +184,11 @@ static void top_local_setup();
%type <node> singleton string %type <node> singleton string
%type <val> literal numeric %type <val> literal numeric
%type <node> compstmt stmts stmt expr arg primary command_call method_call %type <node> compstmt stmts stmt expr arg primary command command_call method_call
%type <node> if_tail opt_else case_body cases rescue exc_list exc_var ensure %type <node> if_tail opt_else case_body cases rescue exc_list exc_var ensure
%type <node> opt_call_args call_args ret_args args when_args %type <node> opt_call_args call_args ret_args args when_args
%type <node> aref_args opt_block_arg block_arg stmt_rhs %type <node> aref_args opt_block_arg block_arg var_ref
%type <node> mrhs mrhs_basic superclass generic_call block_call var_ref %type <node> mrhs mrhs_basic superclass generic_call block_call blocklike_call
%type <node> f_arglist f_args f_optarg f_opt f_block_arg opt_f_block_arg %type <node> f_arglist f_args f_optarg f_opt f_block_arg opt_f_block_arg
%type <node> assoc_list assocs assoc undef_list backref %type <node> assoc_list assocs assoc undef_list backref
%type <node> block_var opt_block_var brace_block do_block lhs none %type <node> block_var opt_block_var brace_block do_block lhs none
@ -295,8 +295,7 @@ stmts : none
$$ = $2; $$ = $2;
} }
stmt : block_call stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem
| kALIAS fitem {lex_state = EXPR_FNAME;} fitem
{ {
if (cur_mid || in_single) if (cur_mid || in_single)
yyerror("alias within method"); yyerror("alias within method");
@ -396,12 +395,12 @@ stmt : block_call
$$ = NEW_ITER(0, NEW_POSTEXE(), $3); $$ = NEW_ITER(0, NEW_POSTEXE(), $3);
} }
| lhs '=' stmt_rhs | lhs '=' command_call
{ {
value_expr($3); value_expr($3);
$$ = node_assign($1, $3); $$ = node_assign($1, $3);
} }
| mlhs '=' stmt_rhs | mlhs '=' command_call
{ {
value_expr($3); value_expr($3);
$1->nd_value = $3; $1->nd_value = $3;
@ -445,7 +444,22 @@ expr : mlhs '=' mrhs
} }
| arg | arg
command_call : operation call_args command_call : command
| blocklike_call
blocklike_call : block_call
| block_call '.' operation2 call_args
{
value_expr($1);
$$ = new_call($1, $3, $4);
}
| block_call tCOLON2 operation2 call_args
{
value_expr($1);
$$ = new_call($1, $3, $4);
}
command : operation call_args
{ {
$$ = new_fcall($1, $2); $$ = new_fcall($1, $2);
fixpos($$, $2); fixpos($$, $2);
@ -897,14 +911,6 @@ aref_args : none
{ {
$$ = list_append($1, $3); $$ = list_append($1, $3);
} }
| block_call opt_nl
{
$$ = NEW_LIST($1);
}
| args ',' block_call opt_nl
{
$$ = list_append($1, $3);
}
| args trailer | args trailer
{ {
$$ = $1; $$ = $1;
@ -926,24 +932,20 @@ aref_args : none
opt_call_args : none opt_call_args : none
| call_args opt_nl | call_args opt_nl
| block_call opt_nl | blocklike_call opt_nl
{ {
$$ = NEW_LIST($1); $$ = NEW_LIST($1);
} }
| args ',' block_call | args ',' blocklike_call
{ {
$$ = list_append($1, $3); $$ = list_append($1, $3);
} }
call_args : command_call call_args : command
{ {
$$ = NEW_LIST($1); $$ = NEW_LIST($1);
} /* }
| args ',' | args ',' command
{
$$ = $1;
} */
| args ',' command_call
{ {
$$ = list_append($1, $3); $$ = list_append($1, $3);
} }
@ -956,11 +958,7 @@ call_args : command_call
value_expr($4); value_expr($4);
$$ = arg_concat($1, $4); $$ = arg_concat($1, $4);
$$ = arg_blk_pass($$, $5); $$ = arg_blk_pass($$, $5);
} /* }
| assocs ','
{
$$ = NEW_LIST(NEW_HASH($1));
} */
| assocs opt_block_arg | assocs opt_block_arg
{ {
$$ = NEW_LIST(NEW_HASH($1)); $$ = NEW_LIST(NEW_HASH($1));
@ -976,11 +974,7 @@ call_args : command_call
{ {
$$ = list_append($1, NEW_HASH($3)); $$ = list_append($1, NEW_HASH($3));
$$ = arg_blk_pass($$, $4); $$ = arg_blk_pass($$, $4);
} /* }
| args ',' assocs ','
{
$$ = list_append($1, NEW_HASH($3));
} */
| args ',' assocs ',' tSTAR arg opt_block_arg | args ',' assocs ',' tSTAR arg opt_block_arg
{ {
value_expr($6); value_expr($6);
@ -1345,7 +1339,7 @@ then : term
| term kTHEN | term kTHEN
do : term do : term
| kDO | kDO2
if_tail : opt_else if_tail : opt_else
| kELSIF expr then | kELSIF expr then
@ -1405,19 +1399,6 @@ brace_block : '{'
fixpos($$, $4); fixpos($$, $4);
dyna_pop($<vars>2); dyna_pop($<vars>2);
} }
| kDO2
{
$<vars>$ = dyna_push();
}
opt_block_var
compstmt
kEND
{
$$ = NEW_ITER($3, 0, $4);
fixpos($$, $4);
dyna_pop($<vars>2);
}
generic_call : tIDENTIFIER generic_call : tIDENTIFIER
{ {
@ -1434,6 +1415,7 @@ generic_call : tIDENTIFIER
| method_call | method_call
| command_call | command_call
block_call : generic_call do_block block_call : generic_call do_block
{ {
if ($1 && nd_type($1) == NODE_BLOCK_PASS) { if ($1 && nd_type($1) == NODE_BLOCK_PASS) {
@ -1443,6 +1425,26 @@ block_call : generic_call do_block
$$ = $2; $$ = $2;
fixpos($$, $2); fixpos($$, $2);
} }
| block_call '.' operation2
{
value_expr($1);
$$ = new_call($1, $3, 0);
}
| block_call '.' operation2 '(' opt_call_args close_paren
{
value_expr($1);
$$ = new_call($1, $3, $5);
}
| block_call tCOLON2 operation2
{
value_expr($1);
$$ = new_call($1, $3, 0);
}
| block_call tCOLON2 operation2 '(' opt_call_args close_paren
{
value_expr($1);
$$ = new_call($1, $3, $5);
}
method_call : operation '(' opt_call_args close_paren method_call : operation '(' opt_call_args close_paren
{ {
@ -1492,9 +1494,6 @@ close_paren : ')'
if (!COND_P()) lex_state = EXPR_PAREN; if (!COND_P()) lex_state = EXPR_PAREN;
} }
stmt_rhs : block_call
| command_call
case_body : kWHEN when_args then case_body : kWHEN when_args then
compstmt compstmt
cases cases
@ -3617,7 +3616,7 @@ yylex()
if (state == EXPR_FNAME) { if (state == EXPR_FNAME) {
yylval.id = rb_intern(kw->name); yylval.id = rb_intern(kw->name);
} }
if (kw->id[0] == kDO && !COND_P() && state == EXPR_PAREN) { if (kw->id[0] == kDO && COND_P()) {
return kDO2; return kDO2;
} }
return kw->id[state != EXPR_BEG]; return kw->id[state != EXPR_BEG];