@@ 344-383 (lines=40) @@ | ||
341 | }; |
|
342 | proto.onToken = function (token, value) { |
|
343 | if(this.state === VALUE){ |
|
344 | if(token === STRING || token === NUMBER || token === TRUE || token === FALSE || token === NULL){ |
|
345 | if (this.value) { |
|
346 | this.value[this.key] = value; |
|
347 | } |
|
348 | this.emit(value); |
|
349 | }else if(token === LEFT_BRACE){ |
|
350 | this.push(); |
|
351 | if (this.value) { |
|
352 | this.value = this.value[this.key] = {}; |
|
353 | } else { |
|
354 | this.value = {}; |
|
355 | } |
|
356 | this.key = undefined; |
|
357 | this.state = KEY; |
|
358 | this.mode = OBJECT; |
|
359 | }else if(token === LEFT_BRACKET){ |
|
360 | this.push(); |
|
361 | if (this.value) { |
|
362 | this.value = this.value[this.key] = []; |
|
363 | } else { |
|
364 | this.value = []; |
|
365 | } |
|
366 | this.key = 0; |
|
367 | this.mode = ARRAY; |
|
368 | this.state = VALUE; |
|
369 | }else if(token === RIGHT_BRACE){ |
|
370 | if (this.mode === OBJECT) { |
|
371 | this.pop(); |
|
372 | } else { |
|
373 | return this.parseError(token, value); |
|
374 | } |
|
375 | }else if(token === RIGHT_BRACKET){ |
|
376 | if (this.mode === ARRAY) { |
|
377 | this.pop(); |
|
378 | } else { |
|
379 | return this.parseError(token, value); |
|
380 | } |
|
381 | }else{ |
|
382 | return this.parseError(token, value); |
|
383 | } |
|
384 | }else if(this.state === KEY){ |
|
385 | if (token === STRING) { |
|
386 | this.key = value; |
|
@@ 384-408 (lines=25) @@ | ||
381 | }else{ |
|
382 | return this.parseError(token, value); |
|
383 | } |
|
384 | }else if(this.state === KEY){ |
|
385 | if (token === STRING) { |
|
386 | this.key = value; |
|
387 | this.state = COLON; |
|
388 | } else if (token === RIGHT_BRACE) { |
|
389 | this.pop(); |
|
390 | } else { |
|
391 | return this.parseError(token, value); |
|
392 | } |
|
393 | }else if(this.state === COLON){ |
|
394 | if (token === COLON) { this.state = VALUE; } |
|
395 | else { return this.parseError(token, value); } |
|
396 | }else if(this.state === COMMA){ |
|
397 | if (token === COMMA) { |
|
398 | if (this.mode === ARRAY) { this.key++; this.state = VALUE; } |
|
399 | else if (this.mode === OBJECT) { this.state = KEY; } |
|
400 | ||
401 | } else if (token === RIGHT_BRACKET && this.mode === ARRAY || token === RIGHT_BRACE && this.mode === OBJECT) { |
|
402 | this.pop(); |
|
403 | } else { |
|
404 | return this.parseError(token, value); |
|
405 | } |
|
406 | }else{ |
|
407 | return this.parseError(token, value); |
|
408 | } |
|
409 | }; |
|
410 | ||
411 | Parser.C = C; |