mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* parse.y: clarify do ambiguity, bit more complex but natural
from my point of view. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1151 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
74273daffb
commit
161e3313d2
3 changed files with 78 additions and 55 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Fri Jan 26 01:42:40 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* parse.y: clarify do ambiguity, bit more complex but natural
|
||||||
|
from my point of view.
|
||||||
|
|
||||||
Wed Jan 24 14:58:08 2001 Akinori MUSHA <knu@ruby-lang.org>
|
Wed Jan 24 14:58:08 2001 Akinori MUSHA <knu@ruby-lang.org>
|
||||||
|
|
||||||
* lib/cgi.rb: fix the problem that when running under mod_ruby
|
* lib/cgi.rb: fix the problem that when running under mod_ruby
|
||||||
|
|
|
@ -15,7 +15,9 @@ class Tempfile < SimpleDelegator
|
||||||
Max_try = 10
|
Max_try = 10
|
||||||
|
|
||||||
def Tempfile.callback(path, data)
|
def Tempfile.callback(path, data)
|
||||||
|
pid = $$
|
||||||
lambda{
|
lambda{
|
||||||
|
if pid == $$
|
||||||
print "removing ", path, "..." if $DEBUG
|
print "removing ", path, "..." if $DEBUG
|
||||||
data[0].close if data[0]
|
data[0].close if data[0]
|
||||||
if File.exist?(path)
|
if File.exist?(path)
|
||||||
|
@ -25,6 +27,7 @@ class Tempfile < SimpleDelegator
|
||||||
Dir.rmdir(path + '.lock')
|
Dir.rmdir(path + '.lock')
|
||||||
end
|
end
|
||||||
print "done\n" if $DEBUG
|
print "done\n" if $DEBUG
|
||||||
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
109
parse.y
109
parse.y
|
@ -68,6 +68,18 @@ static unsigned long cond_stack = 0;
|
||||||
} while (0)
|
} while (0)
|
||||||
#define COND_P() (cond_nest > 0 && (cond_stack&1))
|
#define COND_P() (cond_nest > 0 && (cond_stack&1))
|
||||||
|
|
||||||
|
static int cmdarg_nest = 0;
|
||||||
|
static unsigned long cmdarg_stack = 0;
|
||||||
|
#define CMDARG_PUSH do {\
|
||||||
|
cmdarg_nest++;\
|
||||||
|
cmdarg_stack = (cmdarg_stack<<1)|1;\
|
||||||
|
} while(0)
|
||||||
|
#define CMDARG_POP do {\
|
||||||
|
cmdarg_nest--;\
|
||||||
|
cmdarg_stack >>= 1;\
|
||||||
|
} while (0)
|
||||||
|
#define CMDARG_P() (cmdarg_nest > 0 && (cmdarg_stack&1))
|
||||||
|
|
||||||
static int class_nest = 0;
|
static int class_nest = 0;
|
||||||
static int in_single = 0;
|
static int in_single = 0;
|
||||||
static int compile_for_eval = 0;
|
static int compile_for_eval = 0;
|
||||||
|
@ -154,7 +166,8 @@ static void top_local_setup();
|
||||||
kRETRY
|
kRETRY
|
||||||
kIN
|
kIN
|
||||||
kDO
|
kDO
|
||||||
kDO2
|
kDO_COND
|
||||||
|
kDO_BLOCK
|
||||||
kRETURN
|
kRETURN
|
||||||
kYIELD
|
kYIELD
|
||||||
kSUPER
|
kSUPER
|
||||||
|
@ -186,8 +199,8 @@ static void top_local_setup();
|
||||||
%type <node> compstmt stmts stmt expr arg primary command 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> args ret_args when_args call_args paren_args opt_paren_args
|
%type <node> args ret_args when_args call_args paren_args opt_paren_args
|
||||||
%type <node> aref_args opt_block_arg block_arg var_ref
|
%type <node> command_args aref_args opt_block_arg block_arg var_ref
|
||||||
%type <node> mrhs mrhs_basic superclass generic_call block_call call_block
|
%type <node> mrhs mrhs_basic superclass block_call block_command
|
||||||
%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
|
||||||
|
@ -444,38 +457,38 @@ expr : mlhs '=' mrhs
|
||||||
| arg
|
| arg
|
||||||
|
|
||||||
command_call : command
|
command_call : command
|
||||||
| block_call
|
| block_command
|
||||||
|
|
||||||
block_call : call_block
|
block_command : block_call
|
||||||
| call_block '.' operation2 call_args
|
| block_call '.' operation2 command_args
|
||||||
{
|
{
|
||||||
value_expr($1);
|
value_expr($1);
|
||||||
$$ = new_call($1, $3, $4);
|
$$ = new_call($1, $3, $4);
|
||||||
}
|
}
|
||||||
| call_block tCOLON2 operation2 call_args
|
| block_call tCOLON2 operation2 command_args
|
||||||
{
|
{
|
||||||
value_expr($1);
|
value_expr($1);
|
||||||
$$ = new_call($1, $3, $4);
|
$$ = new_call($1, $3, $4);
|
||||||
}
|
}
|
||||||
|
|
||||||
command : operation call_args
|
command : operation command_args
|
||||||
{
|
{
|
||||||
$$ = new_fcall($1, $2);
|
$$ = new_fcall($1, $2);
|
||||||
fixpos($$, $2);
|
fixpos($$, $2);
|
||||||
}
|
}
|
||||||
| primary '.' operation2 call_args
|
| primary '.' operation2 command_args
|
||||||
{
|
{
|
||||||
value_expr($1);
|
value_expr($1);
|
||||||
$$ = new_call($1, $3, $4);
|
$$ = new_call($1, $3, $4);
|
||||||
fixpos($$, $1);
|
fixpos($$, $1);
|
||||||
}
|
}
|
||||||
| primary tCOLON2 operation2 call_args
|
| primary tCOLON2 operation2 command_args
|
||||||
{
|
{
|
||||||
value_expr($1);
|
value_expr($1);
|
||||||
$$ = new_call($1, $3, $4);
|
$$ = new_call($1, $3, $4);
|
||||||
fixpos($$, $1);
|
fixpos($$, $1);
|
||||||
}
|
}
|
||||||
| kSUPER call_args
|
| kSUPER command_args
|
||||||
{
|
{
|
||||||
if (!compile_for_eval && !cur_mid && !in_single)
|
if (!compile_for_eval && !cur_mid && !in_single)
|
||||||
yyerror("super called outside of method");
|
yyerror("super called outside of method");
|
||||||
|
@ -488,7 +501,6 @@ command : operation call_args
|
||||||
fixpos($$, $2);
|
fixpos($$, $2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mlhs : mlhs_basic
|
mlhs : mlhs_basic
|
||||||
| tLPAREN mlhs_entry ')'
|
| tLPAREN mlhs_entry ')'
|
||||||
{
|
{
|
||||||
|
@ -996,6 +1008,12 @@ call_args : command
|
||||||
}
|
}
|
||||||
| block_arg
|
| block_arg
|
||||||
|
|
||||||
|
command_args : {CMDARG_PUSH;} call_args
|
||||||
|
{
|
||||||
|
CMDARG_POP;
|
||||||
|
$$ = $2;
|
||||||
|
}
|
||||||
|
|
||||||
block_arg : tAMPER arg
|
block_arg : tAMPER arg
|
||||||
{
|
{
|
||||||
value_expr($2);
|
value_expr($2);
|
||||||
|
@ -1347,7 +1365,7 @@ then : term
|
||||||
| term kTHEN
|
| term kTHEN
|
||||||
|
|
||||||
do : term
|
do : term
|
||||||
| kDO2
|
| kDO_COND
|
||||||
|
|
||||||
if_tail : opt_else
|
if_tail : opt_else
|
||||||
| kELSIF expr then
|
| kELSIF expr then
|
||||||
|
@ -1383,7 +1401,7 @@ opt_block_var : none
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
do_block : kDO
|
do_block : kDO_BLOCK
|
||||||
{
|
{
|
||||||
$<vars>$ = dyna_push();
|
$<vars>$ = dyna_push();
|
||||||
}
|
}
|
||||||
|
@ -1396,35 +1414,7 @@ do_block : kDO
|
||||||
dyna_pop($<vars>2);
|
dyna_pop($<vars>2);
|
||||||
}
|
}
|
||||||
|
|
||||||
brace_block : '{'
|
block_call : command do_block
|
||||||
{
|
|
||||||
$<vars>$ = dyna_push();
|
|
||||||
}
|
|
||||||
opt_block_var
|
|
||||||
compstmt '}'
|
|
||||||
{
|
|
||||||
$$ = NEW_ITER($3, 0, $4);
|
|
||||||
fixpos($$, $4);
|
|
||||||
dyna_pop($<vars>2);
|
|
||||||
}
|
|
||||||
|
|
||||||
generic_call : tIDENTIFIER
|
|
||||||
{
|
|
||||||
$$ = NEW_VCALL($1);
|
|
||||||
}
|
|
||||||
| tCONSTANT
|
|
||||||
{
|
|
||||||
$$ = NEW_VCALL($1);
|
|
||||||
}
|
|
||||||
| tFID
|
|
||||||
{
|
|
||||||
$$ = NEW_VCALL($1);
|
|
||||||
}
|
|
||||||
| method_call
|
|
||||||
| command_call
|
|
||||||
|
|
||||||
|
|
||||||
call_block : generic_call do_block
|
|
||||||
{
|
{
|
||||||
if ($1 && nd_type($1) == NODE_BLOCK_PASS) {
|
if ($1 && nd_type($1) == NODE_BLOCK_PASS) {
|
||||||
rb_compile_error("both block arg and actual block given");
|
rb_compile_error("both block arg and actual block given");
|
||||||
|
@ -1433,12 +1423,12 @@ call_block : generic_call do_block
|
||||||
$$ = $2;
|
$$ = $2;
|
||||||
fixpos($$, $2);
|
fixpos($$, $2);
|
||||||
}
|
}
|
||||||
| call_block '.' operation2 opt_paren_args
|
| block_call '.' operation2 opt_paren_args
|
||||||
{
|
{
|
||||||
value_expr($1);
|
value_expr($1);
|
||||||
$$ = new_call($1, $3, $4);
|
$$ = new_call($1, $3, $4);
|
||||||
}
|
}
|
||||||
| call_block tCOLON2 operation2 opt_paren_args
|
| block_call tCOLON2 operation2 opt_paren_args
|
||||||
{
|
{
|
||||||
value_expr($1);
|
value_expr($1);
|
||||||
$$ = new_call($1, $3, $4);
|
$$ = new_call($1, $3, $4);
|
||||||
|
@ -1481,6 +1471,29 @@ method_call : operation paren_args
|
||||||
$$ = NEW_ZSUPER();
|
$$ = NEW_ZSUPER();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
brace_block : '{'
|
||||||
|
{
|
||||||
|
$<vars>$ = dyna_push();
|
||||||
|
}
|
||||||
|
opt_block_var
|
||||||
|
compstmt '}'
|
||||||
|
{
|
||||||
|
$$ = NEW_ITER($3, 0, $4);
|
||||||
|
fixpos($$, $4);
|
||||||
|
dyna_pop($<vars>2);
|
||||||
|
}
|
||||||
|
| kDO
|
||||||
|
{
|
||||||
|
$<vars>$ = dyna_push();
|
||||||
|
}
|
||||||
|
opt_block_var
|
||||||
|
compstmt kEND
|
||||||
|
{
|
||||||
|
$$ = NEW_ITER($3, 0, $4);
|
||||||
|
fixpos($$, $4);
|
||||||
|
dyna_pop($<vars>2);
|
||||||
|
}
|
||||||
|
|
||||||
case_body : kWHEN when_args then
|
case_body : kWHEN when_args then
|
||||||
compstmt
|
compstmt
|
||||||
cases
|
cases
|
||||||
|
@ -3599,8 +3612,10 @@ 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()) {
|
if (kw->id[0] == kDO) {
|
||||||
return kDO2;
|
if (COND_P()) return kDO_COND;
|
||||||
|
if (CMDARG_P()) return kDO_BLOCK;
|
||||||
|
return kDO;
|
||||||
}
|
}
|
||||||
return kw->id[state != EXPR_BEG];
|
return kw->id[state != EXPR_BEG];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue