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

Method inst_header

Tools/cases_generator/parsing.py:375–403  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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:
390 annotations.append(anno.text)
391 tkn = self.expect(lx.INST)
392 if not tkn:
393 tkn = self.expect(lx.OP)
394 if tkn:
395 kind = cast(Literal["inst", "op"], tkn.text)
396 if self.expect(lx.LPAREN) and (tkn := self.expect(lx.IDENTIFIER)):
397 name = tkn.text
398 if self.expect(lx.COMMA):
399 inp, outp = self.io_effect()
400 if self.expect(lx.RPAREN):
401 if (tkn := self.peek()) and tkn.kind == lx.LBRACE:
402 return InstHeader(annotations, kind, name, inp, outp)
403 return None
404
405 def io_effect(self) -> tuple[list[InputEffect], list[OutputEffect]]:
406 # '(' [inputs] '--' [outputs] ')'

Callers 1

inst_defMethod · 0.95

Calls 7

expectMethod · 0.95
io_effectMethod · 0.95
castFunction · 0.90
InstHeaderClass · 0.85
requireMethod · 0.80
appendMethod · 0.45
peekMethod · 0.45

Tested by

no test coverage detected