| 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] ')' |