Skip to content

Commit f50516e

Browse files
authored
bpo-40334: Correctly generate C parser when assigned var is None (GH-20296)
When there are 2 negative lookaheads in the same rule, let's say `!"(" blabla "," !")"`, there will the 2 `FunctionCall`'s where assigned value is None. Currently when the `add_var` is called the first one will be ignored but when the second lookahead's var is sent to dedupe it will be returned as `None_1` and this won't be ignored by the declaration generator in the `visit_Alt`. This patch adds an explicit check to `add_var` to distinguish whether if there is a variable or not.
1 parent a487a39 commit f50516e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Tools/peg_generator/pegen/c_generator.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,4 +722,7 @@ def collect_vars(self, node: Alt) -> Dict[Optional[str], Optional[str]]:
722722

723723
def add_var(self, node: NamedItem) -> Tuple[Optional[str], Optional[str]]:
724724
call = self.callmakervisitor.visit(node.item)
725-
return self.dedupe(node.name if node.name else call.assigned_variable), call.return_type
725+
name = node.name if node.name else call.assigned_variable
726+
if name is not None:
727+
name = self.dedupe(name)
728+
return name, call.return_type

0 commit comments

Comments
 (0)