diff options
author | Georg Brandl <georg@python.org> | 2009-05-25 21:10:36 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2009-05-25 21:10:36 (GMT) |
commit | 0c31562a913e9a49842bd73c04847861c23774f1 (patch) | |
tree | f5fb007402b1a1863c4d317b08be6de4f5547b66 /Modules/parsermodule.c | |
parent | 0c1829b919cce6f6823e843a16c52e104f28c7f9 (diff) | |
download | cpython-0c31562a913e9a49842bd73c04847861c23774f1.zip cpython-0c31562a913e9a49842bd73c04847861c23774f1.tar.gz cpython-0c31562a913e9a49842bd73c04847861c23774f1.tar.bz2 |
Merged revisions 72924 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r72924 | georg.brandl | 2009-05-25 23:02:56 +0200 (Mo, 25 Mai 2009) | 6 lines
Allow multiple context managers in one with statement, as proposed
in http://codereview.appspot.com/53094 and accepted by Guido.
The construct is transformed into multiple With AST nodes so that
there should be no problems with the semantics.
........
Diffstat (limited to 'Modules/parsermodule.c')
-rw-r--r-- | Modules/parsermodule.c | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c index 49f6e23..a16e69c 100644 --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -2446,36 +2446,39 @@ validate_decorators(node *tree) return ok; } -/* with_var -with_var: 'as' expr +/* with_item: + * test ['as' expr] */ static int -validate_with_var(node *tree) +validate_with_item(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; + int ok = (validate_ntype(tree, with_item) + && (nch == 1 || nch == 3) + && validate_test(CHILD(tree, 0))); + if (ok && nch == 3) + ok = (validate_name(CHILD(tree, 1), "as") + && validate_expr(CHILD(tree, 2))); + return ok; } -/* with_stmt - * 0 1 2 -2 -1 -with_stmt: 'with' test [ with_var ] ':' suite +/* with_stmt: + * 0 1 ... -2 -1 + * 'with' with_item (',' with_item)* ':' suite */ static int validate_with_stmt(node *tree) { + int i; int nch = NCH(tree); int ok = (validate_ntype(tree, with_stmt) - && ((nch == 4) || (nch == 5)) + && (nch % 2 == 0) && 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; + for (i = 1; ok && i < nch - 2; i += 2) + ok = validate_with_item(CHILD(tree, i)); + return ok; } /* funcdef: |