Skip to content

Add zig implementation#21

Merged
knadh merged 2 commits into
huml-lang:masterfrom
SphericalKat:patch-1
Feb 18, 2026
Merged

Add zig implementation#21
knadh merged 2 commits into
huml-lang:masterfrom
SphericalKat:patch-1

Conversation

@SphericalKat
Copy link
Copy Markdown
Contributor

@SphericalKat SphericalKat commented Jan 7, 2026

Background: I was quite happy to see a zig implementation being PRed in #16, but I quickly ran into hiccups when using it.

  1. It only supports HUML v0.1.0. I wanted support for the latest and greatest v0.2.0.
  2. It does not support serializing into HUML. Deal breaker.
  3. It does not support de/serializing from/to Zig structs. This results in a clunky API where I have to manually do a lot of grunt work which should be abstracted away by a library.

Compare this

const result = huml.parse(input, allocator);
switch (result) {
    .document => |doc| {
        var document = doc.doc;
        defer document.deinit();

        const db = document.root.get("database").?;
        const host = db.get("host").?.asString().?;
        const port = db.get("port").?.asInt().?;
        
        const options = db.get("options").?;
        const pool_size = options.get("pool_size").?.asInt().?;
    },
    // ...
}

To my implementation

const huml = @import("humlz");
const std = @import("std");

const Config = struct {
    host: []const u8,
    port: u16,
    debug: bool = false,
};

const data =
    \\host: "localhost"
    \\port: 8080
    \\debug: true
;

var parsed = try huml.parseInto(Config, allocator, data);
defer parsed.deinit();

std.debug.print("Connecting to {s}:{d}\n", .{parsed.value.host, parsed.value.port});

Feels a lot cleaner imo! Especially type safe error handling.

@lurch
Copy link
Copy Markdown
Contributor

lurch commented Feb 4, 2026

Does 6089bac mean that this is no longer needed?

@knadh knadh merged commit 144d160 into huml-lang:master Feb 18, 2026
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.

3 participants