mirror of
https://github.com/python/cpython.git
synced 2025-11-01 06:01:29 +00:00
bpo-41044: Generate valid PEG python parsers for opt+seq rules (GH-20995)
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
This commit is contained in:
parent
af157fad28
commit
55460ee6dc
2 changed files with 15 additions and 1 deletions
|
|
@ -93,7 +93,13 @@ def visit_NegativeLookahead(self, node: NegativeLookahead) -> Tuple[None, str]:
|
|||
|
||||
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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue