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

Side by Side Diff: Modules/parsermodule.c

Issue 11682: PEP 380 reference implementation for 3.3
Patch Set: Created 8 years, 1 month 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:
View unified diff | Download patch
OLDNEW
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 980
980 #undef VALIDATER 981 #undef VALIDATER
981 982
982 #define is_even(n) (((n) & 1) == 0) 983 #define is_even(n) (((n) & 1) == 0)
983 #define is_odd(n) (((n) & 1) == 1) 984 #define is_odd(n) (((n) & 1) == 1)
984 985
985 986
986 static int 987 static int
987 validate_ntype(node *n, int t) 988 validate_ntype(node *n, int t)
988 { 989 {
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
1629 else 1630 else
1630 (void) validate_numnodes(tree, 2, "raise"); 1631 (void) validate_numnodes(tree, 2, "raise");
1631 if (res && (nch == 4)) 1632 if (res && (nch == 4))
1632 res = (validate_comma(CHILD(tree, 2)) 1633 res = (validate_comma(CHILD(tree, 2))
1633 && validate_test(CHILD(tree, 3))); 1634 && validate_test(CHILD(tree, 3)));
1634 1635
1635 return (res); 1636 return (res);
1636 } 1637 }
1637 1638
1638 1639
1639 /* yield_expr: 'yield' [testlist] 1640 /* yield_expr: 'yield' [yield_arg]
1640 */ 1641 */
1641 static int 1642 static int
1642 validate_yield_expr(node *tree) 1643 validate_yield_expr(node *tree)
1643 { 1644 {
1644 int nch = NCH(tree); 1645 int nch = NCH(tree);
1645 int res = (validate_ntype(tree, yield_expr) 1646 if (nch < 1 || nch > 2)
1646 && ((nch == 1) || (nch == 2)) 1647 return 0;
1647 && validate_name(CHILD(tree, 0), "yield")); 1648 if (!validate_ntype(tree, yield_expr))
1648 1649 return 0;
1649 if (res && (nch == 2)) 1650 if (!validate_name(CHILD(tree, 0), "yield"))
1650 res = validate_testlist(CHILD(tree, 1)); 1651 return 0;
1651 1652 if (nch == 2) {
1652 return (res); 1653 if (!validate_yield_arg(CHILD(tree, 1)))
1654 return 0;
1655 }
1656 return 1;
1653 } 1657 }
1654 1658
1659 /* yield_arg: 'from' test | testlist
1660 */
1661 static int
1662 validate_yield_arg(node *tree)
1663 {
1664 int nch = NCH(tree);
1665 if (!validate_ntype(tree, yield_arg))
1666 return 0;
1667 if (nch == 1) {
1668 if (!validate_testlist(CHILD(tree, nch - 1)))
1669 return 0;
1670 }
1671 else if (nch == 2) {
1672 if (!validate_name(CHILD(tree, 0), "from"))
1673 return 0;
1674 if (!validate_test(CHILD(tree, 1)))
1675 return 0;
1676 }
1677 else
1678 return 0;
1679 return 1;
1680 }
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 }
1655 1695
1656 /* yield_stmt: yield_expr 1696 /* yield_stmt: yield_expr
1657 */ 1697 */
1658 static int 1698 static int
1659 validate_yield_stmt(node *tree) 1699 validate_yield_stmt(node *tree)
1660 { 1700 {
1661 return (validate_ntype(tree, yield_stmt) 1701 return (validate_ntype(tree, yield_stmt)
1662 && validate_numnodes(tree, 1, "yield_stmt") 1702 && validate_numnodes(tree, 1, "yield_stmt")
1663 && validate_yield_expr(CHILD(tree, 0))); 1703 && validate_yield_expr(CHILD(tree, 0)));
1664 } 1704 }
(...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after
2658 2698
2659 /* argument: 2699 /* argument:
2660 * 2700 *
2661 * [test '='] test [comp_for] 2701 * [test '='] test [comp_for]
2662 */ 2702 */
2663 static int 2703 static int
2664 validate_argument(node *tree) 2704 validate_argument(node *tree)
2665 { 2705 {
2666 int nch = NCH(tree); 2706 int nch = NCH(tree);
2667 int res = (validate_ntype(tree, argument) 2707 int res = (validate_ntype(tree, argument)
2668 && ((nch == 1) || (nch == 2) || (nch == 3)) 2708 && ((nch == 1) || (nch == 2) || (nch == 3)));
2669 && validate_test(CHILD(tree, 0))); 2709 if (res) {
2670 2710 if (TYPE(CHILD(tree, 0)) == yield_from)
2711 res = (nch == 1) && validate_yield_from(CHILD(tree, 0));
2712 else
2713 res = validate_test(CHILD(tree, 0));
2714 }
2671 if (res && (nch == 2)) 2715 if (res && (nch == 2))
2672 res = validate_comp_for(CHILD(tree, 1)); 2716 res = validate_comp_for(CHILD(tree, 1));
2673 else if (res && (nch == 3)) 2717 else if (res && (nch == 3))
2674 res = (validate_equal(CHILD(tree, 1)) 2718 res = (validate_equal(CHILD(tree, 1))
2675 && validate_test(CHILD(tree, 2))); 2719 && validate_test(CHILD(tree, 2)));
2676 2720
2677 return (res); 2721 return (res);
2678 } 2722 }
2679 2723
2680 2724
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
3254 pickle_constructor, NULL); 3298 pickle_constructor, NULL);
3255 Py_XDECREF(res); 3299 Py_XDECREF(res);
3256 } 3300 }
3257 Py_XDECREF(func); 3301 Py_XDECREF(func);
3258 Py_XDECREF(pickle_constructor); 3302 Py_XDECREF(pickle_constructor);
3259 Py_XDECREF(pickler); 3303 Py_XDECREF(pickler);
3260 Py_DECREF(copyreg); 3304 Py_DECREF(copyreg);
3261 } 3305 }
3262 return module; 3306 return module;
3263 } 3307 }
OLDNEW

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