@@ -954,7 +954,8 @@ VALIDATER(del_stmt);
954954VALIDATER (return_stmt ); VALIDATER (raise_stmt );
955955VALIDATER (import_stmt ); VALIDATER (import_stmt );
956956VALIDATER (import_name ); VALIDATER (yield_stmt );
957- VALIDATER (global_stmt ); VALIDATER (assert_stmt );
957+ VALIDATER (global_stmt ); VALIDATER (nonlocal_stmt );
958+ VALIDATER (assert_stmt );
958959VALIDATER (compound_stmt ); VALIDATER (test_or_star_expr );
959960VALIDATER (while ); VALIDATER (for );
960961VALIDATER (try ); VALIDATER (except_clause );
@@ -1477,6 +1478,7 @@ validate_small_stmt(node *tree)
14771478 || (ntype == flow_stmt )
14781479 || (ntype == import_stmt )
14791480 || (ntype == global_stmt )
1481+ || (ntype == nonlocal_stmt )
14801482 || (ntype == assert_stmt ))
14811483 res = validate_node (CHILD (tree , 0 ));
14821484 else {
@@ -1834,8 +1836,10 @@ validate_import_stmt(node *tree)
18341836}
18351837
18361838
1837-
1838-
1839+ /* global_stmt:
1840+ *
1841+ * 'global' NAME (',' NAME)*
1842+ */
18391843static int
18401844validate_global_stmt (node * tree )
18411845{
@@ -1857,6 +1861,30 @@ validate_global_stmt(node *tree)
18571861 return (res );
18581862}
18591863
1864+ /* nonlocal_stmt:
1865+ *
1866+ * 'nonlocal' NAME (',' NAME)*
1867+ */
1868+ static int
1869+ validate_nonlocal_stmt (node * tree )
1870+ {
1871+ int j ;
1872+ int nch = NCH (tree );
1873+ int res = (validate_ntype (tree , nonlocal_stmt )
1874+ && is_even (nch ) && (nch >= 2 ));
1875+
1876+ if (!res && !PyErr_Occurred ())
1877+ err_string ("illegal nonlocal statement" );
1878+
1879+ if (res )
1880+ res = (validate_name (CHILD (tree , 0 ), "nonlocal" )
1881+ && validate_ntype (CHILD (tree , 1 ), NAME ));
1882+ for (j = 2 ; res && (j < nch ); j += 2 )
1883+ res = (validate_comma (CHILD (tree , j ))
1884+ && validate_ntype (CHILD (tree , j + 1 ), NAME ));
1885+
1886+ return res ;
1887+ }
18601888
18611889/* assert_stmt:
18621890 *
@@ -2921,8 +2949,8 @@ validate_node(node *tree)
29212949 break ;
29222950 case small_stmt :
29232951 /*
2924- * expr_stmt | del_stmt | pass_stmt | flow_stmt
2925- * | import_stmt | global_stmt | assert_stmt
2952+ * expr_stmt | del_stmt | pass_stmt | flow_stmt |
2953+ * import_stmt | global_stmt | nonlocal_stmt | assert_stmt
29262954 */
29272955 res = validate_small_stmt (tree );
29282956 break ;
@@ -2989,6 +3017,9 @@ validate_node(node *tree)
29893017 case global_stmt :
29903018 res = validate_global_stmt (tree );
29913019 break ;
3020+ case nonlocal_stmt :
3021+ res = validate_nonlocal_stmt (tree );
3022+ break ;
29923023 case assert_stmt :
29933024 res = validate_assert_stmt (tree );
29943025 break ;
0 commit comments