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

Method parseArray

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

Source from the content-addressed store, hash-verified

79 }
80
81 private parseArray(): any[] {
82 const arr: any[] = [];
83 this.expectChar('[');
84 this.skipWhitespace();
85 // Empty array?
86 if (this.currentChar() === ']') {
87 this.index++; // consume "]"
88 return arr;
89 }
90 while (true) {
91 this.skipWhitespace();
92 arr.push(this.parseValue());
93 this.skipWhitespace();
94 if (this.currentChar() === ',') {
95 this.index++; // consume comma
96 this.skipWhitespace();
97 // Allow trailing comma:
98 if (this.currentChar() === ']') {
99 this.index++;
100 break;
101 }
102 } else if (this.currentChar() === ']') {
103 this.index++; // consume "]"
104 break;
105 } else {
106 throw this.error(
107 `Expected ',' or ']' in array but found '${this.currentChar()}'`
108 );
109 }
110 }
111 return arr;
112 }
113
114 private parseString(): string {
115 const quote = this.currentChar();

Callers 1

parseValueMethod · 0.95

Calls 5

expectCharMethod · 0.95
skipWhitespaceMethod · 0.95
currentCharMethod · 0.95
parseValueMethod · 0.95
errorMethod · 0.95

Tested by

no test coverage detected