diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-06-09 21:40:07 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-09 21:40:07 (GMT) |
commit | ae6e002f5a27b267192204177a3b23ce23f0a4e7 (patch) | |
tree | 5278d5525f562c5df7009d98ba05aa834f3097db /Parser | |
parent | 411366ccdb7708cbf4e00db9186c2cffb3a0c652 (diff) | |
download | cpython-ae6e002f5a27b267192204177a3b23ce23f0a4e7.zip cpython-ae6e002f5a27b267192204177a3b23ce23f0a4e7.tar.gz cpython-ae6e002f5a27b267192204177a3b23ce23f0a4e7.tar.bz2 |
[3.12] gh-105549: Tokenize separately NUMBER and NAME tokens and allow 0-prefixed literals (GH-105555) (#105602)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Diffstat (limited to 'Parser')
-rw-r--r-- | Parser/tokenizer.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index 89594e6..57c98fe 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -1600,8 +1600,12 @@ lookahead(struct tok_state *tok, const char *test) } static int -verify_end_of_number(struct tok_state *tok, int c, const char *kind) -{ +verify_end_of_number(struct tok_state *tok, int c, const char *kind) { + if (tok->tok_extra_tokens) { + // When we are parsing extra tokens, we don't want to emit warnings + // about invalid literals, because we want to be a bit more liberal. + return 1; + } /* Emit a deprecation warning only if the numeric literal is immediately * followed by one of keywords which can occur after a numeric literal * in valid code: "and", "else", "for", "if", "in", "is" and "or". @@ -1659,6 +1663,9 @@ verify_end_of_number(struct tok_state *tok, int c, const char *kind) static int verify_identifier(struct tok_state *tok) { + if (tok->tok_extra_tokens) { + return 1; + } PyObject *s; if (tok->decoding_erred) return 0; @@ -2318,7 +2325,7 @@ tok_get_normal_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct t else if (c == 'j' || c == 'J') { goto imaginary; } - else if (nonzero) { + else if (nonzero && !tok->tok_extra_tokens) { /* Old-style octal: now disallowed. */ tok_backup(tok, c); return MAKE_TOKEN(syntaxerror_known_range( |