diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-06-09 21:45:43 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-09 21:45:43 (GMT) |
commit | f807a4fad4da8f629ea7fe1f00719e817c77b63c (patch) | |
tree | 1ef8fc5c3cf24eb407f7a3e8be9ee684c9920200 /Parser | |
parent | 664ae29e6f61988e74cb8753dd4ee71e9ea57227 (diff) | |
download | cpython-f807a4fad4da8f629ea7fe1f00719e817c77b63c.zip cpython-f807a4fad4da8f629ea7fe1f00719e817c77b63c.tar.gz cpython-f807a4fad4da8f629ea7fe1f00719e817c77b63c.tar.bz2 |
bpo-44368: Ensure we don't raise incorrect custom syntax errors with soft keywords (GH-26630)
(cherry picked from commit 457ce60fc70f1c9290023f46fb82b6a490dff32e)
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Diffstat (limited to 'Parser')
-rw-r--r-- | Parser/pegen.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/Parser/pegen.c b/Parser/pegen.c index e651819..82f840c 100644 --- a/Parser/pegen.c +++ b/Parser/pegen.c @@ -936,10 +936,9 @@ _PyPegen_get_last_nonnwhitespace_token(Parser *p) return token; } -expr_ty -_PyPegen_name_token(Parser *p) +static expr_ty +_PyPegen_name_from_token(Parser *p, Token* t) { - Token *t = _PyPegen_expect_token(p, NAME); if (t == NULL) { return NULL; } @@ -957,6 +956,14 @@ _PyPegen_name_token(Parser *p) t->end_col_offset, p->arena); } + +expr_ty +_PyPegen_name_token(Parser *p) +{ + Token *t = _PyPegen_expect_token(p, NAME); + return _PyPegen_name_from_token(p, t); +} + void * _PyPegen_string_token(Parser *p) { @@ -974,7 +981,7 @@ expr_ty _PyPegen_soft_keyword_token(Parser *p) { PyBytes_AsStringAndSize(t->bytes, &the_token, &size); for (char **keyword = p->soft_keywords; *keyword != NULL; keyword++) { if (strncmp(*keyword, the_token, size) == 0) { - return _PyPegen_name_token(p); + return _PyPegen_name_from_token(p, t); } } return NULL; |