@@ -402,7 +402,12 @@ with_item[withitem_ty]:
402
402
try_stmt[stmt_ty]:
403
403
| invalid_try_stmt
404
404
| 'try' &&':' b=block f=finally_block { _PyAST_Try(b, NULL, NULL, f, EXTRA) }
405
- | 'try' &&':' b=block ex[asdl_excepthandler_seq*]=except_block+ el=[else_block] f=[finally_block] { _PyAST_Try(b, ex, el, f, EXTRA) }
405
+ | 'try' &&':' b=block ex[asdl_excepthandler_seq*]=except_block+ d_ex[asdl_match_case_seq*]=[default_except_block] el=[else_block] f=[finally_block] {
406
+ _PyAST_Try(b, (d_ex) ? (asdl_excepthandler_seq*)_PyPegen_seq_append_to_end(p, (asdl_seq*)ex, d_ex) : ex, el, f, EXTRA)
407
+ }
408
+ | 'try' &&':' b=block d_ex[asdl_match_case_seq*]=default_except_block el=[else_block] f=[finally_block] {
409
+ _PyAST_Try(b, (asdl_excepthandler_seq*)_PyPegen_singleton_seq(p, d_ex), el, f, EXTRA)
410
+ }
406
411
407
412
# Except statement
408
413
# ----------------
@@ -411,8 +416,9 @@ except_block[excepthandler_ty]:
411
416
| invalid_except_stmt_indent
412
417
| 'except' e=expression t=['as' z=NAME { z }] ':' b=block {
413
418
_PyAST_ExceptHandler(e, (t) ? ((expr_ty) t)->v.Name.id : NULL, b, EXTRA) }
414
- | 'except' ':' b=block { _PyAST_ExceptHandler(NULL, NULL, b, EXTRA) }
415
419
| invalid_except_stmt
420
+ default_except_block[excepthandler_ty]:
421
+ | 'except' ':' b=block { _PyAST_ExceptHandler(NULL, NULL, b, EXTRA) }
416
422
finally_block[asdl_stmt_seq*]:
417
423
| invalid_finally_stmt
418
424
| 'finally' &&':' a=block { a }
@@ -1187,6 +1193,9 @@ invalid_try_stmt:
1187
1193
| a='try' ':' NEWLINE !INDENT {
1188
1194
RAISE_INDENTATION_ERROR("expected an indented block after 'try' statement on line %d", a->lineno) }
1189
1195
| 'try' ':' block !('except' | 'finally') { RAISE_SYNTAX_ERROR("expected 'except' or 'finally' block") }
1196
+ | 'try' ':' block except_block* a=default_except_block (except_block|default_except_block)+ {
1197
+ RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "default 'except:' must be last") }
1198
+
1190
1199
invalid_except_stmt:
1191
1200
| 'except' a=expression ',' expressions ['as' NAME ] ':' {
1192
1201
RAISE_SYNTAX_ERROR_STARTING_FROM(a, "multiple exception types must be parenthesized") }
0 commit comments