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

Function parseStatementWithLabel

src/parser/syntaxes/statements.ts:216–236  ·  view source on GitHub ↗

* ```abnf * StatementWithLabel = "#" IDENT ":" Statement * ```

(s: ITokenStream)

Source from the content-addressed store, hash-verified

214 * ```
215*/
216function parseStatementWithLabel(s: ITokenStream): Ast.Each | Ast.For | Ast.Loop | Ast.If | Ast.Match | Ast.Block {
217 const label = parseLabel(s);
218 s.expect(TokenKind.Colon);
219 s.next();
220
221 const statement = parseStatement(s);
222 switch (statement.type) {
223 case 'if':
224 case 'match':
225 case 'block':
226 case 'each':
227 case 'for':
228 case 'loop': {
229 statement.label = label;
230 return statement;
231 }
232 default: {
233 throw new AiScriptSyntaxError('cannot use label for statement other than eval / if / match / for / each / while / do-while / loop', statement.loc.start);
234 }
235 }
236}
237
238/**
239 * ```abnf

Callers 1

parseStatementFunction · 0.85

Calls 4

parseLabelFunction · 0.85
parseStatementFunction · 0.85
expectMethod · 0.65
nextMethod · 0.65

Tested by

no test coverage detected