| 644 | } |
| 645 | |
| 646 | bool Reader::readObject(Token& tokenStart) { |
| 647 | Token tokenName; |
| 648 | std::string name; |
| 649 | Value init(objectValue); |
| 650 | currentValue().swapPayload(init); |
| 651 | currentValue().setOffsetStart(tokenStart.start_ - begin_); |
| 652 | while (readToken(tokenName)) { |
| 653 | bool initialTokenOk = true; |
| 654 | while (tokenName.type_ == tokenComment && initialTokenOk) |
| 655 | initialTokenOk = readToken(tokenName); |
| 656 | if (!initialTokenOk) |
| 657 | break; |
| 658 | if (tokenName.type_ == tokenObjectEnd && name.empty()) // empty object |
| 659 | return true; |
| 660 | name = ""; |
| 661 | if (tokenName.type_ == tokenString) { |
| 662 | if (!decodeString(tokenName, name)) |
| 663 | return recoverFromError(tokenObjectEnd); |
| 664 | } else if (tokenName.type_ == tokenNumber && features_.allowNumericKeys_) { |
| 665 | Value numberName; |
| 666 | if (!decodeNumber(tokenName, numberName)) |
| 667 | return recoverFromError(tokenObjectEnd); |
| 668 | name = numberName.asString(); |
| 669 | } else { |
| 670 | break; |
| 671 | } |
| 672 | |
| 673 | Token colon; |
| 674 | if (!readToken(colon) || colon.type_ != tokenMemberSeparator) { |
| 675 | return addErrorAndRecover( |
| 676 | "Missing ':' after object member name", colon, tokenObjectEnd); |
| 677 | } |
| 678 | Value& value = currentValue()[name]; |
| 679 | nodes_.push(&value); |
| 680 | bool ok = readValue(); |
| 681 | nodes_.pop(); |
| 682 | if (!ok) // error already set |
| 683 | return recoverFromError(tokenObjectEnd); |
| 684 | |
| 685 | Token comma; |
| 686 | if (!readToken(comma) || |
| 687 | (comma.type_ != tokenObjectEnd && comma.type_ != tokenArraySeparator && |
| 688 | comma.type_ != tokenComment)) { |
| 689 | return addErrorAndRecover( |
| 690 | "Missing ',' or '}' in object declaration", comma, tokenObjectEnd); |
| 691 | } |
| 692 | bool finalizeTokenOk = true; |
| 693 | while (comma.type_ == tokenComment && finalizeTokenOk) |
| 694 | finalizeTokenOk = readToken(comma); |
| 695 | if (comma.type_ == tokenObjectEnd) |
| 696 | return true; |
| 697 | } |
| 698 | return addErrorAndRecover( |
| 699 | "Missing '}' or object member name", tokenName, tokenObjectEnd); |
| 700 | } |
| 701 | |
| 702 | bool Reader::readArray(Token& tokenStart) { |
| 703 | Value init(arrayValue); |
nothing calls this directly
no test coverage detected