GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix 'gather' rules in the python parser generator (GH-22021) · python/cpython@e55a0e9

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Lib/test/test_peg_generator
    • test_pegen.py
  • Tools/peg_generator/pegen
    • python_generator.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Lib/test/test_peg_generator/test_pegen.py‎

Copy file name to clipboardExpand all lines: Lib/test/test_peg_generator/test_pegen.py
+15-1Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_typed_rules(self) -> None:
7474
"Rule('term', 'int', Rhs([Alt([NamedItem(None, NameLeaf('NUMBER'))])]))"
7575
)
7676

77-
def test_repeat_with_separator_rules(self) -> None:
77+
def test_gather(self) -> None:
7878
grammar = """
7979
start: ','.thing+ NEWLINE
8080
thing: NUMBER
@@ -85,6 +85,20 @@ def test_repeat_with_separator_rules(self) -> None:
8585
"Rule('start', None, Rhs([Alt([NamedItem(None, Gather(StringLeaf(\"','\"), NameLeaf('thing'"
8686
))
8787
self.assertEqual(str(rules["thing"]), "thing: NUMBER")
88+
parser_class = make_parser(grammar)
89+
node = parse_string("42\n", parser_class)
90+
assert node == [
91+
[[TokenInfo(NUMBER, string="42", start=(1, 0), end=(1, 2), line="42\n")]],
92+
TokenInfo(NEWLINE, string="\n", start=(1, 2), end=(1, 3), line="42\n"),
93+
]
94+
node = parse_string("1, 2\n", parser_class)
95+
assert node == [
96+
[
97+
[TokenInfo(NUMBER, string="1", start=(1, 0), end=(1, 1), line="1, 2\n")],
98+
[TokenInfo(NUMBER, string="2", start=(1, 3), end=(1, 4), line="1, 2\n")],
99+
],
100+
TokenInfo(NEWLINE, string="\n", start=(1, 4), end=(1, 5), line="1, 2\n"),
101+
]
88102

89103
def test_expr_grammar(self) -> None:
90104
grammar = """
Collapse file

‎Tools/peg_generator/pegen/python_generator.py‎

Copy file name to clipboardExpand all lines: Tools/peg_generator/pegen/python_generator.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ def visit_Alt(self, node: Alt, is_loop: bool, is_gather: bool) -> None:
217217
else:
218218
self.print("and")
219219
self.visit(item)
220+
if is_gather:
221+
self.print("is not None")
222+
220223
self.print("):")
221224
with self.indent():
222225
action = node.action

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.