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

Delta Between Two Patch Sets: Modules/parsermodule.c

Issue 11682: PEP 380 reference implementation for 3.3
Left Patch Set: Created 7 years, 8 months ago
Right Patch Set: Created 7 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Misc/NEWS ('k') | Objects/abstract.c » ('j') | Objects/exceptions.c » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* parsermodule.c 1 /* parsermodule.c
2 * 2 *
3 * Copyright 1995-1996 by Fred L. Drake, Jr. and Virginia Polytechnic 3 * Copyright 1995-1996 by Fred L. Drake, Jr. and Virginia Polytechnic
4 * Institute and State University, Blacksburg, Virginia, USA. 4 * Institute and State University, Blacksburg, Virginia, USA.
5 * Portions copyright 1991-1995 by Stichting Mathematisch Centrum, 5 * Portions copyright 1991-1995 by Stichting Mathematisch Centrum,
6 * Amsterdam, The Netherlands. Copying is permitted under the terms 6 * Amsterdam, The Netherlands. Copying is permitted under the terms
7 * associated with the main Python distribution, with the additional 7 * associated with the main Python distribution, with the additional
8 * restriction that this additional notice be included and maintained 8 * restriction that this additional notice be included and maintained
9 * on all distributed copies. 9 * on all distributed copies.
10 * 10 *
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 VALIDATER(atom); VALIDATER(lambdef); 969 VALIDATER(atom); VALIDATER(lambdef);
970 VALIDATER(trailer); VALIDATER(subscript); 970 VALIDATER(trailer); VALIDATER(subscript);
971 VALIDATER(subscriptlist); VALIDATER(sliceop); 971 VALIDATER(subscriptlist); VALIDATER(sliceop);
972 VALIDATER(exprlist); VALIDATER(dictorsetmaker); 972 VALIDATER(exprlist); VALIDATER(dictorsetmaker);
973 VALIDATER(arglist); VALIDATER(argument); 973 VALIDATER(arglist); VALIDATER(argument);
974 VALIDATER(comp_for); 974 VALIDATER(comp_for);
975 VALIDATER(comp_iter); VALIDATER(comp_if); 975 VALIDATER(comp_iter); VALIDATER(comp_if);
976 VALIDATER(testlist_comp); VALIDATER(yield_expr); 976 VALIDATER(testlist_comp); VALIDATER(yield_expr);
977 VALIDATER(or_test); 977 VALIDATER(or_test);
978 VALIDATER(test_nocond); VALIDATER(lambdef_nocond); 978 VALIDATER(test_nocond); VALIDATER(lambdef_nocond);
979 VALIDATER(yield_arg); VALIDATER(yield_from); 979 VALIDATER(yield_arg);
980 980
981 #undef VALIDATER 981 #undef VALIDATER
982 982
983 #define is_even(n) (((n) & 1) == 0) 983 #define is_even(n) (((n) & 1) == 0)
984 #define is_odd(n) (((n) & 1) == 1) 984 #define is_odd(n) (((n) & 1) == 1)
985 985
986 986
987 static int 987 static int
988 validate_ntype(node *n, int t) 988 validate_ntype(node *n, int t)
989 { 989 {
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after
1642 static int 1642 static int
1643 validate_yield_expr(node *tree) 1643 validate_yield_expr(node *tree)
1644 { 1644 {
1645 int nch = NCH(tree); 1645 int nch = NCH(tree);
1646 if (nch < 1 || nch > 2) 1646 if (nch < 1 || nch > 2)
1647 return 0; 1647 return 0;
1648 if (!validate_ntype(tree, yield_expr)) 1648 if (!validate_ntype(tree, yield_expr))
1649 return 0; 1649 return 0;
1650 if (!validate_name(CHILD(tree, 0), "yield")) 1650 if (!validate_name(CHILD(tree, 0), "yield"))
1651 return 0; 1651 return 0;
1652 if (nch == 2) { 1652 if (nch == 2) {
Z. Jędrzejewski-Szmek 2012/01/12 19:06:52 nch was tested to be (>=1 && <=2) above. This seco
1653 if (!validate_yield_arg(CHILD(tree, 1))) 1653 if (!validate_yield_arg(CHILD(tree, 1)))
1654 return 0; 1654 return 0;
1655 } 1655 }
1656 return 1; 1656 return 1;
1657 } 1657 }
1658 1658
1659 /* yield_arg: 'from' test | testlist 1659 /* yield_arg: 'from' test | testlist
1660 */ 1660 */
1661 static int 1661 static int
1662 validate_yield_arg(node *tree) 1662 validate_yield_arg(node *tree)
1663 { 1663 {
1664 int nch = NCH(tree); 1664 int nch = NCH(tree);
1665 if (!validate_ntype(tree, yield_arg)) 1665 if (!validate_ntype(tree, yield_arg))
1666 return 0; 1666 return 0;
1667 if (nch == 1) { 1667 if (nch == 1) {
1668 if (!validate_testlist(CHILD(tree, nch - 1))) 1668 if (!validate_testlist(CHILD(tree, nch - 1)))
1669 return 0; 1669 return 0;
1670 } 1670 }
1671 else if (nch == 2) { 1671 else if (nch == 2) {
Z. Jędrzejewski-Szmek 2012/01/12 19:06:52 Indentation here (off-by-one-space) Also I think
1672 if (!validate_name(CHILD(tree, 0), "from")) 1672 if (!validate_name(CHILD(tree, 0), "from"))
1673 return 0; 1673 return 0;
1674 if (!validate_test(CHILD(tree, 1))) 1674 if (!validate_test(CHILD(tree, 1)))
1675 return 0; 1675 return 0;
1676 } 1676 }
1677 else 1677 else
1678 return 0; 1678 return 0;
1679 return 1; 1679 return 1;
1680 } 1680 }
1681 1681
1682 /* yield_from: 'yield' 'from' test
1683 */
1684 static int
1685 validate_yield_from(node *tree)
1686 {
1687 int nch = NCH(tree);
1688 int res = (validate_ntype(tree, yield_from)
1689 && (nch == 3)
1690 && validate_name(CHILD(tree, 0), "yield")
1691 && validate_name(CHILD(tree, 1), "from")
1692 && validate_test(CHILD(tree, 2)));
1693 return res;
1694 }
1695
1696 /* yield_stmt: yield_expr 1682 /* yield_stmt: yield_expr
1697 */ 1683 */
1698 static int 1684 static int
1699 validate_yield_stmt(node *tree) 1685 validate_yield_stmt(node *tree)
1700 { 1686 {
1701 return (validate_ntype(tree, yield_stmt) 1687 return (validate_ntype(tree, yield_stmt)
1702 && validate_numnodes(tree, 1, "yield_stmt") 1688 && validate_numnodes(tree, 1, "yield_stmt")
1703 && validate_yield_expr(CHILD(tree, 0))); 1689 && validate_yield_expr(CHILD(tree, 0)));
1704 } 1690 }
1705 1691
(...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after
2700 * 2686 *
2701 * [test '='] test [comp_for] 2687 * [test '='] test [comp_for]
2702 */ 2688 */
2703 static int 2689 static int
2704 validate_argument(node *tree) 2690 validate_argument(node *tree)
2705 { 2691 {
2706 int nch = NCH(tree); 2692 int nch = NCH(tree);
2707 int res = (validate_ntype(tree, argument) 2693 int res = (validate_ntype(tree, argument)
2708 && ((nch == 1) || (nch == 2) || (nch == 3))); 2694 && ((nch == 1) || (nch == 2) || (nch == 3)));
2709 if (res) { 2695 if (res) {
2710 if (TYPE(CHILD(tree, 0)) == yield_from) 2696 res = validate_test(CHILD(tree, 0));
2711 res = (nch == 1) && validate_yield_from(CHILD(tree, 0));
2712 else
2713 res = validate_test(CHILD(tree, 0));
2714 } 2697 }
2715 if (res && (nch == 2)) 2698 if (res && (nch == 2))
2716 res = validate_comp_for(CHILD(tree, 1)); 2699 res = validate_comp_for(CHILD(tree, 1));
2717 else if (res && (nch == 3)) 2700 else if (res && (nch == 3))
2718 res = (validate_equal(CHILD(tree, 1)) 2701 res = (validate_equal(CHILD(tree, 1))
2719 && validate_test(CHILD(tree, 2))); 2702 && validate_test(CHILD(tree, 2)));
2720 2703
2721 return (res); 2704 return (res);
2722 } 2705 }
2723 2706
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
3301 pickle_constructor, NULL); 3284 pickle_constructor, NULL);
3302 Py_XDECREF(res); 3285 Py_XDECREF(res);
3303 } 3286 }
3304 Py_XDECREF(func); 3287 Py_XDECREF(func);
3305 Py_XDECREF(pickle_constructor); 3288 Py_XDECREF(pickle_constructor);
3306 Py_XDECREF(pickler); 3289 Py_XDECREF(pickler);
3307 Py_DECREF(copyreg); 3290 Py_DECREF(copyreg);
3308 } 3291 }
3309 return module; 3292 return module;
3310 } 3293 }
LEFTRIGHT

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