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

Class Parser

Tools/cases_generator/parsing.py:332–715  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

330
331
332class Parser(PLexer):
333 @contextual
334 def definition(self) -> AstNode | None:
335 if macro := self.macro_def():
336 return macro
337 if family := self.family_def():
338 return family
339 if pseudo := self.pseudo_def():
340 return pseudo
341 if inst := self.inst_def():
342 return inst
343 if label := self.label_def():
344 return label
345 return None
346
347 @contextual
348 def label_def(self) -> LabelDef | None:
349 spilled = False
350 if self.expect(lx.SPILLED):
351 spilled = True
352 if self.expect(lx.LABEL):
353 if self.expect(lx.LPAREN):
354 if tkn := self.expect(lx.IDENTIFIER):
355 if self.expect(lx.RPAREN):
356 block = self.block()
357 return LabelDef(tkn.text, spilled, block)
358 return None
359
360 @contextual
361 def inst_def(self) -> InstDef | None:
362 if hdr := self.inst_header():
363 block = self.block()
364 return InstDef(
365 hdr.annotations,
366 hdr.kind,
367 hdr.name,
368 hdr.inputs,
369 hdr.outputs,
370 block,
371 )
372 return None
373
374 @contextual
375 def inst_header(self) -> InstHeader | None:
376 # annotation* inst(NAME, (inputs -- outputs))
377 # | annotation* op(NAME, (inputs -- outputs))
378 annotations = []
379 while anno := self.expect(lx.ANNOTATION):
380 if anno.text == "replicate":
381 self.require(lx.LPAREN)
382 stop = self.require(lx.NUMBER)
383 start_text = "0"
384 if self.expect(lx.COLON):
385 start_text = stop.text
386 stop = self.require(lx.NUMBER)
387 self.require(lx.RPAREN)
388 annotations.append(f"replicate({start_text}:{stop.text})")
389 else:

Callers 2

parse_filesFunction · 0.90
parsing.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…