summaryrefslogtreecommitdiffstats
path: root/Parser
diff options
context:
space:
mode:
authorLysandros Nikolaou <lisandrosnik@gmail.com>2020-05-27 16:04:11 (GMT)
committerGitHub <noreply@github.com>2020-05-27 16:04:11 (GMT)
commit526e23f1538134b728c21ac71ac977ae9e6a8de6 (patch)
treed44682b18c82e671902c5515c79791c2172986cb /Parser
parent29a1384c040d39659e7d01f1fd7b6eb71ef2634e (diff)
downloadcpython-526e23f1538134b728c21ac71ac977ae9e6a8de6.zip
cpython-526e23f1538134b728c21ac71ac977ae9e6a8de6.tar.gz
cpython-526e23f1538134b728c21ac71ac977ae9e6a8de6.tar.bz2
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
Diffstat (limited to 'Parser')
-rw-r--r--Parser/pegen/pegen.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/Parser/pegen/pegen.c b/Parser/pegen/pegen.c
index a0285bc..c55ff7e 100644
--- a/Parser/pegen/pegen.c
+++ b/Parser/pegen/pegen.c
@@ -775,15 +775,15 @@ _PyPegen_expect_soft_keyword(Parser *p, const char *keyword)
if (t->type != NAME) {
return NULL;
}
- char* s = PyBytes_AsString(t->bytes);
+ char *s = PyBytes_AsString(t->bytes);
if (!s) {
+ p->error_indicator = 1;
return NULL;
}
if (strcmp(s, keyword) != 0) {
return NULL;
}
- expr_ty res = _PyPegen_name_token(p);
- return res;
+ return _PyPegen_name_token(p);
}
Token *
@@ -809,10 +809,12 @@ _PyPegen_name_token(Parser *p)
}
char* s = PyBytes_AsString(t->bytes);
if (!s) {
+ p->error_indicator = 1;
return NULL;
}
PyObject *id = _PyPegen_new_identifier(p, s);
if (id == NULL) {
+ p->error_indicator = 1;
return NULL;
}
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);
if (num_raw == NULL) {
+ p->error_indicator = 1;
return NULL;
}
@@ -917,11 +920,13 @@ _PyPegen_number_token(Parser *p)
PyObject *c = parsenumber(num_raw);
if (c == NULL) {
+ p->error_indicator = 1;
return NULL;
}
if (PyArena_AddPyObject(p->arena, c) < 0) {
Py_DECREF(c);
+ p->error_indicator = 1;
return NULL;
}