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

Side by Side Diff: Modules/parsermodule.c

Issue 11682: PEP 380 reference implementation for 3.3
Patch Set: Created 7 years, 5 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:
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);
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) {
Z. Jędrzejewski-Szmek 2012/01/12 19:06:52 nch was tested to be (>=1 && <=2) above. This seco
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) {
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"))
1673 return 0;
1674 if (!validate_test(CHILD(tree, 1)))
1675 return 0;
1676 }
1677 else
1678 return 0;
1679 return 1;
1680 }
1655 1681
1656 /* yield_stmt: yield_expr 1682 /* yield_stmt: yield_expr
1657 */ 1683 */
1658 static int 1684 static int
1659 validate_yield_stmt(node *tree) 1685 validate_yield_stmt(node *tree)
1660 { 1686 {
1661 return (validate_ntype(tree, yield_stmt) 1687 return (validate_ntype(tree, yield_stmt)
1662 && validate_numnodes(tree, 1, "yield_stmt") 1688 && validate_numnodes(tree, 1, "yield_stmt")
1663 && validate_yield_expr(CHILD(tree, 0))); 1689 && validate_yield_expr(CHILD(tree, 0)));
1664 } 1690 }
(...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after
2658 2684
2659 /* argument: 2685 /* argument:
2660 * 2686 *
2661 * [test '='] test [comp_for] 2687 * [test '='] test [comp_for]
2662 */ 2688 */
2663 static int 2689 static int
2664 validate_argument(node *tree) 2690 validate_argument(node *tree)
2665 { 2691 {
2666 int nch = NCH(tree); 2692 int nch = NCH(tree);
2667 int res = (validate_ntype(tree, argument) 2693 int res = (validate_ntype(tree, argument)
2668 && ((nch == 1) || (nch == 2) || (nch == 3)) 2694 && ((nch == 1) || (nch == 2) || (nch == 3)));
2669 && validate_test(CHILD(tree, 0))); 2695 if (res) {
2670 2696 res = validate_test(CHILD(tree, 0));
2697 }
2671 if (res && (nch == 2)) 2698 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
2672 res = validate_comp_for(CHILD(tree, 1)); 2699 res = validate_comp_for(CHILD(tree, 1));
2673 else if (res && (nch == 3)) 2700 else if (res && (nch == 3))
2674 res = (validate_equal(CHILD(tree, 1)) 2701 res = (validate_equal(CHILD(tree, 1))
2675 && validate_test(CHILD(tree, 2))); 2702 && validate_test(CHILD(tree, 2)));
2676 2703
2677 return (res); 2704 return (res);
2678 } 2705 }
2679 2706
2680 2707
2681 2708
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
3257 pickle_constructor, NULL); 3284 pickle_constructor, NULL);
3258 Py_XDECREF(res); 3285 Py_XDECREF(res);
3259 } 3286 }
3260 Py_XDECREF(func); 3287 Py_XDECREF(func);
3261 Py_XDECREF(pickle_constructor); 3288 Py_XDECREF(pickle_constructor);
3262 Py_XDECREF(pickler); 3289 Py_XDECREF(pickler);
3263 Py_DECREF(copyreg); 3290 Py_DECREF(copyreg);
3264 } 3291 }
3265 return module; 3292 return module;
3266 } 3293 }
OLDNEW
« 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+