Raise SyntaxError for syntax errors detected in this phase.

This commit is contained in:
Guido van Rossum 1992-01-26 18:12:03 +00:00
parent bd7fd1a225
commit 598fd8c980

View file

@ -156,7 +156,7 @@ block_push(c, type)
int type; int type;
{ {
if (c->c_nblocks >= MAXBLOCKS) { if (c->c_nblocks >= MAXBLOCKS) {
err_setstr(TypeError, "too many statically nested blocks"); err_setstr(SystemError, "too many statically nested blocks");
c->c_errors++; c->c_errors++;
} }
else { else {
@ -1126,7 +1126,7 @@ com_assign_trailer(c, n, assigning)
REQ(n, trailer); REQ(n, trailer);
switch (TYPE(CHILD(n, 0))) { switch (TYPE(CHILD(n, 0))) {
case LPAR: /* '(' [exprlist] ')' */ case LPAR: /* '(' [exprlist] ')' */
err_setstr(TypeError, "can't assign to function call"); err_setstr(SyntaxError, "can't assign to function call");
c->c_errors++; c->c_errors++;
break; break;
case DOT: /* '.' NAME */ case DOT: /* '.' NAME */
@ -1141,7 +1141,7 @@ com_assign_trailer(c, n, assigning)
com_assign_subscript(c, CHILD(n, 0), assigning); com_assign_subscript(c, CHILD(n, 0), assigning);
break; break;
default: default:
err_setstr(TypeError, "unknown trailer type"); err_setstr(SystemError, "unknown trailer type");
c->c_errors++; c->c_errors++;
} }
} }
@ -1214,7 +1214,7 @@ com_assign(c, n, assigning)
case arith_expr: case arith_expr:
case term: case term:
if (NCH(n) > 1) { if (NCH(n) > 1) {
err_setstr(TypeError, err_setstr(SyntaxError,
"can't assign to operator"); "can't assign to operator");
c->c_errors++; c->c_errors++;
return; return;
@ -1224,7 +1224,7 @@ com_assign(c, n, assigning)
case factor: /* ('+'|'-'|'~') factor | atom trailer* */ case factor: /* ('+'|'-'|'~') factor | atom trailer* */
if (TYPE(CHILD(n, 0)) != atom) { /* '+'|'-'|'~' */ if (TYPE(CHILD(n, 0)) != atom) { /* '+'|'-'|'~' */
err_setstr(TypeError, err_setstr(SyntaxError,
"can't assign to operator"); "can't assign to operator");
c->c_errors++; c->c_errors++;
return; return;
@ -1248,7 +1248,7 @@ com_assign(c, n, assigning)
n = CHILD(n, 1); n = CHILD(n, 1);
if (TYPE(n) == RPAR) { if (TYPE(n) == RPAR) {
/* XXX Should allow () = () ??? */ /* XXX Should allow () = () ??? */
err_setstr(TypeError, err_setstr(SyntaxError,
"can't assign to ()"); "can't assign to ()");
c->c_errors++; c->c_errors++;
return; return;
@ -1257,7 +1257,7 @@ com_assign(c, n, assigning)
case LSQB: case LSQB:
n = CHILD(n, 1); n = CHILD(n, 1);
if (TYPE(n) == RSQB) { if (TYPE(n) == RSQB) {
err_setstr(TypeError, err_setstr(SyntaxError,
"can't assign to []"); "can't assign to []");
c->c_errors++; c->c_errors++;
return; return;
@ -1268,7 +1268,7 @@ com_assign(c, n, assigning)
com_assign_name(c, CHILD(n, 0), assigning); com_assign_name(c, CHILD(n, 0), assigning);
return; return;
default: default:
err_setstr(TypeError, err_setstr(SyntaxError,
"can't assign to literal"); "can't assign to literal");
c->c_errors++; c->c_errors++;
return; return;
@ -1328,7 +1328,7 @@ com_return_stmt(c, n)
{ {
REQ(n, return_stmt); /* 'return' [testlist] */ REQ(n, return_stmt); /* 'return' [testlist] */
if (!c->c_infunction) { if (!c->c_infunction) {
err_setstr(TypeError, "'return' outside function"); err_setstr(SyntaxError, "'return' outside function");
c->c_errors++; c->c_errors++;
} }
if (NCH(n) < 2) if (NCH(n) < 2)
@ -1604,7 +1604,7 @@ com_try_stmt(c, n)
i += 3) { i += 3) {
/* except_clause: 'except' [expr [',' expr]] */ /* except_clause: 'except' [expr [',' expr]] */
if (except_anchor == 0) { if (except_anchor == 0) {
err_setstr(TypeError, err_setstr(SyntaxError,
"default 'except:' must be last"); "default 'except:' must be last");
c->c_errors++; c->c_errors++;
break; break;
@ -1679,7 +1679,7 @@ com_continue_stmt(c, n)
com_addoparg(c, JUMP_ABSOLUTE, c->c_begin); com_addoparg(c, JUMP_ABSOLUTE, c->c_begin);
} }
else { else {
err_setstr(TypeError, "'continue' not properly in loop"); err_setstr(SyntaxError, "'continue' not properly in loop");
c->c_errors++; c->c_errors++;
} }
/* XXX Could allow it inside a 'finally' clause /* XXX Could allow it inside a 'finally' clause
@ -1842,7 +1842,7 @@ com_node(c, n)
break; break;
case break_stmt: case break_stmt:
if (c->c_loops == 0) { if (c->c_loops == 0) {
err_setstr(TypeError, "'break' outside loop"); err_setstr(SyntaxError, "'break' outside loop");
c->c_errors++; c->c_errors++;
} }
com_addbyte(c, BREAK_LOOP); com_addbyte(c, BREAK_LOOP);