diff --git a/ChangeLog b/ChangeLog index 31acf39615..dffa9dee93 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Sat Mar 20 23:51:03 2004 WATANABE Hirofumi + + * 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 * ext/extmk.rb: rm -rf $extout, not extout. @@ -12,6 +20,11 @@ Sat Mar 20 09:33:36 2004 Tadayoshi Funaba * 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 + + * parse.y (assoc_list): allow {sym: val} style Hash. [Ruby2] + this change is done by Nobuyoshi Nakada . + Fri Mar 19 15:15:15 2004 Yukihiro Matsumoto * variable.c (rb_cvar_set): class variables become private to the diff --git a/array.c b/array.c index 058b669a8c..0f3fc1b202 100644 --- a/array.c +++ b/array.c @@ -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; ilen; i++) { diff --git a/eval.c b/eval.c index 45dc8320d5..f2d8c9b667 100644 --- a/eval.c +++ b/eval.c @@ -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; } diff --git a/lib/optparse.rb b/lib/optparse.rb index 1b083b8e6e..4a979a78d1 100644 --- a/lib/optparse.rb +++ b/lib/optparse.rb @@ -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 diff --git a/parse.y b/parse.y index 471c8a8d2f..1408622cf5 100644 --- a/parse.y +++ b/parse.y @@ -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 tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR +%token tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR tLABEL %token tINTEGER tFLOAT tSTRING_CONTENT %token tNTH_REF tBACK_REF %token 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; } diff --git a/sample/optparse/opttest.rb b/sample/optparse/opttest.rb index 61b157bce5..683c450d57 100644 --- a/sample/optparse/opttest.rb +++ b/sample/optparse/opttest.rb @@ -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}"}