MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / parseObject

Method parseObject

src/common/json5.ts:37–79  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

35 }
36
37 private parseObject(): any {
38 const obj: Record<string, any> = {};
39 this.expectChar('{');
40 this.skipWhitespace();
41 // Empty object?
42 if (this.currentChar() === '}') {
43 this.index++; // consume "}"
44 return obj;
45 }
46 while (true) {
47 this.skipWhitespace();
48 let key: string;
49 const ch = this.currentChar();
50 if (ch === '"' || ch === "'") {
51 key = this.parseString();
52 } else {
53 key = this.parseIdentifier();
54 }
55 this.skipWhitespace();
56 this.expectChar(':');
57 this.skipWhitespace();
58 const value = this.parseValue();
59 obj[key] = value;
60 this.skipWhitespace();
61 if (this.currentChar() === ',') {
62 this.index++; // consume comma
63 this.skipWhitespace();
64 // Allow trailing comma: if next is "}", break out.
65 if (this.currentChar() === '}') {
66 this.index++;
67 break;
68 }
69 } else if (this.currentChar() === '}') {
70 this.index++; // consume "}"
71 break;
72 } else {
73 throw this.error(
74 `Expected ',' or '}' in object but found '${this.currentChar()}'`
75 );
76 }
77 }
78 return obj;
79 }
80
81 private parseArray(): any[] {
82 const arr: any[] = [];

Callers 1

parseValueMethod · 0.95

Calls 7

expectCharMethod · 0.95
skipWhitespaceMethod · 0.95
currentCharMethod · 0.95
parseStringMethod · 0.95
parseIdentifierMethod · 0.95
parseValueMethod · 0.95
errorMethod · 0.95

Tested by

no test coverage detected