* eval.c (rb_require_safe): preserve old ruby_errinfo.

[ruby-talk:95409]

* eval.c (rb_f_raise): should not clear backtrace information if
  exception object already have one.

* parse.y (assoc_list): allow {sym: val} style Hash. [Ruby2]
  this change is done by Nobuyoshi Nakada <nobu@ruby-lang.org>.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5987 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2004-03-20 16:45:41 +00:00
Родитель 38fc76574a
Коммит aab1ba1365
6 изменённых файлов: 59 добавлений и 22 удалений

Просмотреть файл

@ -1,3 +1,11 @@
Sat Mar 20 23:51:03 2004 WATANABE Hirofumi <eban@ruby-lang.org>
* eval.c (rb_require_safe): preserve old ruby_errinfo.
[ruby-talk:95409]
* eval.c (rb_f_raise): should not clear backtrace information if
exception object already have one.
Sat Mar 20 21:21:03 2004 WATANABE Hirofumi <eban@ruby-lang.org> Sat Mar 20 21:21:03 2004 WATANABE Hirofumi <eban@ruby-lang.org>
* ext/extmk.rb: rm -rf $extout, not extout. * ext/extmk.rb: rm -rf $extout, not extout.
@ -12,6 +20,11 @@ Sat Mar 20 09:33:36 2004 Tadayoshi Funaba <tadf@dotrb.org>
* lib/date.rb, lib/date/format.rb: _parse() now accepts fractional * lib/date.rb, lib/date/format.rb: _parse() now accepts fractional
part of second minute that follows a comma or a full stop. part of second minute that follows a comma or a full stop.
Fri Mar 19 21:06:21 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* parse.y (assoc_list): allow {sym: val} style Hash. [Ruby2]
this change is done by Nobuyoshi Nakada <nobu@ruby-lang.org>.
Fri Mar 19 15:15:15 2004 Yukihiro Matsumoto <matz@ruby-lang.org> Fri Mar 19 15:15:15 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* variable.c (rb_cvar_set): class variables become private to the * variable.c (rb_cvar_set): class variables become private to the

Просмотреть файл

