Mercurial > cpython-lru_cache-weakref
diff Modules/parsermodule.c @ 36673:2ddea5535f08 legacy-trunk
Update for PEP 308 patch.
| author | Thomas Wouters <thomas@python.org> |
|---|---|
| date | Mon, 27 Feb 2006 16:25:11 +0000 |
| parents | 9f3f87e920a6 |
| children | 54eb5b1fb363 |
line wrap: on
line diff
--- a/Modules/parsermodule.c Mon Feb 27 16:11:03 2006 +0000 +++ b/Modules/parsermodule.c Mon Feb 27 16:25:11 2006 +0000 @@ -861,7 +861,8 @@ VALIDATER(testlist1); VALIDATER(gen_for); VALIDATER(gen_iter); VALIDATER(gen_if); VALIDATER(testlist_gexp); VALIDATER(yield_expr); -VALIDATER(yield_or_testlist); +VALIDATER(yield_or_testlist); VALIDATER(or_test); +VALIDATER(old_test); VALIDATER(old_lambdef); #undef VALIDATER @@ -1095,7 +1096,7 @@ validate_testlist_safe(node *tree) { return (validate_repeating_list(tree, testlist_safe, - validate_test, "testlist_safe")); + validate_old_test, "testlist_safe")); } @@ -1315,7 +1316,7 @@ res = (validate_name(CHILD(tree, 0), "for") && validate_exprlist(CHILD(tree, 1)) && validate_name(CHILD(tree, 2), "in") - && validate_test(CHILD(tree, 3))); + && validate_or_test(CHILD(tree, 3))); return res; } @@ -2047,6 +2048,37 @@ res = ((nch == 1) && validate_lambdef(CHILD(tree, 0))); else if (res) { + res = validate_or_test(CHILD(tree, 0)); + res = (res && (nch == 1 || (nch == 5 && + validate_name(CHILD(tree, 1), "if") && + validate_or_test(CHILD(tree, 2)) && + validate_name(CHILD(tree, 3), "else") && + validate_test(CHILD(tree, 4))))); + } + return (res); +} + +static int +validate_old_test(node *tree) +{ + int nch = NCH(tree); + int res = validate_ntype(tree, old_test) && (nch == 1); + + if (res && (TYPE(CHILD(tree, 0)) == old_lambdef)) + res = (validate_old_lambdef(CHILD(tree, 0))); + else if (res) { + res = (validate_or_test(CHILD(tree, 0))); + } + return (res); +} + +static int +validate_or_test(node *tree) +{ + int nch = NCH(tree); + int res = validate_ntype(tree, or_test) && is_odd(nch); + + if (res) { int pos; res = validate_and_test(CHILD(tree, 0)); for (pos = 1; res && (pos < nch); pos += 2) @@ -2533,6 +2565,25 @@ } +static int +validate_old_lambdef(node *tree) +{ + int nch = NCH(tree); + int res = (validate_ntype(tree, old_lambdef) + && ((nch == 3) || (nch == 4)) + && validate_name(CHILD(tree, 0), "lambda") + && validate_colon(CHILD(tree, nch - 2)) + && validate_test(CHILD(tree, nch - 1))); + + if (res && (nch == 4)) + res = validate_varargslist(CHILD(tree, 1)); + else if (!res && !PyErr_Occurred()) + (void) validate_numnodes(tree, 3, "old_lambdef"); + + return (res); +} + + /* arglist: * * (argument ',')* (argument [','] | '*' test [',' '**' test] | '**' test)
