|
|
@ -307,7 +307,7 @@ Value Parser::getObject() |
|
|
|
|
|
|
|
|
|
|
|
Value object = Value::Type::Object; |
|
|
|
Value object = Value::Type::Object; |
|
|
|
Token token; |
|
|
|
Token token; |
|
|
|
std::string key; |
|
|
|
std::string name; |
|
|
|
std::map<std::string, uint8_t> unique; |
|
|
|
std::map<std::string, uint8_t> unique; |
|
|
|
for (;;) { |
|
|
|
for (;;) { |
|
|
|
token = consume(); |
|
|
|
token = consume(); |
|
|
@ -319,20 +319,20 @@ Value Parser::getObject() |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
// Find string key
|
|
|
|
// Find string name
|
|
|
|
if (token.type != Token::Type::String) { |
|
|
|
if (token.type != Token::Type::String) { |
|
|
|
reportError(token, "expecting string, or '}' not '" + token.symbol + "'"); |
|
|
|
reportError(token, "expecting string, or '}' not '" + token.symbol + "'"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Check if key exists in hashmap
|
|
|
|
// Check if name exists in hashmap
|
|
|
|
key = token.symbol; |
|
|
|
name = token.symbol; |
|
|
|
if (unique.find(key) != unique.end()) { |
|
|
|
if (unique.find(name) != unique.end()) { |
|
|
|
reportError(token, "duplicate key '" + token.symbol + "', names should be unique"); |
|
|
|
reportError(token, "duplicate name '" + token.symbol + "', names should be unique"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
// Add key to hashmap
|
|
|
|
// Add name to hashmap
|
|
|
|
unique.insert({ key, 0 }); |
|
|
|
unique.insert({ name, 0 }); |
|
|
|
|
|
|
|
|
|
|
|
// Find :
|
|
|
|
// Find :
|
|
|
|
token = consume(); |
|
|
|
token = consume(); |
|
|
@ -344,26 +344,28 @@ Value Parser::getObject() |
|
|
|
// Add member (name:value pair) to object
|
|
|
|
// Add member (name:value pair) to object
|
|
|
|
token = consume(); |
|
|
|
token = consume(); |
|
|
|
if (token.type == Token::Type::Literal) { |
|
|
|
if (token.type == Token::Type::Literal) { |
|
|
|
printf("Adding literal to object.. k:{%s}, v:{%s}, t:{%d}\n", key.c_str(), token.symbol.c_str(), (int)token.type); |
|
|
|
printf("Adding literal to object.. k:{%s}, v:{%s}, t:{%d}\n", name.c_str(), token.symbol.c_str(), (int)token.type); |
|
|
|
m_index--; |
|
|
|
m_index--; |
|
|
|
object[key] = getLiteral(); |
|
|
|
object[name] = getLiteral(); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (token.type == Token::Type::Number) { |
|
|
|
else if (token.type == Token::Type::Number) { |
|
|
|
printf("Adding number to object.. k:{%s}, v:{%s}, t:{%d} -> %f\n", name.c_str(), token.symbol.c_str(), (int)token.type, std::stod(token.symbol)); |
|
|
|
printf("Adding number to object.. k:{%s}, v:{%s}, t:{%d} -> %f\n", name.c_str(), token.symbol.c_str(), (int)token.type, std::stod(token.symbol)); |
|
|
|
m_index--; |
|
|
|
m_index--; |
|
|
|
object[key] = getNumber(); |
|
|
|
object[name] = getNumber(); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (token.type == Token::Type::String) { |
|
|
|
else if (token.type == Token::Type::String) { |
|
|
|
printf("Adding string to object.. k:{%s}, v:{%s}, t:{%d}\n", key.c_str(), token.symbol.c_str(), (int)token.type); |
|
|
|
#ifdef JSON_DEBUG |
|
|
|
object[key] = token.symbol; |
|
|
|
printf("Adding string to object.. k:{%s}, v:{%s}, t:{%d}\n", name.c_str(), token.symbol.c_str(), (int)token.type); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
object[name] = token.symbol; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (token.type == Token::Type::BracketOpen) { |
|
|
|
else if (token.type == Token::Type::BracketOpen) { |
|
|
|
m_index--; |
|
|
|
m_index--; |
|
|
|
object[key] = getArray(); |
|
|
|
object[name] = getArray(); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (token.type == Token::Type::BraceOpen) { |
|
|
|
else if (token.type == Token::Type::BraceOpen) { |
|
|
|
m_index--; |
|
|
|
m_index--; |
|
|
|
object[key] = getObject(); |
|
|
|
object[name] = getObject(); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
reportError(token, "expecting value, not '" + token.symbol + "'"); |
|
|
|
reportError(token, "expecting value, not '" + token.symbol + "'"); |
|
|
|