Compare commits

..

No commits in common. "259c22999c14345222992b7cb4d06e1a3e76cadc" and "cf21c48771fd3e186f41d64d04c43d109a4a64d8" have entirely different histories.

2 changed files with 23 additions and 17 deletions

View File

@ -27,5 +27,27 @@ pub fn main() !void {
};
defer doc.deinit();
try std.json.stringify(doc.root, .{}, std.io.getStdOut().writer());
std.debug.print("\n-----\n\n", .{});
dump(doc.root);
}
fn dump(val: yaml.Value) void {
switch (val) {
.scalar => |str| std.debug.print("scalar: {s}\n", .{str}),
.list => |list| {
std.debug.print("list: \n", .{});
for (list) |item| dump(item);
std.debug.print("end list\n", .{});
},
.map => |map| {
std.debug.print("map: \n", .{});
var iter = map.iterator();
while (iter.next()) |entry| {
std.debug.print("key: {s}\n", .{entry.key_ptr.*});
dump(entry.value_ptr.*);
}
std.debug.print("end map\n", .{});
},
}
}

View File

@ -297,20 +297,4 @@ pub const Value = union(enum) {
}
}
};
pub fn jsonStringify(value: @This(), jws: anytype) !void {
switch (value) {
.scalar => |scalar| try jws.write(scalar),
.list => |list| try jws.write(list),
.map => |map| {
try jws.beginObject();
var it = map.iterator();
while (it.next()) |entry| {
try jws.objectField(entry.key_ptr.*);
try jws.write(entry.value_ptr.*);
}
try jws.endObject();
},
}
}
};