@ -213,6 +213,13 @@ to_ary(ary)
return rb_convert_type(ary, T_ARRAY, "Array", "to_ary"); return rb_convert_type(ary, T_ARRAY, "Array", "to_ary");
} }
static VALUE
to_a(ary)
VALUE ary;
{
return rb_convert_type(ary, T_ARRAY, "Array", "to_a");
}
VALUE VALUE
rb_check_array_type(ary) rb_check_array_type(ary)
VALUE ary; VALUE ary;
@ -2025,7 +2032,7 @@ rb_ary_zip(argc, argv, ary)
VALUE result; VALUE result;
for (i=0; i<argc; i++) { for (i=0; i<argc; i++) {
argv[i] = to_ary(argv[i]); argv[i] = to_a(argv[i]);
} }
if (rb_block_given_p()) { if (rb_block_given_p()) {
for (i=0; i<RARRAY(ary)->len; i++) { for (i=0; i<RARRAY(ary)->len; i++) {

10
eval.c
Просмотреть файл

@ -4410,7 +4410,8 @@ rb_f_raise(argc, argv)
if (argc > 0) { if (argc > 0) {
if (!rb_obj_is_kind_of(mesg, rb_eException)) if (!rb_obj_is_kind_of(mesg, rb_eException))
rb_raise(rb_eTypeError, "exception object expected"); rb_raise(rb_eTypeError, "exception object expected");
set_backtrace(mesg, (argc>2)?argv[2]:Qnil); if (argc>2)
set_backtrace(mesg, argv[2]);
} }
if (ruby_frame != top_frame) { if (ruby_frame != top_frame) {
@ -5549,7 +5550,7 @@ rb_call0(klass, recv, id, oid, argc, argv, body, nosuper)
rb_raise(rb_eArgError, "wrong number of arguments(%d for %d)", rb_raise(rb_eArgError, "wrong number of arguments(%d for %d)",
argc, i); argc, i);
} }
if (node->nd_rest == -1) { if ((int)node->nd_rest == -1) {
int opt = i; int opt = i;
NODE *optnode = node->nd_opt; NODE *optnode = node->nd_opt;
@ -5584,7 +5585,7 @@ rb_call0(klass, recv, id, oid, argc, argv, body, nosuper)
} }
} }
local_vars = ruby_scope->local_vars; local_vars = ruby_scope->local_vars;
if (node->nd_rest >= 0) { if ((int)node->nd_rest >= 0) {
VALUE v; VALUE v;
if (argc > 0) if (argc > 0)
@ -6705,6 +6706,7 @@ rb_require_safe(fname, safe)
int safe; int safe;
{ {
VALUE result = Qnil; VALUE result = Qnil;
volatile VALUE errinfo = ruby_errinfo;
int state; int state;
struct { struct {
NODE *node; NODE *node;
@ -6782,7 +6784,7 @@ rb_require_safe(fname, safe)
if (NIL_P(result)) { if (NIL_P(result)) {
load_failed(fname); load_failed(fname);
} }
ruby_errinfo = Qnil; ruby_errinfo = errinfo;
return result; return result;
} }

Просмотреть файл

@ -417,7 +417,7 @@ class OptionParser
yield(indent + l) yield(indent + l)
end end
while (l = left.shift; r = right.shift; l or r) while begin l = left.shift; r = right.shift; l or r end
l = l.to_s.ljust(width) + ' ' + r if r and !r.empty? l = l.to_s.ljust(width) + ' ' + r if r and !r.empty?
yield(indent + l) yield(indent + l)
end end

45
parse.y
Просмотреть файл

@ -74,6 +74,7 @@ static enum lex_state {
EXPR_FNAME, /* ignore newline, no reserved words. */ EXPR_FNAME, /* ignore newline, no reserved words. */
EXPR_DOT, /* right after `.' or `::', no reserved words. */ EXPR_DOT, /* right after `.' or `::', no reserved words. */
EXPR_CLASS, /* immediate after `class', no here document. */ EXPR_CLASS, /* immediate after `class', no here document. */
EXPR_TERNARY, /* alike EXPR_BEG but immediate after ternary op. */
} lex_state; } lex_state;
static NODE *lex_strterm; static NODE *lex_strterm;
@ -244,7 +245,7 @@ static void top_local_setup();
k__LINE__ k__LINE__
k__FILE__ k__FILE__
%token <id> tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR %token <id> tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR tLABEL
%token <node> tINTEGER tFLOAT tSTRING_CONTENT %token <node> tINTEGER tFLOAT tSTRING_CONTENT
%token <node> tNTH_REF tBACK_REF %token <node> tNTH_REF tBACK_REF
%token <num> tREGEXP_END %token <num> tREGEXP_END
@ -2380,6 +2381,10 @@ assoc_list : none
} }
$$ = $1; $$ = $1;
} }
| tLABEL arg_value
{
$$ = list_append(NEW_LIST(NEW_LIT(ID2SYM($1))), $2);
}
; ;
assocs : assoc assocs : assoc
@ -3305,6 +3310,7 @@ arg_ambiguous()
} }
#define IS_ARG() (lex_state == EXPR_ARG || lex_state == EXPR_CMDARG) #define IS_ARG() (lex_state == EXPR_ARG || lex_state == EXPR_CMDARG)
#define IS_BEG() (lex_state == EXPR_BEG || lex_state == EXPR_MID || lex_state == EXPR_TERNARY)
static int static int
yylex() yylex()
@ -3360,6 +3366,7 @@ yylex()
case EXPR_FNAME: case EXPR_FNAME:
case EXPR_DOT: case EXPR_DOT:
case EXPR_CLASS: case EXPR_CLASS:
case EXPR_TERNARY:
goto retry; goto retry;
default: default:
break; break;
@ -3389,7 +3396,7 @@ yylex()
rb_warning("`*' interpreted as argument prefix"); rb_warning("`*' interpreted as argument prefix");
c = tSTAR; c = tSTAR;
} }
else if (lex_state == EXPR_BEG || lex_state == EXPR_MID) { else if (IS_BEG()) {
c = tSTAR; c = tSTAR;
} }
else { else {
@ -3542,7 +3549,7 @@ yylex()
case '?': case '?':
if (lex_state == EXPR_END || lex_state == EXPR_ENDARG) { if (lex_state == EXPR_END || lex_state == EXPR_ENDARG) {
lex_state = EXPR_BEG; lex_state = EXPR_TERNARY;
return '?'; return '?';
} }
c = nextc(); c = nextc();
@ -3579,7 +3586,7 @@ yylex()
} }
ternary: ternary:
pushback(c); pushback(c);
lex_state = EXPR_BEG; lex_state = EXPR_TERNARY;
return '?'; return '?';
} }
else if (ismbchar(c)) { else if (ismbchar(c)) {
@ -3618,7 +3625,7 @@ yylex()
rb_warning("`&' interpreted as argument prefix"); rb_warning("`&' interpreted as argument prefix");
c = tAMPER; c = tAMPER;
} }
else if (lex_state == EXPR_BEG || lex_state == EXPR_MID) { else if (IS_BEG()) {
c = tAMPER; c = tAMPER;
} }
else { else {
@ -3672,7 +3679,7 @@ yylex()
lex_state = EXPR_BEG; lex_state = EXPR_BEG;
return tOP_ASGN; return tOP_ASGN;
} }
if (lex_state == EXPR_BEG || lex_state == EXPR_MID || if (IS_BEG() ||
(IS_ARG() && space_seen && !ISSPACE(c))) { (IS_ARG() && space_seen && !ISSPACE(c))) {
if (IS_ARG()) arg_ambiguous(); if (IS_ARG()) arg_ambiguous();
lex_state = EXPR_BEG; lex_state = EXPR_BEG;
@ -3702,7 +3709,7 @@ yylex()
lex_state = EXPR_BEG; lex_state = EXPR_BEG;
return tOP_ASGN; return tOP_ASGN;
} }
if (lex_state == EXPR_BEG || lex_state == EXPR_MID || if (IS_BEG() ||
(IS_ARG() && space_seen && !ISSPACE(c))) { (IS_ARG() && space_seen && !ISSPACE(c))) {
if (IS_ARG()) arg_ambiguous(); if (IS_ARG()) arg_ambiguous();
lex_state = EXPR_BEG; lex_state = EXPR_BEG;
@ -3961,7 +3968,7 @@ yylex()
case ':': case ':':
c = nextc(); c = nextc();
if (c == ':') { if (c == ':') {
if (lex_state == EXPR_BEG || lex_state == EXPR_MID || if (IS_BEG() ||
lex_state == EXPR_CLASS || (IS_ARG() && space_seen)) { lex_state == EXPR_CLASS || (IS_ARG() && space_seen)) {
lex_state = EXPR_BEG; lex_state = EXPR_BEG;
return tCOLON3; return tCOLON3;
@ -3989,7 +3996,7 @@ yylex()
return tSYMBEG; return tSYMBEG;
case '/': case '/':
if (lex_state == EXPR_BEG || lex_state == EXPR_MID) { if (IS_BEG()) {
lex_strterm = NEW_STRTERM(str_regexp, '/', 0); lex_strterm = NEW_STRTERM(str_regexp, '/', 0);
return tREGEXP_BEG; return tREGEXP_BEG;
} }
@ -4051,7 +4058,7 @@ yylex()
case '(': case '(':
command_start = Qtrue; command_start = Qtrue;
if (lex_state == EXPR_BEG || lex_state == EXPR_MID) { if (IS_BEG()) {
c = tLPAREN; c = tLPAREN;
} }
else if (space_seen) { else if (space_seen) {
@ -4081,7 +4088,7 @@ yylex()
pushback(c); pushback(c);
return '['; return '[';
} }
else if (lex_state == EXPR_BEG || lex_state == EXPR_MID) { else if (IS_BEG()) {
c = tLBRACK; c = tLBRACK;
} }
else if (IS_ARG() && space_seen) { else if (IS_ARG() && space_seen) {
@ -4114,7 +4121,7 @@ yylex()
return '\\'; return '\\';
case '%': case '%':
if (lex_state == EXPR_BEG || lex_state == EXPR_MID) { if (IS_BEG()) {
int term; int term;
int paren; int paren;
@ -4400,7 +4407,7 @@ yylex()
return kDO_BLOCK; return kDO_BLOCK;
return kDO; return kDO;
} }
if (state == EXPR_BEG) if (state == EXPR_BEG || state == EXPR_TERNARY)
return kw->id[0]; return kw->id[0];
else { else {
if (kw->id[0] != kw->id[1]) if (kw->id[0] != kw->id[1])
@ -4411,10 +4418,18 @@ yylex()
} }
if (lex_state == EXPR_BEG || if (lex_state == EXPR_BEG ||
lex_state == EXPR_MID ||
lex_state == EXPR_DOT ||
lex_state == EXPR_ARG || lex_state == EXPR_ARG ||
lex_state == EXPR_CMDARG) { lex_state == EXPR_CMDARG) {
if (peek(':') && !(lex_p + 1 < lex_pend && lex_p[1] == ':')) {
lex_state = EXPR_BEG;
nextc();
yylval.id = rb_intern(tok());
return tLABEL;
}
}
if (IS_BEG() ||
lex_state == EXPR_DOT ||
IS_ARG()) {
if (cmd_state) { if (cmd_state) {
lex_state = EXPR_CMDARG; lex_state = EXPR_CMDARG;
} }

Просмотреть файл

@ -79,7 +79,7 @@ ARGV.options do
end end
pp self pp self
(print ARGV.options; exit) if @quit begin print ARGV.options; exit end if @quit
ARGV.options = nil # no more parse ARGV.options = nil # no more parse
puts "ARGV = #{ARGV.join(' ')}" if !ARGV.empty? puts "ARGV = #{ARGV.join(' ')}" if !ARGV.empty?
#opts.variable.each {|sym| puts "#{sym} = #{opts.send(sym).inspect}"} #opts.variable.each {|sym| puts "#{sym} = #{opts.send(sym).inspect}"}