mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-45727: Only trigger the 'did you forgot a comma' error suggestion if inside parentheses (GH-29757)
This commit is contained in:
parent
f4afc53bf6
commit
24c10d2943
8 changed files with 15 additions and 8 deletions
|
@ -18298,7 +18298,7 @@ invalid_expression_rule(Parser *p)
|
|||
)
|
||||
{
|
||||
D(fprintf(stderr, "%*c+ invalid_expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "!(NAME STRING | SOFT_KEYWORD) disjunction expression_without_invalid"));
|
||||
_res = _PyPegen_check_legacy_stmt ( p , a ) ? NULL : RAISE_SYNTAX_ERROR_KNOWN_RANGE ( a , b , "invalid syntax. Perhaps you forgot a comma?" );
|
||||
_res = _PyPegen_check_legacy_stmt ( p , a ) ? NULL : p -> tokens [p -> mark - 1] -> level == 0 ? NULL : RAISE_SYNTAX_ERROR_KNOWN_RANGE ( a , b , "invalid syntax. Perhaps you forgot a comma?" );
|
||||
if (_res == NULL && PyErr_Occurred()) {
|
||||
p->error_indicator = 1;
|
||||
D(p->level--);
|
||||
|
|
|
@ -170,6 +170,8 @@ initialize_token(Parser *p, Token *token, const char *start, const char *end, in
|
|||
return -1;
|
||||
}
|
||||
|
||||
token->level = p->tok->level;
|
||||
|
||||
const char *line_start = token_type == STRING ? p->tok->multi_line_start : p->tok->line_start;
|
||||
int lineno = token_type == STRING ? p->tok->first_lineno : p->tok->lineno;
|
||||
int end_lineno = p->tok->lineno;
|
||||
|
@ -946,4 +948,4 @@ _PyPegen_run_parser_from_string(const char *str, int start_rule, PyObject *filen
|
|||
error:
|
||||
_PyTokenizer_Free(tok);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ typedef struct _memo {
|
|||
typedef struct {
|
||||
int type;
|
||||
PyObject *bytes;
|
||||
int level;
|
||||
int lineno, col_offset, end_lineno, end_col_offset;
|
||||
Memo *memo;
|
||||
} Token;
|
||||
|
|
|
@ -399,7 +399,7 @@ _Pypegen_set_syntax_error(Parser* p, Token* last_token) {
|
|||
RAISE_SYNTAX_ERROR("error at start before reading any input");
|
||||
}
|
||||
// Parser encountered EOF (End of File) unexpectedtly
|
||||
if (p->tok->done == E_EOF) {
|
||||
if (last_token->type == ERRORTOKEN && p->tok->done == E_EOF) {
|
||||
if (p->tok->level) {
|
||||
raise_unclosed_parentheses_error(p);
|
||||
} else {
|
||||
|
@ -422,4 +422,4 @@ _Pypegen_set_syntax_error(Parser* p, Token* last_token) {
|
|||
// _PyPegen_tokenize_full_source_to_check_for_errors will override the existing
|
||||
// generic SyntaxError we just raised if errors are found.
|
||||
_PyPegen_tokenize_full_source_to_check_for_errors(p);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue