diff options
author | Batuhan Taskaya <batuhanosmantaskaya@gmail.com> | 2020-05-21 19:57:52 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-21 19:57:52 (GMT) |
commit | f50516e6a978ee694232512399dd1ab47aaebab1 (patch) | |
tree | 3c757f56126f25fa19edec7feb84ea67359ae32d /Tools | |
parent | a487a39dca4c41305928c7dfdbcb0b3aa344683b (diff) | |
download | cpython-f50516e6a978ee694232512399dd1ab47aaebab1.zip cpython-f50516e6a978ee694232512399dd1ab47aaebab1.tar.gz cpython-f50516e6a978ee694232512399dd1ab47aaebab1.tar.bz2 |
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.
Diffstat (limited to 'Tools')
-rw-r--r-- | Tools/peg_generator/pegen/c_generator.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/Tools/peg_generator/pegen/c_generator.py b/Tools/peg_generator/pegen/c_generator.py index c93b348..e8107ec 100644 --- a/Tools/peg_generator/pegen/c_generator.py +++ b/Tools/peg_generator/pegen/c_generator.py @@ -722,4 +722,7 @@ class CParserGenerator(ParserGenerator, GrammarVisitor): 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 |