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

Function parseObject

src/parser/syntaxes/expressions.ts:583–631  ·  view source on GitHub ↗

* ```abnf * Object = "{" [ObjectKey ":" Expr *(SEP IDENT ":" Expr) [SEP]] "}" * ```

(s: ITokenStream, isStatic: boolean)

Source from the content-addressed store, hash-verified

581 * ```
582*/
583function parseObject(s: ITokenStream, isStatic: boolean): Ast.Obj {
584 const startPos = s.getPos();
585
586 s.expect(TokenKind.OpenBrace);
587 s.next();
588
589 while (s.is(TokenKind.NewLine)) {
590 s.next();
591 }
592
593 const map = new Map<string, Ast.Expression>();
594 while (!s.is(TokenKind.CloseBrace)) {
595 const k = parseObjectKey(s);
596 s.next();
597
598 s.expect(TokenKind.Colon);
599 s.next();
600
601 const v = parseExpr(s, isStatic);
602
603 map.set(k, v);
604
605 // separator
606 switch (s.getTokenKind()) {
607 case TokenKind.NewLine:
608 case TokenKind.Comma: {
609 s.next();
610 while (s.is(TokenKind.NewLine)) {
611 s.next();
612 }
613 break;
614 }
615 case TokenKind.CloseBrace: {
616 break;
617 }
618 case TokenKind.EOF: {
619 throw new AiScriptUnexpectedEOFError(s.getPos());
620 }
621 default: {
622 throw new AiScriptSyntaxError('separator expected', s.getPos());
623 }
624 }
625 }
626
627 s.expect(TokenKind.CloseBrace);
628 s.next();
629
630 return NODE('obj', { value: map }, startPos, s.getPos());
631}
632
633/**
634 * ```abnf

Callers 1

parseAtomFunction · 0.85

Calls 9

parseObjectKeyFunction · 0.85
parseExprFunction · 0.85
NODEFunction · 0.85
getPosMethod · 0.65
expectMethod · 0.65
nextMethod · 0.65
isMethod · 0.65
setMethod · 0.65
getTokenKindMethod · 0.65

Tested by

no test coverage detected