Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

addErrorsFromNode

main.addErrorsFromNode
fn addErrorsFromNode(
    decl_index: Decl.Index,
    out: *std.array_hash_map.String(ErrorIdentifier),
    node: Ast.Node.Index,
) Oom!void

File

lib/docs/wasm/main.zig:344

Code

fn addErrorsFromNode(
    decl_index: Decl.Index,
    out: *std.array_hash_map.String(ErrorIdentifier),
    node: Ast.Node.Index,
) Oom!void {
    const decl = decl_index.get();
    const ast = decl.file.get_ast();
    const error_token = ast.nodeMainToken(node);
    var tok_i = error_token + 2;
    while (true) : (tok_i += 1) switch (ast.tokenTag(tok_i)) {
        .doc_comment, .comma => {},
        .identifier => {
            const name = ast.tokenSlice(tok_i);
            const gop = try out.getOrPut(gpa, name);
            // If there are more than one, take the one with doc comments.
            // If they both have doc comments, prefer the existing one.
            const new: ErrorIdentifier = .{
                .token_index = tok_i,
                .decl_index = decl_index,
            };
            if (!gop.found_existing or
                (!gop.value_ptr.hasDocs() and new.hasDocs()))
            {
                gop.value_ptr.* = new;
            }
        },
        .r_brace => break,
        else => unreachable,
    };
}