Skip to content

bpo-42864: Simplify the tokenizer exceptions after generic SyntaxError #24273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions Parser/pegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down