mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
\s and assignment in conditional
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@72 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
00080ffcbb
commit
1b7f82e625
6 changed files with 73 additions and 26 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.
|
||||
|
|
|
|||
|
|
@ -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]");
|
||||
}
|
||||
|
|
|
|||
69
parse.y
69
parse.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)
|
|||
}
|
||||
}
|
||||
|
||||
int
|
||||
assign_in_cond(node)
|
||||
NODE *node;
|
||||
{
|
||||
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;
|
||||
}
|
||||
if (assign_in_cond(node->nd_value)) return 1;
|
||||
}
|
||||
|
||||
static NODE*
|
||||
cond(node)
|
||||
NODE *node;
|
||||
{
|
||||
enum node_type type = nd_type(node);
|
||||
|
||||
switch (type) {
|
||||
case NODE_MASGN:
|
||||
case NODE_LASGN:
|
||||
case NODE_DASGN:
|
||||
case NODE_GASGN:
|
||||
case NODE_IASGN:
|
||||
case NODE_CASGN:
|
||||
Warning("assignment in condition");
|
||||
break;
|
||||
case NODE_NEWLINE:
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue