Refactor error handling code in Parser/pegen/pegen.c (GH-20440)

Set p->error_indicator in various places, where it's needed, but it's
not done.

Automerge-Triggered-By: @gvanrossum
This commit is contained in:
Lysandros Nikolaou 2020-05-27 19:04:11 +03:00 committed by GitHub
parent 29a1384c04
commit 526e23f153
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 3 deletions

View File

@ -775,15 +775,15 @@ _PyPegen_expect_soft_keyword(Parser *p, const char *keyword)
if (t->type != NAME) { if (t->type != NAME) {
return NULL; return NULL;
} }
char* s = PyBytes_AsString(t->bytes); char *s = PyBytes_AsString(t->bytes);
if (!s) { if (!s) {
p->error_indicator = 1;
return NULL; return NULL;
} }
if (strcmp(s, keyword) != 0) { if (strcmp(s, keyword) != 0) {
return NULL; return NULL;
} }
expr_ty res = _PyPegen_name_token(p); return _PyPegen_name_token(p);
return res;
} }
Token * Token *
@ -809,10 +809,12 @@ _PyPegen_name_token(Parser *p)
} }
char* s = PyBytes_AsString(t->bytes); char* s = PyBytes_AsString(t->bytes);
if (!s) { if (!s) {
p->error_indicator = 1;
return NULL; return NULL;
} }
PyObject *id = _PyPegen_new_identifier(p, s); PyObject *id = _PyPegen_new_identifier(p, s);
if (id == NULL) { if (id == NULL) {
p->error_indicator = 1;
return NULL; return NULL;
} }
return Name(id, Load, t->lineno, t->col_offset, t->end_lineno, t->end_col_offset, return Name(id, Load, t->lineno, t->col_offset, t->end_lineno, t->end_col_offset,
@ -905,6 +907,7 @@ _PyPegen_number_token(Parser *p)
char *num_raw = PyBytes_AsString(t->bytes); char *num_raw = PyBytes_AsString(t->bytes);
if (num_raw == NULL) { if (num_raw == NULL) {
p->error_indicator = 1;
return NULL; return NULL;
} }
@ -917,11 +920,13 @@ _PyPegen_number_token(Parser *p)
PyObject *c = parsenumber(num_raw); PyObject *c = parsenumber(num_raw);
if (c == NULL) { if (c == NULL) {
p->error_indicator = 1;
return NULL; return NULL;
} }
if (PyArena_AddPyObject(p->arena, c) < 0) { if (PyArena_AddPyObject(p->arena, c) < 0) {
Py_DECREF(c); Py_DECREF(c);
p->error_indicator = 1;
return NULL; return NULL;
} }