diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2021-03-24 19:34:17 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-24 19:34:17 (GMT) |
commit | 8efad61963809d239cac986e3f3bc4cb505ab8fe (patch) | |
tree | c1d2c56b72ad7e1ee034f481570449267f73a85a /Parser/parser.c | |
parent | 4958f5d69dd2bf86866c43491caf72f774ddec97 (diff) | |
download | cpython-8efad61963809d239cac986e3f3bc4cb505ab8fe.zip cpython-8efad61963809d239cac986e3f3bc4cb505ab8fe.tar.gz cpython-8efad61963809d239cac986e3f3bc4cb505ab8fe.tar.bz2 |
bpo-41064: Improve syntax error for invalid usage of '**' in f-strings (GH-25006)
Diffstat (limited to 'Parser/parser.c')
-rw-r--r-- | Parser/parser.c | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/Parser/parser.c b/Parser/parser.c index 6efaebe..de90c87 100644 --- a/Parser/parser.c +++ b/Parser/parser.c @@ -18285,7 +18285,7 @@ invalid_for_target_rule(Parser *p) return _res; } -// invalid_group: '(' starred_expression ')' +// invalid_group: '(' starred_expression ')' | '(' '**' expression ')' static void * invalid_group_rule(Parser *p) { @@ -18326,6 +18326,39 @@ invalid_group_rule(Parser *p) D(fprintf(stderr, "%*c%s invalid_group[%d-%d]: %s failed!\n", p->level, ' ', p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' starred_expression ')'")); } + { // '(' '**' expression ')' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> invalid_group[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'(' '**' expression ')'")); + Token * _literal; + Token * _literal_1; + Token * a; + expr_ty expression_var; + if ( + (_literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (a = _PyPegen_expect_token(p, 35)) // token='**' + && + (expression_var = expression_rule(p)) // expression + && + (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + D(fprintf(stderr, "%*c+ invalid_group[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'(' '**' expression ')'")); + _res = RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( a , "can't use double starred expression here" ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s invalid_group[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' '**' expression ')'")); + } _res = NULL; done: D(p->level--); |