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.

scanDecls

Walk.scanDecls
fn scanDecls(w: *Walk, namespace: *Scope.Namespace, members: []const Ast.Node.Index) Oom!void

File

lib/docs/wasm/Walk.zig:1030

Code

fn scanDecls(w: *Walk, namespace: *Scope.Namespace, members: []const Ast.Node.Index) Oom!void {
    const ast = w.file.get_ast();

    for (members) |member_node| {
        const name_token = switch (ast.nodeTag(member_node)) {
            .global_var_decl,
            .local_var_decl,
            .simple_var_decl,
            .aligned_var_decl,
            => ast.nodeMainToken(member_node) + 1,

            .fn_proto_simple,
            .fn_proto_multi,
            .fn_proto_one,
            .fn_proto,
            .fn_decl,
            => blk: {
                const ident = ast.nodeMainToken(member_node) + 1;
                if (ast.tokenTag(ident) != .identifier) continue;
                break :blk ident;
            },

            .test_decl => {
                const opt_ident_token = ast.nodeData(member_node).opt_token_and_node[0];
                if (opt_ident_token.unwrap()) |ident_token| {
                    const is_doctest = ast.tokenTag(ident_token) == .identifier;
                    if (is_doctest) {
                        const token_bytes = ast.tokenSlice(ident_token);
                        try namespace.doctests.put(gpa, token_bytes, member_node);
                    }
                }
                continue;
            },

            else => continue,
        };

        const token_bytes = ast.tokenSlice(name_token);
        try namespace.names.put(gpa, token_bytes, member_node);
    }
}