mirror of
https://github.com/python/cpython.git
synced 2025-10-17 20:28:43 +00:00
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.
This commit is contained in:
parent
10430ad7aa
commit
4905e80c3d
8 changed files with 1119 additions and 1085 deletions
|
@ -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)
|
||||
|
@ -2785,11 +2787,28 @@ 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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue