Zig TOML v1.0.0 parser.
This is a top-down LL parser that parses directly into Zig structs.
i16
, f32
.Add zig-toml
to your build.zig.zon
# For zig-master
zig fetch --save git+https://github.com/sam701/zig-toml
# For zig 0.13
zig fetch --save git+https://github.com/sam701/zig-toml#last-zig-0.13
See example1.zig
for the complete code that parses example.toml
Run it with zig build examples
// ....
const Address = struct {
port: i64,
host: []const u8,
};
const Config = struct {
master: bool,
expires_at: toml.DateTime,
description: []const u8,
local: *Address,
peers: []const Address,
};
pub fn main() anyerror!void {
var parser = toml.Parser(Config).init(allocator);
defer parser.deinit();
var result = try parser.parseFile("./examples/example1.toml");
defer result.deinit();
const config = result.value;
std.debug.print("{s}\nlocal address: {s}:{}\n", .{ config.description, config.local.host, config.local.port });
std.debug.print("peer0: {s}:{}\n", .{ config.peers[0].host, config.peers[0].port });
}
TODO
MIT