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

Function parseBreak

src/parser/syntaxes/statements.ts:506–525  ·  view source on GitHub ↗

* ```abnf * Break = "break" ["#" IDENT [Expr]] * ```

(s: ITokenStream)

Source from the content-addressed store, hash-verified

504 * ```
505*/
506function parseBreak(s: ITokenStream): Ast.Break {
507 const startPos = s.getPos();
508
509 s.expect(TokenKind.BreakKeyword);
510 s.next();
511
512 let label: string | undefined;
513 let expr: Ast.Expression | undefined;
514 if (s.is(TokenKind.Sharp)) {
515 label = parseLabel(s);
516
517 if (s.is(TokenKind.Colon)) {
518 throw new AiScriptSyntaxError('cannot omit label from break if expression is given', startPos);
519 } else if (!isStatementTerminator(s)) {
520 expr = parseExpr(s, false);
521 }
522 }
523
524 return NODE('break', { label, expr }, startPos, s.getPos());
525}
526
527/**
528 * ```abnf

Callers 1

parseStatementFunction · 0.85

Calls 8

parseLabelFunction · 0.85
isStatementTerminatorFunction · 0.85
parseExprFunction · 0.85
NODEFunction · 0.85
getPosMethod · 0.65
expectMethod · 0.65
nextMethod · 0.65
isMethod · 0.65

Tested by

no test coverage detected