summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-09-27 02:43:28 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-09-27 02:43:28 (GMT)
commit4905e80c3d2f6abb613d212f0313d1dfe09475dc (patch)
treedf849b7313a57c1d844567bcd45b32f7e89ac0ca /Modules
parent10430ad7aace46c93939341817b97df48951d5a2 (diff)
downloadcpython-4905e80c3d2f6abb613d212f0313d1dfe09475dc.zip
cpython-4905e80c3d2f6abb613d212f0313d1dfe09475dc.tar.gz
cpython-4905e80c3d2f6abb613d212f0313d1dfe09475dc.tar.bz2
fix an ambiguity in the grammar from the implementation of extended unpacking
(one which was strangely "resolved" by pgen) This also kills the unused testlist1 rule and fixes parse tree validation of extended unpacking.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/parsermodule.c74
1 files changed, 45 insertions, 29 deletions
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c
index a16e69c..2fa8529 100644
--- a/Modules/parsermodule.c
+++ b/Modules/parsermodule.c
@@ -943,7 +943,7 @@ VALIDATER(return_stmt); VALIDATER(raise_stmt);
VALIDATER(import_stmt); VALIDATER(import_stmt);
VALIDATER(import_name); VALIDATER(yield_stmt);
VALIDATER(global_stmt); VALIDATER(assert_stmt);
-VALIDATER(compound_stmt);
+VALIDATER(compound_stmt); VALIDATER(test_or_star_expr);
VALIDATER(while); VALIDATER(for);
VALIDATER(try); VALIDATER(except_clause);
VALIDATER(test); VALIDATER(and_test);
@@ -958,10 +958,10 @@ VALIDATER(trailer); VALIDATER(subscript);
VALIDATER(subscriptlist); VALIDATER(sliceop);
VALIDATER(exprlist); VALIDATER(dictorsetmaker);
VALIDATER(arglist); VALIDATER(argument);
-VALIDATER(testlist1); VALIDATER(comp_for);
+VALIDATER(comp_for);
VALIDATER(comp_iter); VALIDATER(comp_if);
VALIDATER(testlist_comp); VALIDATER(yield_expr);
-VALIDATER(yield_or_testlist); VALIDATER(or_test);
+VALIDATER(or_test);
VALIDATER(test_nocond); VALIDATER(lambdef_nocond);
#undef VALIDATER
@@ -1183,12 +1183,11 @@ validate_testlist(node *tree)
validate_test, "testlist"));
}
-
static int
-validate_testlist1(node *tree)
+validate_testlist_star_expr(node *tl)
{
- return (validate_repeating_list(tree, testlist1,
- validate_test, "testlist1"));
+ return (validate_repeating_list(tl, testlist_star_expr, validate_test_or_star_expr,
+ "testlist"));
}
@@ -1516,12 +1515,17 @@ validate_compound_stmt(node *tree)
}
static int
-validate_yield_or_testlist(node *tree)
+validate_yield_or_testlist(node *tree, int tse)
{
- if (TYPE(tree) == yield_expr)
- return validate_yield_expr(tree);
- else
- return validate_testlist(tree);
+ if (TYPE(tree) == yield_expr) {
+ return validate_yield_expr(tree);
+ }
+ else {
+ if (tse)
+ return validate_testlist_star_expr(tree);
+ else
+ return validate_testlist(tree);
+ }
}
static int
@@ -1531,12 +1535,12 @@ validate_expr_stmt(node *tree)
int nch = NCH(tree);
int res = (validate_ntype(tree, expr_stmt)
&& is_odd(nch)
- && validate_testlist(CHILD(tree, 0)));
+ && validate_testlist_star_expr(CHILD(tree, 0)));
if (res && nch == 3
&& TYPE(CHILD(tree, 1)) == augassign) {
res = validate_numnodes(CHILD(tree, 1), 1, "augassign")
- && validate_yield_or_testlist(CHILD(tree, 2));
+ && validate_yield_or_testlist(CHILD(tree, 2), 0);
if (res) {
char *s = STR(CHILD(CHILD(tree, 1), 0));
@@ -1560,7 +1564,7 @@ validate_expr_stmt(node *tree)
else {
for (j = 1; res && (j < nch); j += 2)
res = validate_equal(CHILD(tree, j))
- && validate_yield_or_testlist(CHILD(tree, j + 1));
+ && validate_yield_or_testlist(CHILD(tree, j + 1), 1);
}
return (res);
}
@@ -2077,11 +2081,11 @@ validate_comparison(node *tree)
int nch = NCH(tree);
int res = (validate_ntype(tree, comparison)
&& is_odd(nch)
- && validate_star_expr(CHILD(tree, 0)));
+ && validate_expr(CHILD(tree, 0)));
for (pos = 1; res && (pos < nch); pos += 2)
res = (validate_comp_op(CHILD(tree, pos))
- && validate_star_expr(CHILD(tree, pos + 1)));
+ && validate_expr(CHILD(tree, pos + 1)));
return (res);
}
@@ -2143,12 +2147,10 @@ validate_star_expr(node *tree)
{
int res = validate_ntype(tree, star_expr);
if (!res) return res;
- if (NCH(tree) == 2) {
- return validate_ntype(CHILD(tree, 0), STAR) && \
- validate_expr(CHILD(tree, 1));
- } else {
- return validate_expr(CHILD(tree, 0));
- }
+ if (!validate_numnodes(tree, 2, "star_expr"))
+ return 0;
+ return validate_ntype(CHILD(tree, 0), STAR) && \
+ validate_expr(CHILD(tree, 1));
}
@@ -2379,7 +2381,7 @@ validate_testlist_comp(node *tree)
if (nch == 0)
err_string("missing child nodes of testlist_comp");
else {
- ok = validate_test(CHILD(tree, 0));
+ ok = validate_test_or_star_expr(CHILD(tree, 0));
}
/*
@@ -2392,7 +2394,7 @@ validate_testlist_comp(node *tree)
int i = 1;
while (ok && nch - i >= 2) {
ok = (validate_comma(CHILD(tree, i))
- && validate_test(CHILD(tree, i+1)));
+ && validate_test_or_star_expr(CHILD(tree, i+1)));
i += 2;
}
if (ok && i == nch-1)
@@ -2786,10 +2788,27 @@ validate_sliceop(node *tree)
static int
+validate_test_or_star_expr(node *n)
+{
+ if (TYPE(n) == test)
+ return validate_test(n);
+ return validate_star_expr(n);
+}
+
+static int
+validate_expr_or_star_expr(node *n)
+{
+ if (TYPE(n) == expr)
+ return validate_expr(n);
+ return validate_star_expr(n);
+}
+
+
+static int
validate_exprlist(node *tree)
{
return (validate_repeating_list(tree, exprlist,
- validate_star_expr, "exprlist"));
+ validate_expr_or_star_expr, "exprlist"));
}
@@ -2970,9 +2989,6 @@ validate_node(node *tree)
case yield_expr:
res = validate_yield_expr(tree);
break;
- case testlist1:
- res = validate_testlist1(tree);
- break;
case test:
res = validate_test(tree);
break;