-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.zig
49 lines (40 loc) · 1.37 KB
/
demo.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const std = @import("std");
const Inon = @import("inon");
pub fn main() anyerror!void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
const stdout = std.io.getStdOut().writer();
var inon = Inon.init(allocator);
defer inon.deinit();
try Inon.Stdlib.addAll(&inon);
var data = inon.parse("<demo>",
\\first_name: "joe"
\\last_name: "some {first_name} thing"
\\age: 50
\\address: {
\\ street_no: switch %{
\\ (= age 30): 420
\\ (= age 40): 40
\\ (= age 50): 50
\\ else: 70
\\ }
\\ num: * (self "street_no") 2
\\ city: "nyc"
\\}
\\phone_nos: [100, 200, 300]
\\second_no: index phone_nos 1
) catch |err| switch (err) {
error.ParsingFailed => return try inon.renderError(stdout),
else => |e| return e,
};
try stdout.print("Deserialized: \n\n", .{});
try stdout.print("{}\n\n", .{@TypeOf(data.value.map)});
try stdout.print("Serialized: \n\n", .{});
try inon.serialize(&data, stdout);
try stdout.writeAll("\n\n");
try stdout.print("Json: \n\n", .{});
try inon.serializeToJson(&data, stdout);
try stdout.writeAll("\n\n");
std.log.info("All your config files are belong to us.", .{});
}