zon: Improve the duplicate key error

This commit is contained in:
IntegratedQuantum 2025-02-28 18:38:50 +01:00
parent b660a26b19
commit 1c64a8e4b7

View File

@ -631,6 +631,7 @@ const Parser = struct { // MARK: Parser
return .{.object = map}; return .{.object = map};
} }
if(chars[index.*] == '.') index.* += 1; // Just ignoring the dot in front of identifiers, the file might as well not have for all I care. if(chars[index.*] == '.') index.* += 1; // Just ignoring the dot in front of identifiers, the file might as well not have for all I care.
const keyIndex = index.*;
const key: []const u8 = parseIdentifierOrStringOrEnumLiteral(allocator, chars, index); const key: []const u8 = parseIdentifierOrStringOrEnumLiteral(allocator, chars, index);
skipWhitespaces(chars, index); skipWhitespaces(chars, index);
while(index.* < chars.len and chars[index.*] != '=') { while(index.* < chars.len and chars[index.*] != '=') {
@ -641,7 +642,7 @@ const Parser = struct { // MARK: Parser
skipWhitespaces(chars, index); skipWhitespaces(chars, index);
const value: ZonElement = parseElement(allocator, chars, index); const value: ZonElement = parseElement(allocator, chars, index);
if(map.fetchPut(key, value) catch unreachable) |old| { if(map.fetchPut(key, value) catch unreachable) |old| {
printError(chars, index.*, "Duplicate key."); printError(chars, keyIndex, "Duplicate key.");
allocator.free(old.key); allocator.free(old.key);
old.value.deinit(allocator); old.value.deinit(allocator);
} }