MCPcopy Index your code
hub / github.com/aiscript-dev/aiscript / parseDoWhile

Function parseDoWhile

src/parser/syntaxes/statements.ts:453–474  ·  view source on GitHub ↗

* ```abnf * Loop = "do" BlockOrStatement "while" Expr * ```

(s: ITokenStream)

Source from the content-addressed store, hash-verified

451 * ```
452*/
453function parseDoWhile(s: ITokenStream): Ast.Loop {
454 const doStartPos = s.getPos();
455 s.expect(TokenKind.DoKeyword);
456 s.next();
457 const body = parseBlockOrStatement(s);
458 const whilePos = s.getPos();
459 s.expect(TokenKind.WhileKeyword);
460 s.next();
461 const cond = parseExpr(s, false);
462 const endPos = s.getPos();
463
464 return NODE('loop', {
465 statements: [
466 body,
467 NODE('if', {
468 cond: NODE('not', { expr: cond }, whilePos, endPos),
469 then: NODE('break', {}, endPos, endPos),
470 elseif: [],
471 }, whilePos, endPos),
472 ],
473 }, doStartPos, endPos);
474}
475
476/**
477 * ```abnf

Callers 1

parseStatementFunction · 0.85

Calls 6

parseBlockOrStatementFunction · 0.85
parseExprFunction · 0.85
NODEFunction · 0.85
getPosMethod · 0.65
expectMethod · 0.65
nextMethod · 0.65

Tested by

no test coverage detected