kubkon / zig-yaml

YAML parser for Zig
MIT License
139 stars 37 forks source link

Add Support For Yaml Bool #40

Open caleberi opened 1 month ago

caleberi commented 1 month ago

This PR suggest a fix for yaml boolean value particularly true and false value. This was as a result of a boolean usecase

const Simple = struct {
        names: []const []const u8,
        numbers: []const i16,
        nested: struct {
            some: []const u8,
            wick: []const u8,
            ok: bool,
        },
        finally: [4]f16,
        isyaml: bool,
};

Error Detail:

error: Unimplemented
/Users/soundboax/.cache/zig/p/1220841471bd4891cbb199d27cc5e7e0fb0a5b7c5388a70bd24fa3eb7285755c396c/src/yaml.zig:371:9: 0x100f300f7 in parseValue__anon_11054 (zebra)
        return switch (@typeInfo(T)) {
        ^
/Users/soundboax/.cache/zig/p/1220841471bd4891cbb199d27cc5e7e0fb0a5b7c5388a70bd24fa3eb7285755c396c/src/yaml.zig:413:23: 0x100f25b3b in parseOptional__anon_10792 (zebra)
        return @as(T, try self.parseValue(opt_info.child, unwrapped));
                      ^
/Users/soundboax/.cache/zig/p/1220841471bd4891cbb199d27cc5e7e0fb0a5b7c5388a70bd24fa3eb7285755c396c/src/yaml.zig:427:46: 0x100f1331f in parseStruct__anon_10720 (zebra)
                @field(parsed, field.name) = try self.parseOptional(field.type, value);

Proposition:

Since the parse value to a yaml field can also be true or false, this case should be handled. This PR proposes a possiblity for that.