Thanks to visit codestin.com
Credit goes to github.com

Skip to content

bpo-42128: Add 'missing :' syntax error message to match statements #24733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 18, 2021
Merged
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
Prev Previous commit
fixup! bpo-42128: Add 'missing :' syntax error message to match state…
…ments
  • Loading branch information
pablogsal committed Mar 17, 2021
commit ec42b1f5785a0fe510b407de72edbe0c2c9b7f32
4 changes: 2 additions & 2 deletions Grammar/python.gram
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ invalid_except_block:
| 'except' &&':'

invalid_match_stmt:
| "match" subject_expr !':' { RAISE_SYNTAX_ERROR("expected ':'") }
| "match" subject_expr !':' { CHECK_VERSION(void*, 10, "Pattern matching is", RAISE_SYNTAX_ERROR("expected ':'") ) }

invalid_case_block:
| "case" patterns guard=guard? !':' { RAISE_SYNTAX_ERROR("expected ':'") }
| "case" patterns guard? !':' { RAISE_SYNTAX_ERROR("expected ':'") }
7 changes: 4 additions & 3 deletions Parser/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -18603,7 +18603,7 @@ invalid_match_stmt_rule(Parser *p)
)
{
D(fprintf(stderr, "%*c+ invalid_match_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "\"match\" subject_expr !':'"));
_res = RAISE_SYNTAX_ERROR ( "expected ':'" );
_res = CHECK_VERSION ( void * , 10 , "Pattern matching is" , RAISE_SYNTAX_ERROR ( "expected ':'" ) );
if (_res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
D(p->level--);
Expand Down Expand Up @@ -18639,14 +18639,15 @@ invalid_case_block_rule(Parser *p)
}
D(fprintf(stderr, "%*c> invalid_case_block[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "\"case\" patterns guard? !':'"));
expr_ty _keyword;
void *guard;
void *_opt_var;
UNUSED(_opt_var); // Silence compiler warnings
expr_ty patterns_var;
if (
(_keyword = _PyPegen_expect_soft_keyword(p, "case")) // soft_keyword='"case"'
&&
(patterns_var = patterns_rule(p)) // patterns
&&
(guard = guard_rule(p), 1) // guard?
(_opt_var = guard_rule(p), 1) // guard?
&&
_PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, 11) // token=':'
)
Expand Down