Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(170348)

Unified Diff: Modules/parsermodule.c

Issue 11682: PEP 380 reference implementation for 3.3
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Misc/NEWS ('k') | Objects/abstract.c » ('j') | Objects/exceptions.c » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Modules/parsermodule.c Thu Jan 12 08:06:49 2012 +0100
+++ b/Modules/parsermodule.c Fri Jan 13 00:26:31 2012 +1000
@@ -976,6 +976,7 @@
VALIDATER(testlist_comp); VALIDATER(yield_expr);
VALIDATER(or_test);
VALIDATER(test_nocond); VALIDATER(lambdef_nocond);
+VALIDATER(yield_arg);
#undef VALIDATER
@@ -1636,22 +1637,47 @@
}
-/* yield_expr: 'yield' [testlist]
+/* yield_expr: 'yield' [yield_arg]
*/
static int
validate_yield_expr(node *tree)
{
int nch = NCH(tree);
- int res = (validate_ntype(tree, yield_expr)
- && ((nch == 1) || (nch == 2))
- && validate_name(CHILD(tree, 0), "yield"));
-
- if (res && (nch == 2))
- res = validate_testlist(CHILD(tree, 1));
-
- return (res);
+ if (nch < 1 || nch > 2)
+ return 0;
+ if (!validate_ntype(tree, yield_expr))
+ return 0;
+ if (!validate_name(CHILD(tree, 0), "yield"))
+ return 0;
+ if (nch == 2) {
Z. Jędrzejewski-Szmek 2012/01/12 19:06:52 nch was tested to be (>=1 && <=2) above. This seco
+ if (!validate_yield_arg(CHILD(tree, 1)))
+ return 0;
+ }
+ return 1;
}
+/* yield_arg: 'from' test | testlist
+ */
+static int
+validate_yield_arg(node *tree)
+{
+ int nch = NCH(tree);
+ if (!validate_ntype(tree, yield_arg))
+ return 0;
+ if (nch == 1) {
+ if (!validate_testlist(CHILD(tree, nch - 1)))
+ return 0;
+ }
+ else if (nch == 2) {
Z. Jędrzejewski-Szmek 2012/01/12 19:06:52 Indentation here (off-by-one-space) Also I think
+ if (!validate_name(CHILD(tree, 0), "from"))
+ return 0;
+ if (!validate_test(CHILD(tree, 1)))
+ return 0;
+ }
+ else
+ return 0;
+ return 1;
+}
/* yield_stmt: yield_expr
*/
@@ -2665,9 +2691,10 @@
{
int nch = NCH(tree);
int res = (validate_ntype(tree, argument)
- && ((nch == 1) || (nch == 2) || (nch == 3))
- && validate_test(CHILD(tree, 0)));
-
+ && ((nch == 1) || (nch == 2) || (nch == 3)));
+ if (res) {
+ res = validate_test(CHILD(tree, 0));
+ }
if (res && (nch == 2))
Z. Jędrzejewski-Szmek 2012/01/12 19:06:52 Other ifs don't have braces -- this one is out of
res = validate_comp_for(CHILD(tree, 1));
else if (res && (nch == 3))
« no previous file with comments | « Misc/NEWS ('k') | Objects/abstract.c » ('j') | Objects/exceptions.c » ('J')

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+