mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
bpo-43555: Report the column offset for invalid line continuation character (GH-24939)
This commit is contained in:
parent
123ff266cd
commit
96eeff5162
4 changed files with 13 additions and 6 deletions
|
|
@ -328,6 +328,7 @@ tokenizer_error(Parser *p)
|
|||
|
||||
const char *msg = NULL;
|
||||
PyObject* errtype = PyExc_SyntaxError;
|
||||
Py_ssize_t col_offset = -1;
|
||||
switch (p->tok->done) {
|
||||
case E_TOKEN:
|
||||
msg = "invalid token";
|
||||
|
|
@ -359,16 +360,14 @@ tokenizer_error(Parser *p)
|
|||
msg = "too many levels of indentation";
|
||||
break;
|
||||
case E_LINECONT:
|
||||
col_offset = strlen(strtok(p->tok->buf, "\n")) - 1;
|
||||
msg = "unexpected character after line continuation character";
|
||||
break;
|
||||
default:
|
||||
msg = "unknown parsing error";
|
||||
}
|
||||
|
||||
PyErr_Format(errtype, msg);
|
||||
// There is no reliable column information for this error
|
||||
PyErr_SyntaxLocationObject(p->tok->filename, p->tok->lineno, 0);
|
||||
|
||||
RAISE_ERROR_KNOWN_LOCATION(p, errtype, p->tok->lineno, col_offset, msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue