(text: string, i: number, c: number, out: Array<unknown>)
| 287 | |
| 288 | // Handles one structural character and returns the next index. |
| 289 | step(text: string, i: number, c: number, out: Array<unknown>): number { |
| 290 | const frame = this.frames[this.frames.length - 1] |
| 291 | switch (this.state) { |
| 292 | case VALUE: { |
| 293 | const target = this.frames.length === this.config.tokens.length |
| 294 | if (c === LBRACKET || (c === LBRACE && !target)) { |
| 295 | this.frames.push({ object: c === LBRACE, target, found: false, index: 0 }) |
| 296 | this.state = c === LBRACE ? OBJECT_START : ARRAY_START |
| 297 | return i + 1 |
| 298 | } |
| 299 | if (isValueStart(c)) { |
| 300 | const expected = target ? "an array" : "an object or array" |
| 301 | throw this.fail( |
| 302 | "Pointer", |
| 303 | `Expected ${expected} at ${this.pointerPrefix(this.frames.length)}`, |
| 304 | this.base + i |
| 305 | ) |
| 306 | } |
| 307 | break |
| 308 | } |
| 309 | case OBJECT_START: |
| 310 | case OBJECT_KEY: { |
| 311 | if (c === QUOTE) { |
| 312 | this.state = OBJECT_COLON |
| 313 | return this.begin(KEY, text, i, out) |
| 314 | } |
| 315 | if (c === RBRACE && this.state === OBJECT_START) return this.close(i) |
| 316 | break |
| 317 | } |
| 318 | case OBJECT_COLON: { |
| 319 | if (c !== COLON) break |
| 320 | if (this.key === this.config.tokens[this.frames.length - 1]) { |
| 321 | if (frame.found) { |
| 322 | throw this.fail("Pointer", `Duplicate key ${JSON.stringify(this.key)} along the pointer`, this.base + i) |
| 323 | } |
| 324 | frame.found = true |
| 325 | this.state = VALUE |
| 326 | } else { |
| 327 | this.state = OBJECT_VALUE |
| 328 | } |
| 329 | return i + 1 |
| 330 | } |
| 331 | case OBJECT_VALUE: { |
| 332 | if (!isValueStart(c)) break |
| 333 | this.state = OBJECT_NEXT |
| 334 | return this.begin(SKIP, text, i, out) |
| 335 | } |
| 336 | case OBJECT_NEXT: |
| 337 | case ARRAY_NEXT: { |
| 338 | if (c === COMMA) { |
| 339 | this.state = this.state === OBJECT_NEXT ? OBJECT_KEY : ARRAY_VALUE |
| 340 | return i + 1 |
| 341 | } |
| 342 | if (c === (this.state === OBJECT_NEXT ? RBRACE : RBRACKET)) return this.close(i) |
| 343 | break |
| 344 | } |
| 345 | case ARRAY_START: |
| 346 | case ARRAY_VALUE: { |
no test coverage detected