diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2021-03-22 17:28:11 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-22 17:28:11 (GMT) |
commit | 96eeff516204b7cc751103fa33dcc665e387846e (patch) | |
tree | 7eb595bad5b876e53ccf91f041fe4d5512742fd0 /Parser/pegen.c | |
parent | 123ff266cda9ad279106f20dca06ba114f6a9b8a (diff) | |
download | cpython-96eeff516204b7cc751103fa33dcc665e387846e.zip cpython-96eeff516204b7cc751103fa33dcc665e387846e.tar.gz cpython-96eeff516204b7cc751103fa33dcc665e387846e.tar.bz2 |
bpo-43555: Report the column offset for invalid line continuation character (GH-24939)
Diffstat (limited to 'Parser/pegen.c')
-rw-r--r-- | Parser/pegen.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/Parser/pegen.c b/Parser/pegen.c index 953480d..d2b7ec4 100644 --- a/Parser/pegen.c +++ b/Parser/pegen.c @@ -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; } |