diff options
author | Batuhan Taskaya <isidentical@gmail.com> | 2020-06-20 17:40:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-20 17:40:06 (GMT) |
commit | 55460ee6dc9a4f16bd68d6b6be3a8398c7d4a596 (patch) | |
tree | 2be1b8e48d5d63eb03eea14257faba853b475354 /Tools | |
parent | af157fad286c00ff204e86d8556648cbb53ba99e (diff) | |
download | cpython-55460ee6dc9a4f16bd68d6b6be3a8398c7d4a596.zip cpython-55460ee6dc9a4f16bd68d6b6be3a8398c7d4a596.tar.gz cpython-55460ee6dc9a4f16bd68d6b6be3a8398c7d4a596.tar.bz2 |
bpo-41044: Generate valid PEG python parsers for opt+seq rules (GH-20995)
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Diffstat (limited to 'Tools')
-rw-r--r-- | Tools/peg_generator/pegen/python_generator.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Tools/peg_generator/pegen/python_generator.py b/Tools/peg_generator/pegen/python_generator.py index 6433655..45a7597 100644 --- a/Tools/peg_generator/pegen/python_generator.py +++ b/Tools/peg_generator/pegen/python_generator.py @@ -93,7 +93,13 @@ class PythonCallMakerVisitor(GrammarVisitor): def visit_Opt(self, node: Opt) -> Tuple[str, str]: name, call = self.visit(node.node) - return "opt", f"{call}," # Note trailing comma! + # Note trailing comma (the call may already have one comma + # at the end, for example when rules have both repeat0 and optional + # markers, e.g: [rule*]) + if call.endswith(","): + return "opt", call + else: + return "opt", f"{call}," def visit_Repeat0(self, node: Repeat0) -> Tuple[str, str]: if node in self.cache: |