Everywhere: Pass step2 tests by supporting hash-maps

This commit is contained in:
Riyyi
2023-03-24 22:28:31 +01:00
parent 5c5a766b7e
commit c6ea42bc5d
6 changed files with 50 additions and 12 deletions
+21 -3
View File
@@ -193,9 +193,27 @@ ASTNode* Reader::readHashMap()
{
ignore(); // {
HashMap* vector = new HashMap();
HashMap* hash_map = new HashMap();
while (!isEOF() && peek().type != Token::Type::BraceClose) {
vector->addNode(readImpl());
ASTNode* key = readImpl();
ASTNode* value = readImpl();
if (!key && !value) {
break;
}
if (!key || !value) {
Error::the().addError("hash-map requires an even-sized list");
return nullptr;
}
if (!is<String>(key) && !is<Keyword>(key)) {
Error::the().addError(format("{} is not a string or keyword", key));
return nullptr;
}
std::string keyString = is<String>(key) ? static_cast<String*>(key)->data() : static_cast<Keyword*>(key)->keyword();
hash_map->addElement(keyString, value);
}
if (!consumeSpecific(Token { .type = Token::Type::BraceClose })) { // }
@@ -203,7 +221,7 @@ ASTNode* Reader::readHashMap()
m_is_unbalanced = true;
}
return vector;
return hash_map;
}
ASTNode* Reader::readQuote()