@@ -403,6 +403,8 @@ try_stmt[stmt_ty]:
403403 | invalid_try_stmt
404404 | 'try' &&':' b=block f=finally_block { _PyAST_Try(b, NULL, NULL, f, EXTRA) }
405405 | 'try' &&':' b=block ex[asdl_excepthandler_seq*]=except_block+ el=[else_block] f=[finally_block] { _PyAST_Try(b, ex, el, f, EXTRA) }
406+ | 'try' &&':' b=block ex[asdl_excepthandler_seq*]=except_star_block+ el=[else_block] f=[finally_block] { _PyAST_TryStar(b, ex, el, f, EXTRA) }
407+
406408
407409# Except statement
408410# ----------------
@@ -413,6 +415,11 @@ except_block[excepthandler_ty]:
413415 _PyAST_ExceptHandler(e, (t) ? ((expr_ty) t)->v.Name.id : NULL, b, EXTRA) }
414416 | 'except' ':' b=block { _PyAST_ExceptHandler(NULL, NULL, b, EXTRA) }
415417 | invalid_except_stmt
418+ except_star_block[excepthandler_ty]:
419+ | invalid_except_star_stmt_indent
420+ | 'except' '*' e=expression t=['as' z=NAME { z }] ':' b=block {
421+ _PyAST_ExceptHandler(e, (t) ? ((expr_ty) t)->v.Name.id : NULL, b, EXTRA) }
422+ | invalid_except_stmt
416423finally_block[asdl_stmt_seq*]:
417424 | invalid_finally_stmt
418425 | 'finally' &&':' a=block { a }
@@ -1192,18 +1199,24 @@ invalid_try_stmt:
11921199 | a='try' ':' NEWLINE !INDENT {
11931200 RAISE_INDENTATION_ERROR("expected an indented block after 'try' statement on line %d", a->lineno) }
11941201 | 'try' ':' block !('except' | 'finally') { RAISE_SYNTAX_ERROR("expected 'except' or 'finally' block") }
1202+ | 'try' ':' block* ((except_block+ except_star_block) | (except_star_block+ except_block)) block* {
1203+ RAISE_SYNTAX_ERROR("cannot have both 'except' and 'except*' on the same 'try'") }
11951204invalid_except_stmt:
1196- | 'except' a=expression ',' expressions ['as' NAME ] ':' {
1205+ | 'except' '*'? a=expression ',' expressions ['as' NAME ] ':' {
11971206 RAISE_SYNTAX_ERROR_STARTING_FROM(a, "multiple exception types must be parenthesized") }
1198- | a='except' expression ['as' NAME ] NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
1207+ | a='except' '*'? expression ['as' NAME ] NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
11991208 | a='except' NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
1209+ | a='except' '*' (NEWLINE | ':') { RAISE_SYNTAX_ERROR("expected one or more exception types") }
12001210invalid_finally_stmt:
12011211 | a='finally' ':' NEWLINE !INDENT {
12021212 RAISE_INDENTATION_ERROR("expected an indented block after 'finally' statement on line %d", a->lineno) }
12031213invalid_except_stmt_indent:
12041214 | a='except' expression ['as' NAME ] ':' NEWLINE !INDENT {
12051215 RAISE_INDENTATION_ERROR("expected an indented block after 'except' statement on line %d", a->lineno) }
12061216 | a='except' ':' NEWLINE !INDENT { RAISE_SYNTAX_ERROR("expected an indented block after except statement on line %d", a->lineno) }
1217+ invalid_except_star_stmt_indent:
1218+ | a='except' '*' expression ['as' NAME ] ':' NEWLINE !INDENT {
1219+ RAISE_INDENTATION_ERROR("expected an indented block after 'except*' statement on line %d", a->lineno) }
12071220invalid_match_stmt:
12081221 | "match" subject_expr !':' { CHECK_VERSION(void*, 10, "Pattern matching is", RAISE_SYNTAX_ERROR("expected ':'") ) }
12091222 | a="match" subject=subject_expr ':' NEWLINE !INDENT {
0 commit comments