diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-03-22 19:07:05 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-22 19:07:05 (GMT) |
commit | 994a519915bff4901abaa7476e2b91682dea619a (patch) | |
tree | 90b9d0f7fae99d08035a97a398dd25ebf0ff1eee /Parser | |
parent | c145c03281af850130dd7f75abc19c6ea49626e6 (diff) | |
download | cpython-994a519915bff4901abaa7476e2b91682dea619a.zip cpython-994a519915bff4901abaa7476e2b91682dea619a.tar.gz cpython-994a519915bff4901abaa7476e2b91682dea619a.tar.bz2 |
bpo-43555: Report the column offset for invalid line continuation character (GH-24939) (#24975)
(cherry picked from commit 96eeff516204b7cc751103fa33dcc665e387846e)
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Diffstat (limited to 'Parser')
-rw-r--r-- | Parser/pegen/pegen.c | 7 | ||||
-rw-r--r-- | Parser/pegen/pegen.h | 5 |
2 files changed, 6 insertions, 6 deletions
diff --git a/Parser/pegen/pegen.c b/Parser/pegen/pegen.c index 4e742a5..0a26275 100644 --- a/Parser/pegen/pegen.c +++ b/Parser/pegen/pegen.c @@ -313,6 +313,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"; @@ -346,16 +347,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; } diff --git a/Parser/pegen/pegen.h b/Parser/pegen/pegen.h index a2f524a..224c5cb 100644 --- a/Parser/pegen/pegen.h +++ b/Parser/pegen/pegen.h @@ -138,8 +138,9 @@ void *_PyPegen_raise_error_known_location(Parser *p, PyObject *errtype, void *_PyPegen_dummy_name(Parser *p, ...); Py_LOCAL_INLINE(void *) -RAISE_ERROR_KNOWN_LOCATION(Parser *p, PyObject *errtype, int lineno, - int col_offset, const char *errmsg, ...) +RAISE_ERROR_KNOWN_LOCATION(Parser *p, PyObject *errtype, + Py_ssize_t lineno, Py_ssize_t col_offset, + const char *errmsg, ...) { va_list va; va_start(va, errmsg); |