Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support For Yaml Bool #40

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

caleberi
Copy link

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.

Copy link
Owner

@kubkon kubkon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! If you don't mind I have a request to make this patch even better. Let me know what you think!

src/yaml.zig Outdated
Comment on lines 200 to 201
const isTruthy = std.mem.eql(u8, raw, "true");
const isFalsy = std.mem.eql(u8, raw, "false");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am no YAML expert but I think we should handle all possible variants for a boolean:

y|Y|yes|Yes|YES|n|N|no|No|NO|
true|True|TRUE|false|False|FALSE|
on|On|ON|off|Off|OFF

taken from https://stackoverflow.com/questions/53648244/specifying-the-string-value-yes-in-yaml#53648738

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I will look into this

Copy link
Author

@caleberi caleberi Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kubkon I checked the yaml specification and it seems y|Y|yes|Yes|YES|n|N|no|No|NO is a backwards-compatible support but it will be nice to have for this project.

I have gone ahead to include it in this PR. Hopefully, it is optimal enough. I was looking for a constant solution but so far this is what I have come up with

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants