mirror of
https://github.com/python/cpython.git
synced 2025-11-03 03:22:27 +00:00
validate_varargslist(): Fix two bugs in this function, one that affected
it when *args and/or **kw are used, and one when
they are not.
This closes bug #125375: "parser.tuple2ast() failure on valid parse tree".
This commit is contained in:
parent
ed911b8cfb
commit
b6429a2020
1 changed files with 20 additions and 11 deletions
|
|
@ -1098,12 +1098,17 @@ validate_varargslist(node *tree)
|
||||||
int res = validate_ntype(tree, varargslist) && (nch != 0);
|
int res = validate_ntype(tree, varargslist) && (nch != 0);
|
||||||
int sym;
|
int sym;
|
||||||
|
|
||||||
|
if (!res)
|
||||||
|
return 0;
|
||||||
if (nch < 1) {
|
if (nch < 1) {
|
||||||
err_string("varargslist missing child nodes");
|
err_string("varargslist missing child nodes");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
sym = TYPE(CHILD(tree, 0));
|
sym = TYPE(CHILD(tree, 0));
|
||||||
if (sym == STAR || sym == DOUBLESTAR)
|
if (sym == STAR || sym == DOUBLESTAR)
|
||||||
|
/* whole thing matches:
|
||||||
|
* '*' NAME [',' '**' NAME] | '**' NAME
|
||||||
|
*/
|
||||||
res = validate_varargslist_trailer(tree, 0);
|
res = validate_varargslist_trailer(tree, 0);
|
||||||
else if (sym == fpdef) {
|
else if (sym == fpdef) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
@ -1127,11 +1132,16 @@ validate_varargslist(node *tree)
|
||||||
}
|
}
|
||||||
if (res && i < nch) {
|
if (res && i < nch) {
|
||||||
res = validate_comma(CHILD(tree, i));
|
res = validate_comma(CHILD(tree, i));
|
||||||
if (res)
|
|
||||||
++i;
|
++i;
|
||||||
|
if (res && i < nch
|
||||||
|
&& (TYPE(CHILD(tree, i)) == DOUBLESTAR
|
||||||
|
|| TYPE(CHILD(tree, i)) == STAR))
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* handle '*' NAME [',' '**' NAME] | '**' NAME */
|
/* ... '*' NAME [',' '**' NAME] | '**' NAME
|
||||||
|
* i --^^^
|
||||||
|
*/
|
||||||
if (res)
|
if (res)
|
||||||
res = validate_varargslist_trailer(tree, i);
|
res = validate_varargslist_trailer(tree, i);
|
||||||
}
|
}
|
||||||
|
|
@ -1139,6 +1149,7 @@ validate_varargslist(node *tree)
|
||||||
/*
|
/*
|
||||||
* fpdef ['=' test] (',' fpdef ['=' test])* [',']
|
* fpdef ['=' test] (',' fpdef ['=' test])* [',']
|
||||||
*/
|
*/
|
||||||
|
/* strip trailing comma node */
|
||||||
if (sym == COMMA) {
|
if (sym == COMMA) {
|
||||||
res = validate_comma(CHILD(tree, nch-1));
|
res = validate_comma(CHILD(tree, nch-1));
|
||||||
if (!res)
|
if (!res)
|
||||||
|
|
@ -1150,9 +1161,9 @@ validate_varargslist(node *tree)
|
||||||
*/
|
*/
|
||||||
res = validate_fpdef(CHILD(tree, 0));
|
res = validate_fpdef(CHILD(tree, 0));
|
||||||
++i;
|
++i;
|
||||||
if (res && (i+2 < nch) && TYPE(CHILD(tree, 1)) == EQUAL) {
|
if (res && (i+2 <= nch) && TYPE(CHILD(tree, i)) == EQUAL) {
|
||||||
res = (validate_equal(CHILD(tree, 1))
|
res = (validate_equal(CHILD(tree, i))
|
||||||
&& validate_test(CHILD(tree, 2)));
|
&& validate_test(CHILD(tree, i+1)));
|
||||||
i += 2;
|
i += 2;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
|
@ -1163,11 +1174,9 @@ validate_varargslist(node *tree)
|
||||||
res = (validate_comma(CHILD(tree, i))
|
res = (validate_comma(CHILD(tree, i))
|
||||||
&& validate_fpdef(CHILD(tree, i+1)));
|
&& validate_fpdef(CHILD(tree, i+1)));
|
||||||
i += 2;
|
i += 2;
|
||||||
if (res && (nch - i) >= 2
|
if (res && (nch - i) >= 2 && TYPE(CHILD(tree, i)) == EQUAL) {
|
||||||
&& TYPE(CHILD(tree, i)) == COMMA) {
|
res = (validate_equal(CHILD(tree, i))
|
||||||
res = (validate_comma(CHILD(tree, i))
|
|
||||||
&& validate_test(CHILD(tree, i+1)));
|
&& validate_test(CHILD(tree, i+1)));
|
||||||
if (res)
|
|
||||||
i += 2;
|
i += 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue