diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2022-02-08 12:25:15 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-08 12:25:15 +0000 |
commit | 5b58db75291cfbb9b6785c9845824b3e2da01c1c (patch) | |
tree | e44eba71a28740851b8f88a4bddb29cef1ef7f7b /Parser/tokenizer.c | |
parent | cbdcae5ab90710e8d82c213f3798af1154670ff9 (diff) | |
download | cpython-git-5b58db75291cfbb9b6785c9845824b3e2da01c1c.tar.gz |
[3.10] bpo-46521: Fix codeop to use a new partial-input mode of the parser (GH-31010). (GH-31213)
(cherry picked from commit 69e10976b2e7682c6d57f4272932ebc19f8e8859)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Diffstat (limited to 'Parser/tokenizer.c')
-rw-r--r-- | Parser/tokenizer.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index 3738a9021f..eb15ef7a5d 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -39,7 +39,7 @@ static struct tok_state *tok_new(void); static int tok_nextc(struct tok_state *tok); static void tok_backup(struct tok_state *tok, int c); - +static int syntaxerror(struct tok_state *tok, const char *format, ...); /* Spaces in this constant are treated as "zero or more spaces or tabs" when tokenizing. */ @@ -1030,8 +1030,9 @@ tok_nextc(struct tok_state *tok) if (tok->cur != tok->inp) { return Py_CHARMASK(*tok->cur++); /* Fast path */ } - if (tok->done != E_OK) - return EOF; + if (tok->done != E_OK) { + return EOF; + } if (tok->fp == NULL) { rc = tok_underflow_string(tok); } @@ -1963,16 +1964,21 @@ tok_get(struct tok_state *tok, const char **p_start, const char **p_end) tok->line_start = tok->multi_line_start; int start = tok->lineno; tok->lineno = tok->first_lineno; - if (quote_size == 3) { - return syntaxerror(tok, - "unterminated triple-quoted string literal" - " (detected at line %d)", start); + syntaxerror(tok, "unterminated triple-quoted string literal" + " (detected at line %d)", start); + if (c != '\n') { + tok->done = E_EOFS; + } + return ERRORTOKEN; } else { - return syntaxerror(tok, - "unterminated string literal (detected at" - " line %d)", start); + syntaxerror(tok, "unterminated string literal (detected at" + " line %d)", start); + if (c != '\n') { + tok->done = E_EOLS; + } + return ERRORTOKEN; } } if (c == quote) { |