MCPcopy Create free account
hub / github.com/aiscript-dev/aiscript / parseFnExpr

Function parseFnExpr

src/parser/syntaxes/expressions.ts:415–439  ·  view source on GitHub ↗

* ```abnf * FnExpr = "@" [TypeParams] Params [":" Type] Block * ```

(s: ITokenStream)

Source from the content-addressed store, hash-verified

413 * ```
414*/
415function parseFnExpr(s: ITokenStream): Ast.Fn {
416 const startPos = s.getPos();
417
418 s.expect(TokenKind.At);
419 s.next();
420
421 let typeParams: Ast.TypeParam[];
422 if (s.is(TokenKind.Lt)) {
423 typeParams = parseTypeParams(s);
424 } else {
425 typeParams = [];
426 }
427
428 const params = parseParams(s);
429
430 let type: Ast.TypeSource | undefined;
431 if (s.is(TokenKind.Colon)) {
432 s.next();
433 type = parseType(s);
434 }
435
436 const body = parseBlock(s);
437
438 return NODE('fn', { typeParams, params, retType: type, children: body }, startPos, s.getPos());
439}
440
441/**
442 * ```abnf

Callers 1

parseAtomFunction · 0.85

Calls 9

parseTypeParamsFunction · 0.85
parseParamsFunction · 0.85
parseTypeFunction · 0.85
parseBlockFunction · 0.85
NODEFunction · 0.85
getPosMethod · 0.65
expectMethod · 0.65
nextMethod · 0.65
isMethod · 0.65

Tested by

no test coverage detected