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

Method alt

Tools/peg_generator/pegen/grammar_parser.py:294–325  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

292
293 @memoize
294 def alt(self) -> Optional[Alt]:
295 # alt: items '$' action | items '$' | items action | items
296 mark = self._mark()
297 if (
298 (items := self.items())
299 and
300 (literal := self.expect('$'))
301 and
302 (action := self.action())
303 ):
304 return Alt ( items + [NamedItem ( None , NameLeaf ( 'ENDMARKER' ) )] , action = action )
305 self._reset(mark)
306 if (
307 (items := self.items())
308 and
309 (literal := self.expect('$'))
310 ):
311 return Alt ( items + [NamedItem ( None , NameLeaf ( 'ENDMARKER' ) )] , action = None )
312 self._reset(mark)
313 if (
314 (items := self.items())
315 and
316 (action := self.action())
317 ):
318 return Alt ( items , action = action )
319 self._reset(mark)
320 if (
321 (items := self.items())
322 ):
323 return Alt ( items , action = None )
324 self._reset(mark)
325 return None
326
327 @memoize
328 def items(self) -> Optional[NamedItemList]:

Callers 1

altsMethod · 0.95

Calls 7

itemsMethod · 0.95
actionMethod · 0.95
AltClass · 0.90
NamedItemClass · 0.90
NameLeafClass · 0.90
expectMethod · 0.45
_resetMethod · 0.45

Tested by

no test coverage detected