Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Grammar/python.gram
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ simple_stmt[stmt_ty] (memo):
compound_stmt[stmt_ty]:
| &('def' | '@' | 'async') function_def
| &'if' if_stmt
| &"maybe" maybe_stmt
| &('class' | '@') class_def
| &('with' | 'async') with_stmt
| &('for' | 'async') for_stmt
Expand Down Expand Up @@ -366,6 +367,11 @@ default[expr_ty]: '=' a=expression { a } | invalid_default
# If statement
# ------------

maybe_stmt[stmt_ty]:
| invalid_maybe_stmt
| "maybe" a=named_expression ':' b=block c=elif_stmt {
_PyAST_If(a, b, CHECK(asdl_stmt_seq*, _PyPegen_singleton_seq(p, c)), EXTRA) }
| "maybe" a=named_expression ':' b=block c=[else_block] { _PyAST_If(a, b, c, EXTRA) }
if_stmt[stmt_ty]:
| invalid_if_stmt
| 'if' a=named_expression ':' b=block c=elif_stmt {
Expand Down Expand Up @@ -1401,6 +1407,10 @@ invalid_class_pattern:
"positional patterns follow keyword patterns") }
invalid_class_argument_pattern[asdl_pattern_seq*]:
| [positional_patterns ','] keyword_patterns ',' a=positional_patterns { a }
invalid_maybe_stmt:
| "maybe" named_expression NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
| a="maybe" a=named_expression ':' NEWLINE !INDENT {
RAISE_INDENTATION_ERROR("expected an indented block after 'if' statement on line %d", a->lineno) }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
RAISE_INDENTATION_ERROR("expected an indented block after 'if' statement on line %d", a->lineno) }
RAISE_INDENTATION_ERROR("expected an indented block after 'maybe' statement on line %d", a->lineno) }

invalid_if_stmt:
| 'if' named_expression NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
| a='if' a=named_expression ':' NEWLINE !INDENT {
Expand Down
Loading
Loading