@@ -435,14 +435,18 @@ try_stmt[stmt_ty]:
435
435
436
436
except_block[excepthandler_ty]:
437
437
| invalid_except_stmt_indent
438
- | 'except' e=expression t=['as' z=NAME { z }] ':' b=block {
439
- _PyAST_ExceptHandler(e, (t) ? ((expr_ty) t)->v.Name.id : NULL, b, EXTRA) }
438
+ | 'except' e=expressions ':' b=block {
439
+ _PyAST_ExceptHandler(e, NULL, b, EXTRA) }
440
+ | 'except' e=expression 'as' t=NAME ':' b=block {
441
+ _PyAST_ExceptHandler(e, ((expr_ty) t)->v.Name.id, b, EXTRA) }
440
442
| 'except' ':' b=block { _PyAST_ExceptHandler(NULL, NULL, b, EXTRA) }
441
443
| invalid_except_stmt
442
444
except_star_block[excepthandler_ty]:
443
445
| invalid_except_star_stmt_indent
444
- | 'except' '*' e=expression t=['as' z=NAME { z }] ':' b=block {
445
- _PyAST_ExceptHandler(e, (t) ? ((expr_ty) t)->v.Name.id : NULL, b, EXTRA) }
446
+ | 'except' '*' e=expressions ':' b=block {
447
+ _PyAST_ExceptHandler(e, NULL, b, EXTRA) }
448
+ | 'except' '*' e=expression 'as' t=NAME ':' b=block {
449
+ _PyAST_ExceptHandler(e, ((expr_ty) t)->v.Name.id, b, EXTRA) }
446
450
| invalid_except_star_stmt
447
451
finally_block[asdl_stmt_seq*]:
448
452
| invalid_finally_stmt
@@ -1356,16 +1360,16 @@ invalid_try_stmt:
1356
1360
| 'try' ':' block* except_star_block+ a='except' [expression ['as' NAME]] ':' {
1357
1361
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "cannot have both 'except' and 'except*' on the same 'try'") }
1358
1362
invalid_except_stmt:
1359
- | 'except' a=expression ',' expressions [ 'as' NAME ] ':' {
1360
- RAISE_SYNTAX_ERROR_STARTING_FROM(a, "multiple exception types must be parenthesized") }
1363
+ | 'except' a=expression ',' expressions 'as' NAME ':' {
1364
+ RAISE_SYNTAX_ERROR_STARTING_FROM(a, "multiple exception types must be parenthesized when using 'as' ") }
1361
1365
| a='except' expression ['as' NAME ] NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
1362
1366
| a='except' NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
1363
1367
| 'except' expression 'as' a=expression {
1364
1368
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
1365
1369
a, "cannot use except statement with %s", _PyPegen_get_expr_name(a)) }
1366
1370
invalid_except_star_stmt:
1367
- | 'except' '*' a=expression ',' expressions [ 'as' NAME ] ':' {
1368
- RAISE_SYNTAX_ERROR_STARTING_FROM(a, "multiple exception types must be parenthesized") }
1371
+ | 'except' '*' a=expression ',' expressions 'as' NAME ':' {
1372
+ RAISE_SYNTAX_ERROR_STARTING_FROM(a, "multiple exception types must be parenthesized when using 'as' ") }
1369
1373
| a='except' '*' expression ['as' NAME ] NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
1370
1374
| a='except' '*' (NEWLINE | ':') { RAISE_SYNTAX_ERROR("expected one or more exception types") }
1371
1375
| 'except' '*' expression 'as' a=expression {
0 commit comments