mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
Support assert stmt.
This commit is contained in:
parent
4669fb474b
commit
925e547fcc
1 changed files with 32 additions and 1 deletions
|
@ -874,6 +874,7 @@ VALIDATER(print_stmt); VALIDATER(del_stmt);
|
||||||
VALIDATER(return_stmt);
|
VALIDATER(return_stmt);
|
||||||
VALIDATER(raise_stmt); VALIDATER(import_stmt);
|
VALIDATER(raise_stmt); VALIDATER(import_stmt);
|
||||||
VALIDATER(global_stmt);
|
VALIDATER(global_stmt);
|
||||||
|
VALIDATER(assert_stmt);
|
||||||
VALIDATER(exec_stmt); VALIDATER(compound_stmt);
|
VALIDATER(exec_stmt); VALIDATER(compound_stmt);
|
||||||
VALIDATER(while); VALIDATER(for);
|
VALIDATER(while); VALIDATER(for);
|
||||||
VALIDATER(try); VALIDATER(except_clause);
|
VALIDATER(try); VALIDATER(except_clause);
|
||||||
|
@ -1333,6 +1334,7 @@ validate_small_stmt(tree)
|
||||||
|| (TYPE(CHILD(tree, 0)) == flow_stmt)
|
|| (TYPE(CHILD(tree, 0)) == flow_stmt)
|
||||||
|| (TYPE(CHILD(tree, 0)) == import_stmt)
|
|| (TYPE(CHILD(tree, 0)) == import_stmt)
|
||||||
|| (TYPE(CHILD(tree, 0)) == global_stmt)
|
|| (TYPE(CHILD(tree, 0)) == global_stmt)
|
||||||
|
|| (TYPE(CHILD(tree, 0)) == assert_stmt)
|
||||||
|| (TYPE(CHILD(tree, 0)) == exec_stmt)));
|
|| (TYPE(CHILD(tree, 0)) == exec_stmt)));
|
||||||
|
|
||||||
if (res)
|
if (res)
|
||||||
|
@ -1584,6 +1586,32 @@ validate_exec_stmt(tree)
|
||||||
} /* validate_exec_stmt() */
|
} /* validate_exec_stmt() */
|
||||||
|
|
||||||
|
|
||||||
|
/* assert_stmt:
|
||||||
|
*
|
||||||
|
* 'assert' test [',' test]
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
validate_assert_stmt(tree)
|
||||||
|
node *tree;
|
||||||
|
{
|
||||||
|
int nch = NCH(tree);
|
||||||
|
int res = (validate_ntype(tree, assert_stmt)
|
||||||
|
&& ((nch == 2) || (nch == 4))
|
||||||
|
&& (validate_name(CHILD(tree, 0), "__assert__") ||
|
||||||
|
validate_name(CHILD(tree, 0), "assert"))
|
||||||
|
&& validate_test(CHILD(tree, 1)));
|
||||||
|
|
||||||
|
if (!res && !PyErr_Occurred())
|
||||||
|
err_string("Illegal assert statement.");
|
||||||
|
if (res && (nch > 2))
|
||||||
|
res = (validate_comma(CHILD(tree, 2))
|
||||||
|
&& validate_test(CHILD(tree, 3)));
|
||||||
|
|
||||||
|
return (res);
|
||||||
|
|
||||||
|
} /* validate_assert_stmt() */
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
validate_while(tree)
|
validate_while(tree)
|
||||||
node *tree;
|
node *tree;
|
||||||
|
@ -2373,7 +2401,7 @@ validate_node(tree)
|
||||||
case small_stmt:
|
case small_stmt:
|
||||||
/*
|
/*
|
||||||
* expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt
|
* expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt
|
||||||
* | import_stmt | global_stmt | exec_stmt
|
* | import_stmt | global_stmt | exec_stmt | assert_stmt
|
||||||
*/
|
*/
|
||||||
res = validate_small_stmt(tree);
|
res = validate_small_stmt(tree);
|
||||||
break;
|
break;
|
||||||
|
@ -2436,6 +2464,9 @@ validate_node(tree)
|
||||||
case exec_stmt:
|
case exec_stmt:
|
||||||
res = validate_exec_stmt(tree);
|
res = validate_exec_stmt(tree);
|
||||||
break;
|
break;
|
||||||
|
case assert_stmt:
|
||||||
|
res = validate_assert_stmt(tree);
|
||||||
|
break;
|
||||||
case if_stmt:
|
case if_stmt:
|
||||||
res = validate_if(tree);
|
res = validate_if(tree);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue