diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-02-13 09:40:29 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-02-13 09:40:29 +0000 |
commit | 1b7f82e62577986a6122ef453323ace74980d91e (patch) | |
tree | 3518499de338e8c28ec5daaa1396b381e9676e66 | |
parent | 00080ffcbb05cf23bce8e31f0538567f5b780f89 (diff) |
\s and assignment in conditional
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@72 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | lib/thread.rb | 8 | ||||
-rw-r--r-- | lib/tk.rb | 2 | ||||
-rw-r--r-- | numeric.c | 6 | ||||
-rw-r--r-- | parse.y | 61 | ||||
-rw-r--r-- | sample/test.rb | 8 |
6 files changed, 69 insertions, 22 deletions
@@ -1,3 +1,9 @@ +Fri Feb 13 08:16:11 1998 Yukihiro Matsumoto <matz@netlab.co.jp> + + * parse.y (parse_regx): handle \s before read_escape(). + + * parse.y (read_escape): `\s' in strings as space. + Tue Feb 10 17:29:08 1998 Yukihiro Matsumoto <matz@netlab.co.jp> * version 1.1b7 released. diff --git a/lib/thread.rb b/lib/thread.rb index 8f7f6cdd6a..c47d7b20a4 100644 --- a/lib/thread.rb +++ b/lib/thread.rb @@ -69,6 +69,10 @@ class Mutex unlock end end + + def num_waiting + @waiting.size + end end class Queue @@ -137,4 +141,8 @@ class SizedQueue<Queue pop = super pop end + + def num_waiting + @waiting.size + @queue_wait.size + end end @@ -26,7 +26,7 @@ module TkComm private :error_at def tk_tcl2ruby(val) - if val.include? ? + if val.include? ?\s return val.split.collect{|v| tk_tcl2ruby(v)} end case val @@ -49,7 +49,7 @@ coerce_body(x) coerce_rescue(x) VALUE *x; { - TypeError("%s can't convert into %s", + TypeError("%s can't be coerced into %s", rb_class2name(CLASS_OF(x[1])), rb_class2name(CLASS_OF(x[0]))); } @@ -59,14 +59,10 @@ do_coerce(x, y) VALUE *x, *y; { VALUE ary; -#if 0 VALUE a[2]; a[0] = *x; a[1] = *y; ary = rb_rescue(coerce_body, a, coerce_rescue, a); -#else - ary = rb_funcall(*y, coerce, 1, *x); -#endif if (TYPE(ary) != T_ARRAY || RARRAY(ary)->len != 2) { TypeError("coerce must return [x, y]"); } @@ -1684,6 +1684,9 @@ read_escape() case 'b': /* backspace */ return '\b'; + case 's': /* space */ + return ' '; + case 'M': if ((c = nextc()) != '-') { yyerror("Invalid escape character syntax"); @@ -1767,8 +1770,10 @@ parse_regx(term) break; case '\\': + case '^': /* no \^ escape in regexp */ + case 's': tokadd('\\'); - tokadd('\\'); + tokadd(c); break; case '1': case '2': case '3': @@ -1779,11 +1784,6 @@ parse_regx(term) tokadd(c); break; - case '^': /* no \^ escape in regexp */ - tokadd('\\'); - tokadd('^'); - break; - case 'b': if (!in_brack) { tokadd('\\'); @@ -2317,7 +2317,7 @@ retry: return '?'; } c = nextc(); - if (lex_state == EXPR_ARG && space_seen && isspace(c)){ + if (lex_state == EXPR_ARG && isspace(c)){ pushback(c); arg_ambiguous(); lex_state = EXPR_BEG; @@ -3459,28 +3459,57 @@ cond0(node) } } -static NODE* -cond(node) +int +assign_in_cond(node) NODE *node; { - enum node_type type = nd_type(node); - - switch (type) { + switch (nd_type(node)) { case NODE_MASGN: + Error("multiple assignment in conditional"); + return 0; + case NODE_LASGN: case NODE_DASGN: case NODE_GASGN: case NODE_IASGN: case NODE_CASGN: + break; + default: + return 1; + } + + switch (nd_type(node->nd_value)) { + case NODE_LIT: + case NODE_STR: + case NODE_DSTR: + case NODE_XSTR: + case NODE_DXSTR: + case NODE_EVSTR: + case NODE_DREGX: + case NODE_NIL: + case NODE_TRUE: + case NODE_FALSE: + Error("found = in conditional, should be =="); + return 0; + + default: Warning("assignment in condition"); break; - case NODE_NEWLINE: + } + if (assign_in_cond(node->nd_value)) return 1; +} + +static NODE* +cond(node) + NODE *node; +{ + enum node_type type = nd_type(node); + + if (assign_in_cond(node) == 0) return 0; + if (nd_type(node) == NODE_NEWLINE){ node->nd_next = cond0(node->nd_next); return node; - default: - break; } - return cond0(node); } diff --git a/sample/test.rb b/sample/test.rb index 52e936af71..e413ada27a 100644 --- a/sample/test.rb +++ b/sample/test.rb @@ -766,6 +766,14 @@ ok(done) File.unlink "script_tmp" or `/bin/rm -f "script_tmp"` File.unlink "script_tmp.bak" or `/bin/rm -f "script_tmp.bak"` +$bad = false +for script in Dir["{lib,sample}/*.rb"] + unless `./ruby -c #{script}` == "Syntax OK\n" + $bad = true + end +end +ok(!$bad) + check "const" TEST1 = 1 TEST2 = 2 |