mirror of
https://github.com/python/cpython.git
synced 2026-01-06 23:42:34 +00:00
bpo-43822: Improve syntax errors for missing commas (GH-25377)
This commit is contained in:
parent
e692f55979
commit
b280248be8
13 changed files with 1235 additions and 1034 deletions
2180
Parser/parser.c
2180
Parser/parser.c
File diff suppressed because it is too large
Load diff
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
1
Parser/token.c
generated
|
|
@ -65,6 +65,7 @@ const char * const _PyParser_TokenNames[] = {
|
|||
"ASYNC",
|
||||
"TYPE_IGNORE",
|
||||
"TYPE_COMMENT",
|
||||
"SOFT_KEYWORD",
|
||||
"<ERRORTOKEN>",
|
||||
"<COMMENT>",
|
||||
"<NL>",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue