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.
This commit is contained in:
parent
a0a6c5a042
commit
2d3b986480
|
@ -80,7 +80,7 @@ arith_expr: term (('+'|'-') term)*
|
|||
term: factor (('*'|'/'|'%'|'//') factor)*
|
||||
factor: ('+'|'-'|'~') factor | power
|
||||
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)* [','] )
|
||||
lambdef: 'lambda' [varargslist] ':' test
|
||||
trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
|
||||
|
@ -100,3 +100,5 @@ argument: [test '='] test # Really [keyword '='] test
|
|||
list_iter: list_for | list_if
|
||||
list_for: 'for' exprlist 'in' testlist_safe [list_iter]
|
||||
list_if: 'if' test [list_iter]
|
||||
|
||||
testlist1: test (',' test)*
|
||||
|
|
|
@ -64,3 +64,4 @@
|
|||
#define list_iter 319
|
||||
#define list_for 320
|
||||
#define list_if 321
|
||||
#define testlist1 322
|
||||
|
|
|
@ -844,6 +844,7 @@ VALIDATER(subscriptlist); VALIDATER(sliceop);
|
|||
VALIDATER(exprlist); VALIDATER(dictmaker);
|
||||
VALIDATER(arglist); VALIDATER(argument);
|
||||
VALIDATER(listmaker); VALIDATER(yield_stmt);
|
||||
VALIDATER(testlist1);
|
||||
|
||||
#undef VALIDATER
|
||||
|
||||
|
@ -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
|
||||
validate_testlist_safe(node *tree)
|
||||
{
|
||||
|
@ -2185,7 +2194,7 @@ validate_atom(node *tree)
|
|||
break;
|
||||
case BACKQUOTE:
|
||||
res = ((nch == 3)
|
||||
&& validate_testlist(CHILD(tree, 1))
|
||||
&& validate_testlist1(CHILD(tree, 1))
|
||||
&& validate_ntype(CHILD(tree, 2), BACKQUOTE));
|
||||
break;
|
||||
case NAME:
|
||||
|
@ -2671,6 +2680,9 @@ validate_node(node *tree)
|
|||
case testlist:
|
||||
res = validate_testlist(tree);
|
||||
break;
|
||||
case testlist1:
|
||||
res = validate_testlist1(tree);
|
||||
break;
|
||||
case test:
|
||||
res = validate_test(tree);
|
||||
break;
|
||||
|
|
|
@ -2474,6 +2474,7 @@ com_assign(struct compiling *c, node *n, int assigning, node *augn)
|
|||
|
||||
case exprlist:
|
||||
case testlist:
|
||||
case testlist1:
|
||||
if (NCH(n) > 1) {
|
||||
if (assigning > OP_APPLY) {
|
||||
com_error(c, PyExc_SyntaxError,
|
||||
|
@ -2955,6 +2956,7 @@ is_constant_false(struct compiling *c, node *n)
|
|||
|
||||
case expr_stmt:
|
||||
case testlist:
|
||||
case testlist1:
|
||||
case test:
|
||||
case and_test:
|
||||
case not_test:
|
||||
|
@ -3356,6 +3358,7 @@ get_rawdocstring(node *n)
|
|||
|
||||
case expr_stmt:
|
||||
case testlist:
|
||||
case testlist1:
|
||||
case test:
|
||||
case and_test:
|
||||
case not_test:
|
||||
|
@ -3704,6 +3707,7 @@ com_node(struct compiling *c, node *n)
|
|||
/* Expression nodes */
|
||||
|
||||
case testlist:
|
||||
case testlist1:
|
||||
case testlist_safe:
|
||||
com_list(c, n, 0);
|
||||
break;
|
||||
|
@ -5447,6 +5451,7 @@ symtable_assign(struct symtable *st, node *n, int def_flag)
|
|||
return;
|
||||
case exprlist:
|
||||
case testlist:
|
||||
case testlist1:
|
||||
if (NCH(n) == 1) {
|
||||
n = CHILD(n, 0);
|
||||
goto loop;
|
||||
|
|
|
@ -1020,8 +1020,8 @@ static arc arcs_49_0[7] = {
|
|||
{130, 3},
|
||||
{133, 4},
|
||||
{12, 5},
|
||||
{134, 5},
|
||||
{135, 6},
|
||||
{135, 5},
|
||||
{136, 6},
|
||||
};
|
||||
static arc arcs_49_1[2] = {
|
||||
{9, 7},
|
||||
|
@ -1036,13 +1036,13 @@ static arc arcs_49_3[2] = {
|
|||
{132, 5},
|
||||
};
|
||||
static arc arcs_49_4[1] = {
|
||||
{9, 10},
|
||||
{134, 10},
|
||||
};
|
||||
static arc arcs_49_5[1] = {
|
||||
{0, 5},
|
||||
};
|
||||
static arc arcs_49_6[2] = {
|
||||
{135, 6},
|
||||
{136, 6},
|
||||
{0, 6},
|
||||
};
|
||||
static arc arcs_49_7[1] = {
|
||||
|
@ -1074,7 +1074,7 @@ static arc arcs_50_0[1] = {
|
|||
{21, 1},
|
||||
};
|
||||
static arc arcs_50_1[3] = {
|
||||
{136, 2},
|
||||
{137, 2},
|
||||
{22, 3},
|
||||
{0, 1},
|
||||
};
|
||||
|
@ -1097,7 +1097,7 @@ static state states_50[5] = {
|
|||
{2, arcs_50_4},
|
||||
};
|
||||
static arc arcs_51_0[1] = {
|
||||
{137, 1},
|
||||
{138, 1},
|
||||
};
|
||||
static arc arcs_51_1[2] = {
|
||||
{17, 2},
|
||||
|
@ -1125,11 +1125,11 @@ static arc arcs_52_0[3] = {
|
|||
{70, 3},
|
||||
};
|
||||
static arc arcs_52_1[2] = {
|
||||
{138, 4},
|
||||
{139, 4},
|
||||
{18, 5},
|
||||
};
|
||||
static arc arcs_52_2[1] = {
|
||||
{139, 6},
|
||||
{140, 6},
|
||||
};
|
||||
static arc arcs_52_3[1] = {
|
||||
{12, 5},
|
||||
|
@ -1153,14 +1153,14 @@ static state states_52[7] = {
|
|||
{1, arcs_52_6},
|
||||
};
|
||||
static arc arcs_53_0[1] = {
|
||||
{140, 1},
|
||||
{141, 1},
|
||||
};
|
||||
static arc arcs_53_1[2] = {
|
||||
{22, 2},
|
||||
{0, 1},
|
||||
};
|
||||
static arc arcs_53_2[2] = {
|
||||
{140, 1},
|
||||
{141, 1},
|
||||
{0, 2},
|
||||
};
|
||||
static state states_53[3] = {
|
||||
|
@ -1182,14 +1182,14 @@ static arc arcs_54_2[2] = {
|
|||
};
|
||||
static arc arcs_54_3[3] = {
|
||||
{21, 5},
|
||||
{141, 6},
|
||||
{142, 6},
|
||||
{0, 3},
|
||||
};
|
||||
static arc arcs_54_4[1] = {
|
||||
{70, 6},
|
||||
};
|
||||
static arc arcs_54_5[2] = {
|
||||
{141, 6},
|
||||
{142, 6},
|
||||
{0, 5},
|
||||
};
|
||||
static arc arcs_54_6[1] = {
|
||||
|
@ -1301,7 +1301,7 @@ static state states_59[5] = {
|
|||
{2, arcs_59_4},
|
||||
};
|
||||
static arc arcs_60_0[1] = {
|
||||
{143, 1},
|
||||
{144, 1},
|
||||
};
|
||||
static arc arcs_60_1[1] = {
|
||||
{12, 2},
|
||||
|
@ -1336,7 +1336,7 @@ static state states_60[8] = {
|
|||
{1, arcs_60_7},
|
||||
};
|
||||
static arc arcs_61_0[3] = {
|
||||
{144, 1},
|
||||
{145, 1},
|
||||
{23, 2},
|
||||
{24, 3},
|
||||
};
|
||||
|
@ -1351,7 +1351,7 @@ static arc arcs_61_3[1] = {
|
|||
{21, 6},
|
||||
};
|
||||
static arc arcs_61_4[4] = {
|
||||
{144, 1},
|
||||
{145, 1},
|
||||
{23, 2},
|
||||
{24, 3},
|
||||
{0, 4},
|
||||
|
@ -1396,8 +1396,8 @@ static state states_62[4] = {
|
|||
{1, arcs_62_3},
|
||||
};
|
||||
static arc arcs_63_0[2] = {
|
||||
{136, 1},
|
||||
{146, 1},
|
||||
{137, 1},
|
||||
{147, 1},
|
||||
};
|
||||
static arc arcs_63_1[1] = {
|
||||
{0, 1},
|
||||
|
@ -1416,10 +1416,10 @@ static arc arcs_64_2[1] = {
|
|||
{74, 3},
|
||||
};
|
||||
static arc arcs_64_3[1] = {
|
||||
{142, 4},
|
||||
{143, 4},
|
||||
};
|
||||
static arc arcs_64_4[2] = {
|
||||
{145, 5},
|
||||
{146, 5},
|
||||
{0, 4},
|
||||
};
|
||||
static arc arcs_64_5[1] = {
|
||||
|
@ -1440,7 +1440,7 @@ static arc arcs_65_1[1] = {
|
|||
{21, 2},
|
||||
};
|
||||
static arc arcs_65_2[2] = {
|
||||
{145, 3},
|
||||
{146, 3},
|
||||
{0, 2},
|
||||
};
|
||||
static arc arcs_65_3[1] = {
|
||||
|
@ -1452,13 +1452,24 @@ static state states_65[4] = {
|
|||
{2, arcs_65_2},
|
||||
{1, arcs_65_3},
|
||||
};
|
||||
static dfa dfas[66] = {
|
||||
static arc arcs_66_0[1] = {
|
||||
{21, 1},
|
||||
};
|
||||
static arc arcs_66_1[2] = {
|
||||
{22, 0},
|
||||
{0, 1},
|
||||
};
|
||||
static state states_66[2] = {
|
||||
{1, arcs_66_0},
|
||||
{2, arcs_66_1},
|
||||
};
|
||||
static dfa dfas[67] = {
|
||||
{256, "single_input", 0, 3, states_0,
|
||||
"\004\030\001\000\000\000\124\360\213\011\162\000\002\000\140\210\344\202\000"},
|
||||
"\004\030\001\000\000\000\124\360\213\011\162\000\002\000\140\210\244\005\001"},
|
||||
{257, "file_input", 0, 2, states_1,
|
||||
"\204\030\001\000\000\000\124\360\213\011\162\000\002\000\140\210\344\202\000"},
|
||||
"\204\030\001\000\000\000\124\360\213\011\162\000\002\000\140\210\244\005\001"},
|
||||
{258, "eval_input", 0, 3, states_2,
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\002\000\140\210\344\002\000"},
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\002\000\140\210\244\005\000"},
|
||||
{259, "funcdef", 0, 6, states_3,
|
||||
"\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
|
||||
{260, "parameters", 0, 4, states_4,
|
||||
|
@ -1470,13 +1481,13 @@ static dfa dfas[66] = {
|
|||
{263, "fplist", 0, 3, states_7,
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
|
||||
{264, "stmt", 0, 2, states_8,
|
||||
"\000\030\001\000\000\000\124\360\213\011\162\000\002\000\140\210\344\202\000"},
|
||||
"\000\030\001\000\000\000\124\360\213\011\162\000\002\000\140\210\244\005\001"},
|
||||
{265, "simple_stmt", 0, 4, states_9,
|
||||
"\000\020\001\000\000\000\124\360\213\011\000\000\002\000\140\210\344\002\000"},
|
||||
"\000\020\001\000\000\000\124\360\213\011\000\000\002\000\140\210\244\005\000"},
|
||||
{266, "small_stmt", 0, 2, states_10,
|
||||
"\000\020\001\000\000\000\124\360\213\011\000\000\002\000\140\210\344\002\000"},
|
||||
"\000\020\001\000\000\000\124\360\213\011\000\000\002\000\140\210\244\005\000"},
|
||||
{267, "expr_stmt", 0, 6, states_11,
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\002\000\140\210\344\002\000"},
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\002\000\140\210\244\005\000"},
|
||||
{268, "augassign", 0, 2, states_12,
|
||||
"\000\000\000\000\300\377\003\000\000\000\000\000\000\000\000\000\000\000\000"},
|
||||
{269, "print_stmt", 0, 9, states_13,
|
||||
|
@ -1512,7 +1523,7 @@ static dfa dfas[66] = {
|
|||
{284, "assert_stmt", 0, 5, states_28,
|
||||
"\000\000\000\000\000\000\000\000\000\010\000\000\000\000\000\000\000\000\000"},
|
||||
{285, "compound_stmt", 0, 2, states_29,
|
||||
"\000\010\000\000\000\000\000\000\000\000\162\000\000\000\000\000\000\200\000"},
|
||||
"\000\010\000\000\000\000\000\000\000\000\162\000\000\000\000\000\000\000\001"},
|
||||
{286, "if_stmt", 0, 8, states_30,
|
||||
"\000\000\000\000\000\000\000\000\000\000\002\000\000\000\000\000\000\000\000"},
|
||||
{287, "while_stmt", 0, 8, states_31,
|
||||
|
@ -1524,69 +1535,71 @@ static dfa dfas[66] = {
|
|||
{290, "except_clause", 0, 5, states_34,
|
||||
"\000\000\000\000\000\000\000\000\000\000\000\002\000\000\000\000\000\000\000"},
|
||||
{291, "suite", 0, 5, states_35,
|
||||
"\004\020\001\000\000\000\124\360\213\011\000\000\002\000\140\210\344\002\000"},
|
||||
"\004\020\001\000\000\000\124\360\213\011\000\000\002\000\140\210\244\005\000"},
|
||||
{292, "test", 0, 4, states_36,
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\002\000\140\210\344\002\000"},
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\002\000\140\210\244\005\000"},
|
||||
{293, "and_test", 0, 2, states_37,
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\002\000\140\210\344\000\000"},
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\002\000\140\210\244\001\000"},
|
||||
{294, "not_test", 0, 3, states_38,
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\002\000\140\210\344\000\000"},
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\002\000\140\210\244\001\000"},
|
||||
{295, "comparison", 0, 2, states_39,
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\000\000\140\210\344\000\000"},
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\000\000\140\210\244\001\000"},
|
||||
{296, "comp_op", 0, 4, states_40,
|
||||
"\000\000\000\000\000\000\000\000\000\004\000\000\362\017\000\000\000\000\000"},
|
||||
{297, "expr", 0, 2, states_41,
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\000\000\140\210\344\000\000"},
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\000\000\140\210\244\001\000"},
|
||||
{298, "xor_expr", 0, 2, states_42,
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\000\000\140\210\344\000\000"},
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\000\000\140\210\244\001\000"},
|
||||
{299, "and_expr", 0, 2, states_43,
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\000\000\140\210\344\000\000"},
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\000\000\140\210\244\001\000"},
|
||||
{300, "shift_expr", 0, 2, states_44,
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\000\000\140\210\344\000\000"},
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\000\000\140\210\244\001\000"},
|
||||
{301, "arith_expr", 0, 2, states_45,
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\000\000\140\210\344\000\000"},
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\000\000\140\210\244\001\000"},
|
||||
{302, "term", 0, 2, states_46,
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\000\000\140\210\344\000\000"},
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\000\000\140\210\244\001\000"},
|
||||
{303, "factor", 0, 3, states_47,
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\000\000\140\210\344\000\000"},
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\000\000\140\210\244\001\000"},
|
||||
{304, "power", 0, 4, states_48,
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\000\000\000\200\344\000\000"},
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\000\000\000\200\244\001\000"},
|
||||
{305, "atom", 0, 11, states_49,
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\000\000\000\200\344\000\000"},
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\000\000\000\200\244\001\000"},
|
||||
{306, "listmaker", 0, 5, states_50,
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\002\000\140\210\344\002\000"},
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\002\000\140\210\244\005\000"},
|
||||
{307, "lambdef", 0, 5, states_51,
|
||||
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\002\000"},
|
||||
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\004\000"},
|
||||
{308, "trailer", 0, 7, states_52,
|
||||
"\000\000\001\000\000\000\000\000\100\000\000\000\000\000\000\200\000\000\000"},
|
||||
{309, "subscriptlist", 0, 3, states_53,
|
||||
"\000\120\001\000\000\000\000\000\100\000\000\000\002\000\140\210\344\002\000"},
|
||||
"\000\120\001\000\000\000\000\000\100\000\000\000\002\000\140\210\244\005\000"},
|
||||
{310, "subscript", 0, 7, states_54,
|
||||
"\000\120\001\000\000\000\000\000\100\000\000\000\002\000\140\210\344\002\000"},
|
||||
"\000\120\001\000\000\000\000\000\100\000\000\000\002\000\140\210\244\005\000"},
|
||||
{311, "sliceop", 0, 3, states_55,
|
||||
"\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
|
||||
{312, "exprlist", 0, 3, states_56,
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\000\000\140\210\344\000\000"},
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\000\000\140\210\244\001\000"},
|
||||
{313, "testlist", 0, 3, states_57,
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\002\000\140\210\344\002\000"},
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\002\000\140\210\244\005\000"},
|
||||
{314, "testlist_safe", 0, 5, states_58,
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\002\000\140\210\344\002\000"},
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\002\000\140\210\244\005\000"},
|
||||
{315, "dictmaker", 0, 5, states_59,
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\002\000\140\210\344\002\000"},
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\002\000\140\210\244\005\000"},
|
||||
{316, "classdef", 0, 8, states_60,
|
||||
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\200\000"},
|
||||
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\001"},
|
||||
{317, "arglist", 0, 8, states_61,
|
||||
"\000\020\201\001\000\000\000\000\000\000\000\000\002\000\140\210\344\002\000"},
|
||||
"\000\020\201\001\000\000\000\000\000\000\000\000\002\000\140\210\244\005\000"},
|
||||
{318, "argument", 0, 4, states_62,
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\002\000\140\210\344\002\000"},
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\002\000\140\210\244\005\000"},
|
||||
{319, "list_iter", 0, 2, states_63,
|
||||
"\000\000\000\000\000\000\000\000\000\000\042\000\000\000\000\000\000\000\000"},
|
||||
{320, "list_for", 0, 6, states_64,
|
||||
"\000\000\000\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000\000"},
|
||||
{321, "list_if", 0, 4, states_65,
|
||||
"\000\000\000\000\000\000\000\000\000\000\002\000\000\000\000\000\000\000\000"},
|
||||
{322, "testlist1", 0, 2, states_66,
|
||||
"\000\020\001\000\000\000\000\000\000\000\000\000\002\000\140\210\244\005\000"},
|
||||
};
|
||||
static label labels[147] = {
|
||||
static label labels[148] = {
|
||||
{0, "EMPTY"},
|
||||
{256, 0},
|
||||
{4, 0},
|
||||
|
@ -1721,6 +1734,7 @@ static label labels[147] = {
|
|||
{315, 0},
|
||||
{27, 0},
|
||||
{25, 0},
|
||||
{322, 0},
|
||||
{2, 0},
|
||||
{3, 0},
|
||||
{320, 0},
|
||||
|
@ -1736,8 +1750,8 @@ static label labels[147] = {
|
|||
{321, 0},
|
||||
};
|
||||
grammar _PyParser_Grammar = {
|
||||
66,
|
||||
67,
|
||||
dfas,
|
||||
{147, labels},
|
||||
{148, labels},
|
||||
256
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue