Reader: Improve HashMap logic
This commit is contained in:
+5
-3
@@ -180,13 +180,12 @@ ValuePtr Reader::readHashMap()
|
|||||||
auto hash_map = makePtr<HashMap>();
|
auto hash_map = makePtr<HashMap>();
|
||||||
while (!isEOF() && peek().type != Token::Type::BraceClose) {
|
while (!isEOF() && peek().type != Token::Type::BraceClose) {
|
||||||
auto key = readImpl();
|
auto key = readImpl();
|
||||||
auto value = readImpl();
|
|
||||||
|
|
||||||
if (key == nullptr && value == nullptr) {
|
if (key == nullptr || isEOF()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key == nullptr || value == nullptr) {
|
if (peek().type == Token::Type::BraceClose) {
|
||||||
Error::the().add("hash-map requires an even-sized list");
|
Error::the().add("hash-map requires an even-sized list");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@@ -196,12 +195,15 @@ ValuePtr Reader::readHashMap()
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto value = readImpl();
|
||||||
|
|
||||||
std::string keyString = is<String>(key.get()) ? std::static_pointer_cast<String>(key)->data() : std::static_pointer_cast<Keyword>(key)->keyword();
|
std::string keyString = is<String>(key.get()) ? std::static_pointer_cast<String>(key)->data() : std::static_pointer_cast<Keyword>(key)->keyword();
|
||||||
hash_map->add(keyString, value);
|
hash_map->add(keyString, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!consumeSpecific(Token { .type = Token::Type::BraceClose })) { // }
|
if (!consumeSpecific(Token { .type = Token::Type::BraceClose })) { // }
|
||||||
Error::the().add("expected '}', got EOF");
|
Error::the().add("expected '}', got EOF");
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return hash_map;
|
return hash_map;
|
||||||
|
|||||||
Reference in New Issue
Block a user