summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2021-01-20 19:11:56 (GMT)
committerGitHub <noreply@github.com>2021-01-20 19:11:56 (GMT)
commitc3f167d7b243f8b8e1b797586e6cef35add013bc (patch)
tree7fdec8d55db3938cd67a5f0da14023bb8433be6a
parent75e59a97f5d1fddb0c30ed9747b1b8cb84420a62 (diff)
downloadcpython-c3f167d7b243f8b8e1b797586e6cef35add013bc.zip
cpython-c3f167d7b243f8b8e1b797586e6cef35add013bc.tar.gz
cpython-c3f167d7b243f8b8e1b797586e6cef35add013bc.tar.bz2
bpo-42864: Simplify the tokenizer exceptions after generic SyntaxError (GH-24273)
Automerge-Triggered-By: GH:pablogsal
-rw-r--r--Parser/pegen.c13
1 files changed, 3 insertions, 10 deletions
diff --git a/Parser/pegen.c b/Parser/pegen.c
index 6c27980..0d39030 100644
--- a/Parser/pegen.c
+++ b/Parser/pegen.c
@@ -1177,14 +1177,9 @@ _PyPegen_check_tokenizer_errors(Parser *p) {
return 0;
}
-
Token *current_token = p->known_err_token != NULL ? p->known_err_token : p->tokens[p->fill - 1];
Py_ssize_t current_err_line = current_token->lineno;
- // Save the tokenizer state to restore them later in case we found nothing
- struct tok_state saved_tok;
- memcpy(&saved_tok, p->tok, sizeof(struct tok_state));
-
for (;;) {
const char *start;
const char *end;
@@ -1206,8 +1201,6 @@ _PyPegen_check_tokenizer_errors(Parser *p) {
break;
}
- // Restore the tokenizer state
- memcpy(p->tok, &saved_tok, sizeof(struct tok_state));
return 0;
}
@@ -1239,10 +1232,10 @@ _PyPegen_run_parser(Parser *p)
RAISE_INDENTATION_ERROR("unexpected unindent");
}
else {
- if (_PyPegen_check_tokenizer_errors(p)) {
- return NULL;
- }
RAISE_SYNTAX_ERROR("invalid syntax");
+ // _PyPegen_check_tokenizer_errors will override the existing
+ // generic SyntaxError we just raised if errors are found.
+ _PyPegen_check_tokenizer_errors(p);
}
}
return NULL;