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

* 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
parent 38fc76574a
commit aab1ba1365
6 changed files with 59 additions and 22 deletions

View file

@ -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>
* 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
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>
* variable.c (rb_cvar_set): class variables become private to the

View file

@ -213,6 +213,13 @@ to_ary(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
rb_check_array_type(ary)
VALUE ary;
@ -2025,7 +2032,7 @@ rb_ary_zip(argc, argv, ary)
VALUE result;
for (i=0; i<argc; i++) {
argv[i] = to_ary(argv[i]);
argv[i] = to_a(argv[i]);
}
if (rb_block_given_p()) {
for (i=0; i<RARRAY(ary)->len; i++) {

10
eval.c
View file

@ -4410,7 +4410,8 @@ rb_f_raise(argc, argv)
if (argc > 0) {
if (!rb_obj_is_kind_of(mesg, rb_eException))
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) {
@ -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)",
argc, i);
}
if (node->nd_rest == -1) {
if ((int)node->nd_rest == -1) {
int opt = i;
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;
if (node->nd_rest >= 0) {
if ((int)node->nd_rest >= 0) {
VALUE v;
if (argc > 0)
@ -6705,6 +6706,7 @@ rb_require_safe(fname, safe)
int safe;
{
VALUE result = Qnil;
volatile VALUE errinfo = ruby_errinfo;
int state;
struct {
NODE *node;
@ -6782,7 +6784,7 @@ rb_require_safe(fname, safe)
if (NIL_P(result)) {
load_failed(fname);
}
ruby_errinfo = Qnil;
ruby_errinfo = errinfo;
return result;
}

View file

@ -417,7 +417,7 @@ class OptionParser
yield(indent + l)
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?
yield(indent + l)
end

45
parse.y
View file

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

View file

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