bpo-43822: Improve syntax errors for missing commas (GH-25377)

This commit is contained in:
Pablo Galindo 2021-04-15 21:38:45 +01:00 committed by GitHub
parent e692f55979
commit b280248be8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 1235 additions and 1034 deletions

File diff suppressed because it is too large Load diff

View file

@ -943,6 +943,23 @@ _PyPegen_string_token(Parser *p)
return _PyPegen_expect_token(p, STRING);
}
expr_ty _PyPegen_soft_keyword_token(Parser *p) {
Token *t = _PyPegen_expect_token(p, NAME);
if (t == NULL) {
return NULL;
}
char *the_token;
Py_ssize_t size;
PyBytes_AsStringAndSize(t->bytes, &the_token, &size);
for (char **keyword = p->soft_keywords; *keyword != NULL; keyword++) {
if (strncmp(*keyword, the_token, size) == 0) {
return _PyPegen_name_token(p);
}
}
return NULL;
}
static PyObject *
parsenumber_raw(const char *s)
{
@ -1151,6 +1168,7 @@ _PyPegen_Parser_New(struct tok_state *tok, int start_rule, int flags,
p->tok = tok;
p->keywords = NULL;
p->n_keyword_lists = -1;
p->soft_keywords = NULL;
p->tokens = PyMem_Malloc(sizeof(Token *));
if (!p->tokens) {
PyMem_Free(p);

View file

@ -59,6 +59,7 @@ typedef struct {
int fill, size;
PyArena *arena;
KeywordToken **keywords;
char **soft_keywords;
int n_keyword_lists;
int start_rule;
int *errcode;
@ -125,6 +126,7 @@ int _PyPegen_lookahead(int, void *(func)(Parser *), Parser *);
Token *_PyPegen_expect_token(Parser *p, int type);
Token *_PyPegen_expect_forced_token(Parser *p, int type, const char* expected);
expr_ty _PyPegen_expect_soft_keyword(Parser *p, const char *keyword);
expr_ty _PyPegen_soft_keyword_token(Parser *p);
Token *_PyPegen_get_last_nonnwhitespace_token(Parser *);
int _PyPegen_fill_token(Parser *p);
expr_ty _PyPegen_name_token(Parser *p);

1
Parser/token.c generated
View file

@ -65,6 +65,7 @@ const char * const _PyParser_TokenNames[] = {
"ASYNC",
"TYPE_IGNORE",
"TYPE_COMMENT",
"SOFT_KEYWORD",
"<ERRORTOKEN>",
"<COMMENT>",
"<NL>",