summaryrefslogtreecommitdiff
path: root/Python/ast.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-09-27 02:43:28 +0000
committerBenjamin Peterson <benjamin@python.org>2009-09-27 02:43:28 +0000
commit4905e80c3d2f6abb613d212f0313d1dfe09475dc (patch)
treedf849b7313a57c1d844567bcd45b32f7e89ac0ca /Python/ast.c
parent10430ad7aace46c93939341817b97df48951d5a2 (diff)
downloadcpython-git-4905e80c3d2f6abb613d212f0313d1dfe09475dc.tar.gz
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 'Python/ast.c')
-rw-r--r--Python/ast.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/Python/ast.c b/Python/ast.c
index fb3894449a..97b57ec100 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -603,20 +603,23 @@ ast_for_comp_op(struct compiling *c, const node *n)
static asdl_seq *
seq_for_testlist(struct compiling *c, const node *n)
{
- /* testlist: test (',' test)* [','] */
+ /* testlist: test (',' test)* [',']
+ testlist_star_expr: test|star_expr (',' test|star_expr)* [',']
+ */
asdl_seq *seq;
expr_ty expression;
int i;
- assert(TYPE(n) == testlist || TYPE(n) == testlist_comp);
+ assert(TYPE(n) == testlist || TYPE(n) == testlist_star_expr || TYPE(n) == testlist_comp);
seq = asdl_seq_new((NCH(n) + 1) / 2, c->c_arena);
if (!seq)
return NULL;
for (i = 0; i < NCH(n); i += 2) {
- assert(TYPE(CHILD(n, i)) == test || TYPE(CHILD(n, i)) == test_nocond);
+ const node *ch = CHILD(n, i);
+ assert(TYPE(ch) == test || TYPE(ch) == test_nocond || TYPE(ch) == star_expr);
- expression = ast_for_expr(c, CHILD(n, i));
+ expression = ast_for_expr(c, ch);
if (!expression)
return NULL;
@@ -1886,10 +1889,9 @@ ast_for_expr(struct compiling *c, const node *n)
break;
case star_expr:
- if (TYPE(CHILD(n, 0)) == STAR) {
- return ast_for_starred(c, n);
- }
- /* Fallthrough */
+ if (TYPE(CHILD(n, 0)) == STAR)
+ return ast_for_starred(c, n);
+ /* Fall through to generic case. */
/* The next five cases all handle BinOps. The main body of code
is the same in each case, but the switch turned inside out to
reuse the code for each type of operator.
@@ -2067,7 +2069,6 @@ ast_for_testlist(struct compiling *c, const node* n)
{
/* testlist_comp: test (comp_for | (',' test)* [',']) */
/* testlist: test (',' test)* [','] */
- /* testlist1: test (',' test)* */
assert(NCH(n) > 0);
if (TYPE(n) == testlist_comp) {
if (NCH(n) > 1)
@@ -2075,7 +2076,7 @@ ast_for_testlist(struct compiling *c, const node* n)
}
else {
assert(TYPE(n) == testlist ||
- TYPE(n) == testlist1);
+ TYPE(n) == testlist_star_expr);
}
if (NCH(n) == 1)
return ast_for_expr(c, CHILD(n, 0));
@@ -2091,9 +2092,9 @@ static stmt_ty
ast_for_expr_stmt(struct compiling *c, const node *n)
{
REQ(n, expr_stmt);
- /* expr_stmt: testlist (augassign (yield_expr|testlist)
+ /* expr_stmt: testlist_star_expr (augassign (yield_expr|testlist)
| ('=' (yield_expr|testlist))*)
- testlist: test (',' test)* [',']
+ testlist_star_expr: (test|star_expr) (',' test|star_expr)* [',']
augassign: '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^='
| '<<=' | '>>=' | '**=' | '//='
test: ... here starts the operator precendence dance
@@ -2161,7 +2162,7 @@ ast_for_expr_stmt(struct compiling *c, const node *n)
asdl_seq_SET(targets, i / 2, e);
}
value = CHILD(n, NCH(n) - 1);
- if (TYPE(value) == testlist)
+ if (TYPE(value) == testlist_star_expr)
expression = ast_for_testlist(c, value);
else
expression = ast_for_expr(c, value);