Commit 2d3b9864 authored by Guido van Rossum's avatar Guido van Rossum

Disambiguate the grammar for backtick.

The old syntax suggested that a trailing comma was OK inside backticks,
but in fact (due to ideosyncrasies of pgen) it was not.  Fix the grammar
to avoid the ambiguity.  Fred: you may want to update the refman.
parent a0a6c5a0
...@@ -80,7 +80,7 @@ arith_expr: term (('+'|'-') term)* ...@@ -80,7 +80,7 @@ arith_expr: term (('+'|'-') term)*
term: factor (('*'|'/'|'%'|'//') factor)* term: factor (('*'|'/'|'%'|'//') factor)*
factor: ('+'|'-'|'~') factor | power factor: ('+'|'-'|'~') factor | power
power: atom trailer* ['**' factor] power: atom trailer* ['**' factor]
atom: '(' [testlist] ')' | '[' [listmaker] ']' | '{' [dictmaker] '}' | '`' testlist '`' | NAME | NUMBER | STRING+ atom: '(' [testlist] ')' | '[' [listmaker] ']' | '{' [dictmaker] '}' | '`' testlist1 '`' | NAME | NUMBER | STRING+
listmaker: test ( list_for | (',' test)* [','] ) listmaker: test ( list_for | (',' test)* [','] )
lambdef: 'lambda' [varargslist] ':' test lambdef: 'lambda' [varargslist] ':' test
trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
...@@ -100,3 +100,5 @@ argument: [test '='] test # Really [keyword '='] test ...@@ -100,3 +100,5 @@ argument: [test '='] test # Really [keyword '='] test
list_iter: list_for | list_if list_iter: list_for | list_if
list_for: 'for' exprlist 'in' testlist_safe [list_iter] list_for: 'for' exprlist 'in' testlist_safe [list_iter]
list_if: 'if' test [list_iter] list_if: 'if' test [list_iter]
testlist1: test (',' test)*
...@@ -64,3 +64,4 @@ ...@@ -64,3 +64,4 @@
#define list_iter 319 #define list_iter 319
#define list_for 320 #define list_for 320
#define list_if 321 #define list_if 321
#define testlist1 322
...@@ -844,6 +844,7 @@ VALIDATER(subscriptlist); VALIDATER(sliceop); ...@@ -844,6 +844,7 @@ VALIDATER(subscriptlist); VALIDATER(sliceop);
VALIDATER(exprlist); VALIDATER(dictmaker); VALIDATER(exprlist); VALIDATER(dictmaker);
VALIDATER(arglist); VALIDATER(argument); VALIDATER(arglist); VALIDATER(argument);
VALIDATER(listmaker); VALIDATER(yield_stmt); VALIDATER(listmaker); VALIDATER(yield_stmt);
VALIDATER(testlist1);
#undef VALIDATER #undef VALIDATER
...@@ -1056,6 +1057,14 @@ validate_testlist(node *tree) ...@@ -1056,6 +1057,14 @@ validate_testlist(node *tree)
} }
static int
validate_testlist1(node *tree)
{
return (validate_repeating_list(tree, testlist1,
validate_test, "testlist1"));
}
static int static int
validate_testlist_safe(node *tree) validate_testlist_safe(node *tree)
{ {
...@@ -2185,7 +2194,7 @@ validate_atom(node *tree) ...@@ -2185,7 +2194,7 @@ validate_atom(node *tree)
break; break;
case BACKQUOTE: case BACKQUOTE:
res = ((nch == 3) res = ((nch == 3)
&& validate_testlist(CHILD(tree, 1)) && validate_testlist1(CHILD(tree, 1))
&& validate_ntype(CHILD(tree, 2), BACKQUOTE)); && validate_ntype(CHILD(tree, 2), BACKQUOTE));
break; break;
case NAME: case NAME:
...@@ -2671,6 +2680,9 @@ validate_node(node *tree) ...@@ -2671,6 +2680,9 @@ validate_node(node *tree)
case testlist: case testlist:
res = validate_testlist(tree); res = validate_testlist(tree);
break; break;
case testlist1:
res = validate_testlist1(tree);
break;
case test: case test:
res = validate_test(tree); res = validate_test(tree);
break; break;
......
...@@ -2474,6 +2474,7 @@ com_assign(struct compiling *c, node *n, int assigning, node *augn) ...@@ -2474,6 +2474,7 @@ com_assign(struct compiling *c, node *n, int assigning, node *augn)
case exprlist: case exprlist:
case testlist: case testlist:
case testlist1:
if (NCH(n) > 1) { if (NCH(n) > 1) {
if (assigning > OP_APPLY) { if (assigning > OP_APPLY) {
com_error(c, PyExc_SyntaxError, com_error(c, PyExc_SyntaxError,
...@@ -2955,6 +2956,7 @@ is_constant_false(struct compiling *c, node *n) ...@@ -2955,6 +2956,7 @@ is_constant_false(struct compiling *c, node *n)
case expr_stmt: case expr_stmt:
case testlist: case testlist:
case testlist1:
case test: case test:
case and_test: case and_test:
case not_test: case not_test:
...@@ -3356,6 +3358,7 @@ get_rawdocstring(node *n) ...@@ -3356,6 +3358,7 @@ get_rawdocstring(node *n)
case expr_stmt: case expr_stmt:
case testlist: case testlist:
case testlist1:
case test: case test:
case and_test: case and_test:
case not_test: case not_test:
...@@ -3704,6 +3707,7 @@ com_node(struct compiling *c, node *n) ...@@ -3704,6 +3707,7 @@ com_node(struct compiling *c, node *n)
/* Expression nodes */ /* Expression nodes */
case testlist: case testlist:
case testlist1:
case testlist_safe: case testlist_safe:
com_list(c, n, 0); com_list(c, n, 0);
break; break;
...@@ -5447,6 +5451,7 @@ symtable_assign(struct symtable *st, node *n, int def_flag) ...@@ -5447,6 +5451,7 @@ symtable_assign(struct symtable *st, node *n, int def_flag)
return; return;
case exprlist: case exprlist:
case testlist: case testlist:
case testlist1:
if (NCH(n) == 1) { if (NCH(n) == 1) {
n = CHILD(n, 0); n = CHILD(n, 0);
goto loop; goto loop;
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment