示例#1
0
文件: Any.cpp 项目: lev1976g/easywow
	void Any::deserializeBody(TextInput& ti, Token& token) {
		char closeSymbol = '}';
		m_type = TABLE;

		const char c = token.string()[0];

		if (c != '{') {
			m_type = ARRAY;
			// Chose the appropriate close symbol
			closeSymbol = (c == '(') ? ')' : ']';
		}

		// Allocate the underlying data structure
		ensureData();
		m_data->source.set(ti, token);

		// Consume the open token
		token = ti.read();

		while (!((token.type() == Token::SYMBOL) && (token.string()[0] == closeSymbol))) {
			// Read any leading comment.  This must be done here (and not in the recursive deserialize
			// call) in case the body contains only a comment.
			std::string comment;
			deserializeComment(ti, token, comment);

			if ((token.type() == Token::SYMBOL) && (token.string()[0] == closeSymbol)) {
				// We're done; this catches the case where the array is empty
				break;
			}

			// Pointer the value being read
			Any a;
			std::string key;

			if (m_type == TABLE) {
				// Read the key
				if (token.type() != Token::SYMBOL && token.type() != Token::STRING) {
					throw ParseError(ti.filename(), token.line(), token.character(), "Expected a name");
				}

				key = token.string();
				// Consume everything up to the = sign
				token = ti.readSignificant();

				if ((token.type() != Token::SYMBOL) || (token.string() != "=")) {
					throw ParseError(ti.filename(), token.line(), token.character(), "Expected =");
				}
				else {
					// Consume (don't consume comments--we want the value pointed to by a to get those).
					token = ti.read();
				}
			}
			a.deserialize(ti, token);

			if (!comment.empty()) {
				// Prepend the comment we read earlier
				a.ensureData();
				a.m_data->comment = trimWhitespace(comment + "\n" + a.m_data->comment);
			}

			if (m_type == TABLE) {
				set(key, a);
			}
			else {
				append(a);
			}

			// Read until the comma or close paren, discarding trailing comments and newlines
			readUntilCommaOrClose(ti, token);

			// Consume the comma
			if (isSeparator(token.string()[0])) {
				token = ti.read();
			}
		}

		// Consume the close paren (to match other deserialize methods)
		token = ti.read();
	}
void Texture::Specification::deserialize(BinaryInput& b) {
    Any a;
    a.deserialize(b);
    *this = a;
}