Hello, I'm trying to use zon file as a configuration file for my project, I'm almost there but my problem is my code panics when in config file is an array and i can't check its tag becouse it fails when i want to get node from fields.
fn process_ast(config: *Config, ast: std.zig.Ast) !void {
var buf: [2]std.zig.Ast.Node.Index = undefined;
const root = ast.fullStructInit(&buf, ast.nodes.items(.data)[0].lhs) orelse {
return error.ParseError;
};
const allocator = config._arena.allocator();
for (root.ast.fields) |field_idx| {
const field_name = ast.tokenSlice(ast.firstToken(field_idx) - 2);
const whitelist = std.ArrayList(std.net.Address).init(allocator);
errdefer whitelist.deinit();
const node = root.ast.fields[field_idx - 1];
const info: std.zig.Ast.Node = ast.nodes.get(node);
std.debug.print("{s}:{any}\n", .{ field_name, info.tag });
switch (info.tag) {
std.zig.Ast.Node.Tag.number_literal => {
const value = utils.parse_number(ast, field_idx);
try assign_field_value(config, field_name, value.int);
},
std.zig.Ast.Node.Tag.string_literal => {
const value = try utils.parse_string(allocator, ast, field_idx);
defer allocator.free(value);
try assign_field_value(config, field_name, value);
},
else => continue,
}
}
}