@@ -82,16 +82,10 @@ with_var: 'as' expr
8282except_clause: 'except' [test ['as' NAME]]
8383suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT
8484
85- # Backward compatibility cruft to support:
86- # [ x for x in lambda: True, lambda: False if x() ]
87- # even while also allowing:
88- # lambda x: 5 if x else 2
89- # (But not a mix of the two)
90- testlist_safe: old_test [(',' old_test)+ [',']]
91- old_test: or_test | old_lambdef
92- old_lambdef: 'lambda' [varargslist] ':' old_test
93-
9485test: or_test ['if' or_test 'else' test] | lambdef
86+ test_nocond: or_test | lambdef_nocond
87+ lambdef: 'lambda' [varargslist] ':' test
88+ lambdef_nocond: 'lambda' [varargslist] ':' test_nocond
9589or_test: and_test ('or' and_test)*
9690and_test: not_test ('and' not_test)*
9791not_test: 'not' not_test | comparison
@@ -105,33 +99,28 @@ arith_expr: term (('+'|'-') term)*
10599term: factor (('*'|'/'|'%'|'//') factor)*
106100factor: ('+'|'-'|'~') factor | power
107101power: atom trailer* ['**' factor]
108- atom: ('(' [yield_expr|testlist_gexp ] ')' |
109- '[' [listmaker ] ']' |
110- '{' [dictsetmaker ] '}' |
102+ atom: ('(' [yield_expr|testlist_comp ] ')' |
103+ '[' [testlist_comp ] ']' |
104+ '{' [dictorsetmaker ] '}' |
111105 NAME | NUMBER | STRING+ | '...')
112- listmaker: test ( list_for | (',' test)* [','] )
113- testlist_gexp: test ( gen_for | (',' test)* [','] )
114- lambdef: 'lambda' [varargslist] ':' test
106+ testlist_comp: test ( comp_for | (',' test)* [','] )
115107trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
116108subscriptlist: subscript (',' subscript)* [',']
117109subscript: test | [test] ':' [test] [sliceop]
118110sliceop: ':' [test]
119111exprlist: expr (',' expr)* [',']
120112testlist: test (',' test)* [',']
121- dictsetmaker: (test ':' test (',' test ':' test)* [',']) | (test (',' test)* [','])
113+ dictorsetmaker: ( (test ':' test (',' test ':' test)* [',']) |
114+ (test (comp_for | (',' test)* [','])) )
122115
123116classdef: 'class' NAME ['(' [arglist] ')'] ':' suite
124117
125118arglist: (argument ',')* (argument [',']| '*' test [',' '**' test] | '**' test)
126- argument: test [gen_for] | test '=' test # Really [keyword '='] test
127-
128- list_iter: list_for | list_if
129- list_for: 'for' exprlist 'in' testlist_safe [list_iter]
130- list_if: 'if' old_test [list_iter]
119+ argument: test [comp_for] | test '=' test # Really [keyword '='] test
131120
132- gen_iter: gen_for | gen_if
133- gen_for : 'for' exprlist 'in' or_test [gen_iter ]
134- gen_if : 'if' old_test [gen_iter ]
121+ comp_iter: comp_for | comp_if
122+ comp_for : 'for' exprlist 'in' or_test [comp_iter ]
123+ comp_if : 'if' test_nocond [comp_iter ]
135124
136125testlist1: test (',' test)*
137126
0 commit comments