mirror of
https://github.com/python/cpython.git
synced 2025-07-28 21:55:21 +00:00
bpo-40176: Improve error messages for unclosed string literals (GH-19346)
Automerge-Triggered-By: GH:isidentical
This commit is contained in:
parent
c3f167d7b2
commit
a698d52c39
7 changed files with 34 additions and 32 deletions
|
@ -1739,20 +1739,26 @@ tok_get(struct tok_state *tok, const char **p_start, const char **p_end)
|
|||
/* Get rest of string */
|
||||
while (end_quote_size != quote_size) {
|
||||
c = tok_nextc(tok);
|
||||
if (c == EOF) {
|
||||
if (c == EOF || (quote_size == 1 && c == '\n')) {
|
||||
// shift the tok_state's location into
|
||||
// the start of string, and report the error
|
||||
// from the initial quote character
|
||||
tok->cur = (char *)tok->start;
|
||||
tok->cur++;
|
||||
tok->line_start = tok->multi_line_start;
|
||||
int start = tok->lineno;
|
||||
tok->lineno = tok->first_lineno;
|
||||
|
||||
if (quote_size == 3) {
|
||||
tok->done = E_EOFS;
|
||||
return syntaxerror(tok,
|
||||
"unterminated triple-quoted string literal"
|
||||
" (detected at line %d)", start);
|
||||
}
|
||||
else {
|
||||
tok->done = E_EOLS;
|
||||
return syntaxerror(tok,
|
||||
"unterminated string literal (detected at"
|
||||
" line %d)", start);
|
||||
}
|
||||
tok->cur = tok->inp;
|
||||
return ERRORTOKEN;
|
||||
}
|
||||
if (quote_size == 1 && c == '\n') {
|
||||
tok->done = E_EOLS;
|
||||
tok->cur = tok->inp;
|
||||
return ERRORTOKEN;
|
||||
}
|
||||
if (c == quote) {
|
||||
end_quote_size += 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue