summaryrefslogtreecommitdiff
path: root/Grammar
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2021-12-14 16:48:15 +0000
committerGitHub <noreply@github.com>2021-12-14 16:48:15 +0000
commitd60457a6673cf0263213c2f2be02c633ec2e2038 (patch)
tree04461db9079cf30a98c5a4070098f795275aa910 /Grammar
parent850aefc2c651110a784cd5478af9774b1f6287a3 (diff)
downloadcpython-git-d60457a6673cf0263213c2f2be02c633ec2e2038.tar.gz
bpo-45292: [PEP-654] add except* (GH-29581)
Diffstat (limited to 'Grammar')
-rw-r--r--Grammar/python.gram17
1 files changed, 15 insertions, 2 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram
index 2c696a6a08..c989823e30 100644
--- a/Grammar/python.gram
+++ b/Grammar/python.gram
@@ -403,6 +403,8 @@ try_stmt[stmt_ty]:
| invalid_try_stmt
| 'try' &&':' b=block f=finally_block { _PyAST_Try(b, NULL, NULL, f, EXTRA) }
| 'try' &&':' b=block ex[asdl_excepthandler_seq*]=except_block+ el=[else_block] f=[finally_block] { _PyAST_Try(b, ex, el, f, EXTRA) }
+ | 'try' &&':' b=block ex[asdl_excepthandler_seq*]=except_star_block+ el=[else_block] f=[finally_block] { _PyAST_TryStar(b, ex, el, f, EXTRA) }
+
# Except statement
# ----------------
@@ -413,6 +415,11 @@ except_block[excepthandler_ty]:
_PyAST_ExceptHandler(e, (t) ? ((expr_ty) t)->v.Name.id : NULL, b, EXTRA) }
| 'except' ':' b=block { _PyAST_ExceptHandler(NULL, NULL, b, EXTRA) }
| invalid_except_stmt
+except_star_block[excepthandler_ty]:
+ | invalid_except_star_stmt_indent
+ | 'except' '*' e=expression t=['as' z=NAME { z }] ':' b=block {
+ _PyAST_ExceptHandler(e, (t) ? ((expr_ty) t)->v.Name.id : NULL, b, EXTRA) }
+ | invalid_except_stmt
finally_block[asdl_stmt_seq*]:
| invalid_finally_stmt
| 'finally' &&':' a=block { a }
@@ -1192,11 +1199,14 @@ invalid_try_stmt:
| a='try' ':' NEWLINE !INDENT {
RAISE_INDENTATION_ERROR("expected an indented block after 'try' statement on line %d", a->lineno) }
| 'try' ':' block !('except' | 'finally') { RAISE_SYNTAX_ERROR("expected 'except' or 'finally' block") }
+ | 'try' ':' block* ((except_block+ except_star_block) | (except_star_block+ except_block)) block* {
+ RAISE_SYNTAX_ERROR("cannot have both 'except' and 'except*' on the same 'try'") }
invalid_except_stmt:
- | 'except' a=expression ',' expressions ['as' NAME ] ':' {
+ | 'except' '*'? a=expression ',' expressions ['as' NAME ] ':' {
RAISE_SYNTAX_ERROR_STARTING_FROM(a, "multiple exception types must be parenthesized") }
- | a='except' expression ['as' NAME ] NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
+ | a='except' '*'? expression ['as' NAME ] NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
| a='except' NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
+ | a='except' '*' (NEWLINE | ':') { RAISE_SYNTAX_ERROR("expected one or more exception types") }
invalid_finally_stmt:
| a='finally' ':' NEWLINE !INDENT {
RAISE_INDENTATION_ERROR("expected an indented block after 'finally' statement on line %d", a->lineno) }
@@ -1204,6 +1214,9 @@ invalid_except_stmt_indent:
| a='except' expression ['as' NAME ] ':' NEWLINE !INDENT {
RAISE_INDENTATION_ERROR("expected an indented block after 'except' statement on line %d", a->lineno) }
| a='except' ':' NEWLINE !INDENT { RAISE_SYNTAX_ERROR("expected an indented block after except statement on line %d", a->lineno) }
+invalid_except_star_stmt_indent:
+ | a='except' '*' expression ['as' NAME ] ':' NEWLINE !INDENT {
+ RAISE_INDENTATION_ERROR("expected an indented block after 'except*' statement on line %d", a->lineno) }
invalid_match_stmt:
| "match" subject_expr !':' { CHECK_VERSION(void*, 10, "Pattern matching is", RAISE_SYNTAX_ERROR("expected ':'") ) }
| a="match" subject=subject_expr ':' NEWLINE !INDENT {