diff options
author | Benjamin Peterson <benjamin@python.org> | 2008-11-24 04:19:49 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2008-11-24 04:19:49 (GMT) |
commit | 9e233a545c681118f453d2300b4af2317273dfaa (patch) | |
tree | 2f9f9c22a0a8a7f2b13413133ab53b0f517c3e21 /Modules | |
parent | d8ab1e4751132a4bd0cf1029ad92a51b028cd6cc (diff) | |
download | cpython-9e233a545c681118f453d2300b4af2317273dfaa.zip cpython-9e233a545c681118f453d2300b4af2317273dfaa.tar.gz cpython-9e233a545c681118f453d2300b4af2317273dfaa.tar.bz2 |
Merged revisions 67365 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r67365 | benjamin.peterson | 2008-11-23 22:09:03 -0600 (Sun, 23 Nov 2008) | 1 line
#4396 make the parser module correctly validate the with syntax
........
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/parsermodule.c | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c index bea78c2..95fcdcd 100644 --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -1559,7 +1559,7 @@ validate_small_stmt(node *tree) /* compound_stmt: - * if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef | decorated + * if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated */ static int validate_compound_stmt(node *tree) @@ -1577,6 +1577,7 @@ validate_compound_stmt(node *tree) || (ntype == while_stmt) || (ntype == for_stmt) || (ntype == try_stmt) + || (ntype == with_stmt) || (ntype == funcdef) || (ntype == classdef) || (ntype == decorated)) @@ -2617,6 +2618,38 @@ validate_decorators(node *tree) return ok; } +/* with_var +with_var: 'as' expr + */ +static int +validate_with_var(node *tree) +{ + int nch = NCH(tree); + int ok = (validate_ntype(tree, with_var) + && (nch == 2) + && validate_name(CHILD(tree, 0), "as") + && validate_expr(CHILD(tree, 1))); + return ok; +} + +/* with_stmt + * 0 1 2 -2 -1 +with_stmt: 'with' test [ with_var ] ':' suite + */ +static int +validate_with_stmt(node *tree) +{ + int nch = NCH(tree); + int ok = (validate_ntype(tree, with_stmt) + && ((nch == 4) || (nch == 5)) + && validate_name(CHILD(tree, 0), "with") + && validate_test(CHILD(tree, 1)) + && (nch == 4 || validate_with_var(CHILD(tree, 2))) + && validate_colon(RCHILD(tree, -2)) + && validate_suite(RCHILD(tree, -1))); + return ok; +} + /* funcdef: * * -5 -4 -3 -2 -1 @@ -2993,6 +3026,9 @@ validate_node(node *tree) case funcdef: res = validate_funcdef(tree); break; + case with_stmt: + res = validate_with_stmt(tree); + break; case classdef: res = validate_class(tree); break; |