diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-05-21 15:29:58 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-21 15:29:58 (GMT) |
commit | 07dba474c582e61ca455846da7597d4346324e04 (patch) | |
tree | 5d10ddbfa382e3552ca4886822e130dbe49fd9a1 /Parser/pegen.c | |
parent | f14015adf52014c2345522fe32d43f15f001c986 (diff) | |
download | cpython-07dba474c582e61ca455846da7597d4346324e04.zip cpython-07dba474c582e61ca455846da7597d4346324e04.tar.gz cpython-07dba474c582e61ca455846da7597d4346324e04.tar.bz2 |
bpo-44180: Report generic syntax errors in the furthest position reached in the first parser pass (GH-26253) (GH-26281)
(cherry picked from commit b51081c1a8cf01b92ba0692173e1b9274a57f455)
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Diffstat (limited to 'Parser/pegen.c')
-rw-r--r-- | Parser/pegen.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/Parser/pegen.c b/Parser/pegen.c index c2f2540..406c4e8 100644 --- a/Parser/pegen.c +++ b/Parser/pegen.c @@ -1281,6 +1281,7 @@ _PyPegen_run_parser(Parser *p) { void *res = _PyPegen_parse(p); if (res == NULL) { + Token *last_token = p->tokens[p->fill - 1]; reset_parser_state(p); _PyPegen_parse(p); if (PyErr_Occurred()) { @@ -1307,7 +1308,11 @@ _PyPegen_run_parser(Parser *p) RAISE_INDENTATION_ERROR("unexpected unindent"); } else { - RAISE_SYNTAX_ERROR("invalid syntax"); + // Use the last token we found on the first pass to avoid reporting + // incorrect locations for generic syntax errors just because we reached + // further away when trying to find specific syntax errors in the second + // pass. + RAISE_SYNTAX_ERROR_KNOWN_LOCATION(last_token, "invalid syntax"); // _PyPegen_check_tokenizer_errors will override the existing // generic SyntaxError we just raised if errors are found. _PyPegen_check_tokenizer_errors(p); |