Skip to content

Commit 241807e

Browse files
committed
Minor cleanup
1 parent f63ac52 commit 241807e

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

Parser/pegen.c

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,33 +1177,36 @@ _PyPegen_check_tokenizer_errors(Parser *p) {
11771177
return 0;
11781178
}
11791179

1180-
const char *start;
1181-
const char *end;
1182-
int type;
11831180

11841181
Token *current_token = p->known_err_token != NULL ? p->known_err_token : p->tokens[p->fill - 1];
11851182
Py_ssize_t current_err_line = current_token->lineno;
11861183

1187-
// Save the tokenizer buffers to restore them later in case we found nothing
1184+
// Save the tokenizer state to restore them later in case we found nothing
11881185
struct tok_state saved_tok;
11891186
memcpy(&saved_tok, p->tok, sizeof(struct tok_state));
11901187

1191-
while (1) {
1192-
type = PyTokenizer_Get(p->tok, &start, &end);
1193-
if (type == ERRORTOKEN) {
1194-
if (p->tok->level != 0) {
1195-
int error_lineno = p->tok->parenlinenostack[p->tok->level-1];
1196-
if (current_err_line > error_lineno) {
1197-
raise_unclosed_parentheses_error(p);
1198-
return -1;
1188+
for (;;) {
1189+
const char *start;
1190+
const char *end;
1191+
switch (PyTokenizer_Get(p->tok, &start, &end)) {
1192+
case ERRORTOKEN:
1193+
if (p->tok->level != 0) {
1194+
int error_lineno = p->tok->parenlinenostack[p->tok->level-1];
1195+
if (current_err_line > error_lineno) {
1196+
raise_unclosed_parentheses_error(p);
1197+
return -1;
1198+
}
11991199
}
1200-
}
1201-
break;
1202-
}
1203-
if (type == ENDMARKER) {
1204-
break;
1200+
break;
1201+
case ENDMARKER:
1202+
break;
1203+
default:
1204+
continue;
12051205
}
1206+
break;
12061207
}
1208+
1209+
// Restore the tokenizer state
12071210
memcpy(p->tok, &saved_tok, sizeof(struct tok_state));
12081211
return 0;
12091212
}

0 commit comments

Comments
 (0)