Skip to content

Commit

Permalink
bpo-40334: Correctly generate C parser when assigned var is None (GH-…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
isidentical committed May 21, 2020
1 parent a487a39 commit f50516e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Tools/peg_generator/pegen/c_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,4 +722,7 @@ def collect_vars(self, node: Alt) -> Dict[Optional[str], Optional[str]]:

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

0 comments on commit f50516e

Please sign in to comment.