@@ -1078,6 +1078,7 @@ invalid_kwarg:
1078
1078
RAISE_SYNTAX_ERROR_KNOWN_RANGE(
1079
1079
a, b, "expression cannot contain assignment, perhaps you meant \"==\"?") }
1080
1080
1081
+ # IMPORTANT: Note that the "_without_invalid" suffix causes the rule to not call invalid rules under it
1081
1082
expression_without_invalid[expr_ty]:
1082
1083
| a=disjunction 'if' b=disjunction 'else' c=expression { _PyAST_IfExp(b, a, c, EXTRA) }
1083
1084
| disjunction
@@ -1095,16 +1096,14 @@ invalid_expression:
1095
1096
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Perhaps you forgot a comma?") }
1096
1097
| a=disjunction 'if' b=disjunction !('else'|':') { RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "expected 'else' after 'if' expression") }
1097
1098
1098
- invalid_left_assignment_prefixes(memo): list|tuple|genexp|'True'|'None'|'False'
1099
-
1100
- invalid_named_expression:
1099
+ invalid_named_expression(memo):
1101
1100
| a=expression ':=' expression {
1102
1101
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
1103
1102
a, "cannot use assignment expressions with %s", _PyPegen_get_expr_name(a)) }
1104
1103
| a=NAME '=' b=bitwise_or !('='|':=') {
1105
- p->in_raw_rule ? NULL : RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Maybe you meant '==' or ':=' instead of '='?") }
1106
- | !invalid_left_assignment_prefixes a=bitwise_or b='=' bitwise_or !('='|':=') {
1107
- p->in_raw_rule ? NULL : RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "cannot assign to %s here. Maybe you meant '==' instead of '='?",
1104
+ RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Maybe you meant '==' or ':=' instead of '='?") }
1105
+ | !(list|tuple|genexp|'True'|'None'|'False') a=bitwise_or b='=' bitwise_or !('='|':=') {
1106
+ RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "cannot assign to %s here. Maybe you meant '==' instead of '='?",
1108
1107
_PyPegen_get_expr_name(a)) }
1109
1108
1110
1109
invalid_assignment:
0 commit comments