diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2021-10-07 23:50:10 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-07 23:50:10 (GMT) |
commit | 4ce55a2353e07962280181df40af0135aef1cf51 (patch) | |
tree | aa8e738370ad2cc8de1310817e23d167bd6c355e /Parser | |
parent | eabca6e593269301a0b7a36c4dc3525f04f5bb36 (diff) | |
download | cpython-4ce55a2353e07962280181df40af0135aef1cf51.zip cpython-4ce55a2353e07962280181df40af0135aef1cf51.tar.gz cpython-4ce55a2353e07962280181df40af0135aef1cf51.tar.bz2 |
[3.10] bpo-45408: Don't override previous tokenizer errors in the second parser pass (GH-28812). (GH-28813)
(cherry picked from commit 0219017df7ec41839fd0d56a3076b5f09c58d313)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Diffstat (limited to 'Parser')
-rw-r--r-- | Parser/pegen.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/Parser/pegen.c b/Parser/pegen.c index e20e926..1bb975d 100644 --- a/Parser/pegen.c +++ b/Parser/pegen.c @@ -1321,13 +1321,16 @@ _PyPegen_run_parser(Parser *p) { void *res = _PyPegen_parse(p); if (res == NULL) { + if (PyErr_Occurred() && !PyErr_ExceptionMatches(PyExc_SyntaxError)) { + return NULL; + } Token *last_token = p->tokens[p->fill - 1]; reset_parser_state(p); _PyPegen_parse(p); if (PyErr_Occurred()) { // Prioritize tokenizer errors to custom syntax errors raised // on the second phase only if the errors come from the parser. - if (p->tok->done != E_ERROR && PyErr_ExceptionMatches(PyExc_SyntaxError)) { + if (p->tok->done == E_DONE && PyErr_ExceptionMatches(PyExc_SyntaxError)) { _PyPegen_check_tokenizer_errors(p); } return NULL; |