Compare commits
6 Commits
cf21c48771
...
master
Author | SHA1 | Date | |
---|---|---|---|
f431f7aa1c
|
|||
a9f2298132
|
|||
2b643c5221
|
|||
27667032e1
|
|||
259c22999c
|
|||
ab0202a5f7
|
13
build.zig
13
build.zig
@@ -8,11 +8,9 @@ pub fn build(b: *std.Build) void {
|
|||||||
const target = b.standardTargetOptions(.{});
|
const target = b.standardTargetOptions(.{});
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
|
|
||||||
const yaml_zig = b.addModule("libyaml", .{
|
const yaml_zig = b.addModule("zaye", .{
|
||||||
.source_file = .{ .path = "src/yaml.zig" },
|
.root_source_file = b.path("src/zaye.zig"),
|
||||||
});
|
});
|
||||||
// yaml_zig.addIncludePath(.{ .path = b.getInstallPath(.header, "") });
|
|
||||||
// _ = yaml_zig;
|
|
||||||
|
|
||||||
const libyaml = libyaml_build.libyamlLib(b, .{
|
const libyaml = libyaml_build.libyamlLib(b, .{
|
||||||
.name = "libyaml",
|
.name = "libyaml",
|
||||||
@@ -20,16 +18,17 @@ pub fn build(b: *std.Build) void {
|
|||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
yaml_zig.linkLibrary(libyaml);
|
||||||
|
|
||||||
const example_step = b.step("example", "build example");
|
const example_step = b.step("example", "build example");
|
||||||
|
|
||||||
const ex_exe = b.addExecutable(.{
|
const ex_exe = b.addExecutable(.{
|
||||||
.name = "yamltest",
|
.name = "yamltest",
|
||||||
.root_source_file = .{ .path = "example/main.zig" },
|
.root_source_file = b.path("example/main.zig"),
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
});
|
});
|
||||||
ex_exe.linkLibrary(libyaml);
|
ex_exe.root_module.addImport("yaml", yaml_zig);
|
||||||
ex_exe.addModule("yaml", yaml_zig);
|
|
||||||
|
|
||||||
const install = b.addInstallArtifact(ex_exe, .{});
|
const install = b.addInstallArtifact(ex_exe, .{});
|
||||||
example_step.dependOn(&install.step);
|
example_step.dependOn(&install.step);
|
||||||
|
@@ -27,27 +27,5 @@ pub fn main() !void {
|
|||||||
};
|
};
|
||||||
defer doc.deinit();
|
defer doc.deinit();
|
||||||
|
|
||||||
std.debug.print("\n-----\n\n", .{});
|
try std.json.stringify(doc.root, .{}, std.io.getStdOut().writer());
|
||||||
|
|
||||||
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", .{});
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -5,7 +5,7 @@ const std = @import("std");
|
|||||||
|
|
||||||
const LibyamlOptions = struct {
|
const LibyamlOptions = struct {
|
||||||
name: []const u8,
|
name: []const u8,
|
||||||
target: std.zig.CrossTarget,
|
target: std.Build.ResolvedTarget,
|
||||||
optimize: std.builtin.OptimizeMode,
|
optimize: std.builtin.OptimizeMode,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -22,8 +22,8 @@ pub fn libyamlLib(
|
|||||||
const cflags = [_][]const u8{};
|
const cflags = [_][]const u8{};
|
||||||
|
|
||||||
lib.linkLibC();
|
lib.linkLibC();
|
||||||
lib.addIncludePath(.{ .path = include_prefix });
|
lib.addIncludePath(b.path(include_prefix));
|
||||||
lib.addCSourceFiles(&sources, &cflags);
|
lib.addCSourceFiles(.{ .files = &sources, .flags = &cflags });
|
||||||
lib.defineCMacro("YAML_VERSION_MAJOR", "0");
|
lib.defineCMacro("YAML_VERSION_MAJOR", "0");
|
||||||
lib.defineCMacro("YAML_VERSION_MINOR", "2");
|
lib.defineCMacro("YAML_VERSION_MINOR", "2");
|
||||||
lib.defineCMacro("YAML_VERSION_PATCH", "5");
|
lib.defineCMacro("YAML_VERSION_PATCH", "5");
|
||||||
|
@@ -266,7 +266,7 @@ pub const Value = union(enum) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn endMap(self: *Builder, diag: *ParseDiagnostic) !void {
|
fn endMap(self: *Builder, diag: *ParseDiagnostic) !void {
|
||||||
var top = self.container_stack.pop();
|
const top = self.container_stack.pop();
|
||||||
|
|
||||||
if (top != .map) {
|
if (top != .map) {
|
||||||
diag.setMessage("map ended when a map was not the top container");
|
diag.setMessage("map ended when a map was not the top container");
|
||||||
@@ -297,4 +297,20 @@ 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();
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
Reference in New Issue
Block a user