diff options
author | Guido van Rossum <guido@python.org> | 1997-04-02 05:32:13 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1997-04-02 05:32:13 (GMT) |
commit | 925e547fcc6479379ed767c20c01ba84f31383b3 (patch) | |
tree | dcd9cc3baddd5d9d8b02728c9f77818051ead507 /Modules | |
parent | 4669fb474b1a4b9e55467f4fe2fc9c0132f03291 (diff) | |
download | cpython-925e547fcc6479379ed767c20c01ba84f31383b3.zip cpython-925e547fcc6479379ed767c20c01ba84f31383b3.tar.gz cpython-925e547fcc6479379ed767c20c01ba84f31383b3.tar.bz2 |
Support assert stmt.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/parsermodule.c | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c index 4167eb1..bd1be62 100644 --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -874,6 +874,7 @@ VALIDATER(print_stmt); VALIDATER(del_stmt); VALIDATER(return_stmt); VALIDATER(raise_stmt); VALIDATER(import_stmt); VALIDATER(global_stmt); +VALIDATER(assert_stmt); VALIDATER(exec_stmt); VALIDATER(compound_stmt); VALIDATER(while); VALIDATER(for); VALIDATER(try); VALIDATER(except_clause); @@ -1333,6 +1334,7 @@ validate_small_stmt(tree) || (TYPE(CHILD(tree, 0)) == flow_stmt) || (TYPE(CHILD(tree, 0)) == import_stmt) || (TYPE(CHILD(tree, 0)) == global_stmt) + || (TYPE(CHILD(tree, 0)) == assert_stmt) || (TYPE(CHILD(tree, 0)) == exec_stmt))); if (res) @@ -1584,6 +1586,32 @@ validate_exec_stmt(tree) } /* 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 validate_while(tree) node *tree; @@ -2373,7 +2401,7 @@ validate_node(tree) case small_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); break; @@ -2436,6 +2464,9 @@ validate_node(tree) case exec_stmt: res = validate_exec_stmt(tree); break; + case assert_stmt: + res = validate_assert_stmt(tree); + break; case if_stmt: res = validate_if(tree); break; |