MCPcopy Index your code
hub / github.com/python/cpython / flatten

Method flatten

Tools/peg_generator/pegen/grammar.py:92–102  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

90 yield self.rhs
91
92 def flatten(self) -> Rhs:
93 # If it's a single parenthesized group, flatten it.
94 rhs = self.rhs
95 if (
96 not self.is_loop()
97 and len(rhs.alts) == 1
98 and len(rhs.alts[0].items) == 1
99 and isinstance(rhs.alts[0].items[0].item, Group)
100 ):
101 rhs = rhs.alts[0].items[0].item.rhs
102 return rhs
103
104
105class Leaf:

Callers 3

visit_RuleMethod · 0.45
visit_RuleMethod · 0.45
visit_RuleMethod · 0.45

Calls 1

is_loopMethod · 0.95

Tested by

no test coverage detected