@@ -956,7 +956,8 @@ VALIDATER(del_stmt);
956956VALIDATER (return_stmt ); VALIDATER (raise_stmt );
957957VALIDATER (import_stmt ); VALIDATER (import_stmt );
958958VALIDATER (import_name ); VALIDATER (yield_stmt );
959- VALIDATER (global_stmt ); VALIDATER (assert_stmt );
959+ VALIDATER (global_stmt ); VALIDATER (nonlocal_stmt );
960+ VALIDATER (assert_stmt );
960961VALIDATER (compound_stmt ); VALIDATER (test_or_star_expr );
961962VALIDATER (while ); VALIDATER (for );
962963VALIDATER (try ); VALIDATER (except_clause );
@@ -1480,6 +1481,7 @@ validate_small_stmt(node *tree)
14801481 || (ntype == flow_stmt )
14811482 || (ntype == import_stmt )
14821483 || (ntype == global_stmt )
1484+ || (ntype == nonlocal_stmt )
14831485 || (ntype == assert_stmt ))
14841486 res = validate_node (CHILD (tree , 0 ));
14851487 else {
@@ -1864,8 +1866,10 @@ validate_import_stmt(node *tree)
18641866}
18651867
18661868
1867-
1868-
1869+ /* global_stmt:
1870+ *
1871+ * 'global' NAME (',' NAME)*
1872+ */
18691873static int
18701874validate_global_stmt (node * tree )
18711875{
@@ -1887,6 +1891,30 @@ validate_global_stmt(node *tree)
18871891 return (res );
18881892}
18891893
1894+ /* nonlocal_stmt:
1895+ *
1896+ * 'nonlocal' NAME (',' NAME)*
1897+ */
1898+ static int
1899+ validate_nonlocal_stmt (node * tree )
1900+ {
1901+ int j ;
1902+ int nch = NCH (tree );
1903+ int res = (validate_ntype (tree , nonlocal_stmt )
1904+ && is_even (nch ) && (nch >= 2 ));
1905+
1906+ if (!res && !PyErr_Occurred ())
1907+ err_string ("illegal nonlocal statement" );
1908+
1909+ if (res )
1910+ res = (validate_name (CHILD (tree , 0 ), "nonlocal" )
1911+ && validate_ntype (CHILD (tree , 1 ), NAME ));
1912+ for (j = 2 ; res && (j < nch ); j += 2 )
1913+ res = (validate_comma (CHILD (tree , j ))
1914+ && validate_ntype (CHILD (tree , j + 1 ), NAME ));
1915+
1916+ return res ;
1917+ }
18901918
18911919/* assert_stmt:
18921920 *
@@ -2951,8 +2979,8 @@ validate_node(node *tree)
29512979 break ;
29522980 case small_stmt :
29532981 /*
2954- * expr_stmt | del_stmt | pass_stmt | flow_stmt
2955- * | import_stmt | global_stmt | assert_stmt
2982+ * expr_stmt | del_stmt | pass_stmt | flow_stmt |
2983+ * import_stmt | global_stmt | nonlocal_stmt | assert_stmt
29562984 */
29572985 res = validate_small_stmt (tree );
29582986 break ;
@@ -3019,6 +3047,9 @@ validate_node(node *tree)
30193047 case global_stmt :
30203048 res = validate_global_stmt (tree );
30213049 break ;
3050+ case nonlocal_stmt :
3051+ res = validate_nonlocal_stmt (tree );
3052+ break ;
30223053 case assert_stmt :
30233054 res = validate_assert_stmt (tree );
30243055 break ;
0 commit comments