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

Function parseAttr

src/parser/syntaxes/statements.ts:409–431  ·  view source on GitHub ↗

* ```abnf * Attr = "#[" IDENT [StaticExpr] "]" * ```

(s: ITokenStream)

Source from the content-addressed store, hash-verified

407 * ```
408*/
409function parseAttr(s: ITokenStream): Ast.Attribute {
410 const startPos = s.getPos();
411
412 s.expect(TokenKind.OpenSharpBracket);
413 s.next();
414
415 s.expect(TokenKind.Identifier);
416 const name = s.getTokenValue();
417 s.next();
418
419 let value: Ast.Expression;
420 if (!s.is(TokenKind.CloseBracket)) {
421 value = parseExpr(s, true);
422 } else {
423 const closePos = s.getPos();
424 value = NODE('bool', { value: true }, closePos, closePos);
425 }
426
427 s.expect(TokenKind.CloseBracket);
428 s.next();
429
430 return NODE('attr', { name, value }, startPos, s.getPos());
431}
432
433/**
434 * ```abnf

Callers 1

parseStatementWithAttrFunction · 0.85

Calls 7

parseExprFunction · 0.85
NODEFunction · 0.85
getPosMethod · 0.65
expectMethod · 0.65
nextMethod · 0.65
getTokenValueMethod · 0.65
isMethod · 0.65

Tested by

no test coverage detected