expression[expr_ty] (memo):
| invalid_expression
+ | invalid_legacy_expression
| a=disjunction 'if' b=disjunction 'else' c=expression { _PyAST_IfExp(b, a, c, EXTRA) }
| disjunction
| lambdef
"Missing parentheses in call to '%U'. Did you mean %U(...)?", a->v.Name.id, a->v.Name.id) : NULL}
invalid_expression:
- | invalid_legacy_expression
# !(NAME STRING) is not matched so we don't show this error with some invalid string prefixes like: kf"dsfsdf"
# Soft keywords need to also be ignored because they can be parsed as NAME NAME
| !(NAME STRING | SOFT_KEYWORD) a=disjunction b=expression_without_invalid {
- RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Perhaps you forgot a comma?") }
+ _PyPegen_check_legacy_stmt(p, a) ? NULL : RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Perhaps you forgot a comma?") }
| a=disjunction 'if' b=disjunction !('else'|':') { RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "expected 'else' after 'if' expression") }
invalid_named_expression:
// expression:
// | invalid_expression
+// | invalid_legacy_expression
// | disjunction 'if' disjunction 'else' expression
// | disjunction
// | lambdef
D(fprintf(stderr, "%*c%s expression[%d-%d]: %s failed!\n", p->level, ' ',
p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_expression"));
}
+ if (p->call_invalid_rules) { // invalid_legacy_expression
+ if (p->error_indicator) {
+ D(p->level--);
+ return NULL;
+ }
+ D(fprintf(stderr, "%*c> expression[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_legacy_expression"));
+ void *invalid_legacy_expression_var;
+ if (
+ (invalid_legacy_expression_var = invalid_legacy_expression_rule(p)) // invalid_legacy_expression
+ )
+ {
+ D(fprintf(stderr, "%*c+ expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_legacy_expression"));
+ _res = invalid_legacy_expression_var;
+ goto done;
+ }
+ p->mark = _mark;
+ D(fprintf(stderr, "%*c%s expression[%d-%d]: %s failed!\n", p->level, ' ',
+ p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_legacy_expression"));
+ }
{ // disjunction 'if' disjunction 'else' expression
if (p->error_indicator) {
D(p->level--);
}
// invalid_expression:
-// | invalid_legacy_expression
// | !(NAME STRING | SOFT_KEYWORD) disjunction expression_without_invalid
// | disjunction 'if' disjunction !('else' | ':')
static void *
}
void * _res = NULL;
int _mark = p->mark;
- if (p->call_invalid_rules) { // invalid_legacy_expression
- if (p->error_indicator) {
- D(p->level--);
- return NULL;
- }
- D(fprintf(stderr, "%*c> invalid_expression[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_legacy_expression"));
- void *invalid_legacy_expression_var;
- if (
- (invalid_legacy_expression_var = invalid_legacy_expression_rule(p)) // invalid_legacy_expression
- )
- {
- D(fprintf(stderr, "%*c+ invalid_expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_legacy_expression"));
- _res = invalid_legacy_expression_var;
- goto done;
- }
- p->mark = _mark;
- D(fprintf(stderr, "%*c%s invalid_expression[%d-%d]: %s failed!\n", p->level, ' ',
- p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_legacy_expression"));
- }
{ // !(NAME STRING | SOFT_KEYWORD) disjunction expression_without_invalid
if (p->error_indicator) {
D(p->level--);
)
{
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 = RAISE_SYNTAX_ERROR_KNOWN_RANGE ( a , b , "invalid syntax. Perhaps you forgot a comma?" );
+ _res = _PyPegen_check_legacy_stmt ( p , a ) ? 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--);