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.

renderCall

ast.renderCall
fn renderCall(c: *Context, lhs: NodeIndex, args: []const Node) !NodeIndex

File

Code

fn renderCall(c: *Context, lhs: NodeIndex, args: []const Node) !NodeIndex {
    const lparen = try c.addToken(.l_paren, "(");
    const res = switch (args.len) {
        0 => try c.addNode(.{
            .tag = .call_one,
            .main_token = lparen,
            .data = .{ .node_and_opt_node = .{
                lhs, .none,
            } },
        }),
        1 => try c.addNode(.{
            .tag = .call_one,
            .main_token = lparen,
            .data = .{ .node_and_opt_node = .{
                lhs, (try renderNode(c, args[0])).toOptional(),
            } },
        }),
        else => blk: {
            var rendered = try c.gpa.alloc(NodeIndex, args.len);
            defer c.gpa.free(rendered);

            for (args, 0..) |arg, i| {
                if (i != 0) _ = try c.addToken(.comma, ",");
                rendered[i] = try renderNode(c, arg);
            }
            const span = try c.listToSpan(rendered);
            break :blk try c.addNode(.{
                .tag = .call,
                .main_token = lparen,
                .data = .{ .node_and_extra = .{
                    lhs,
                    try c.addExtra(NodeSubRange{
                        .start = span.start,
                        .end = span.end,
                    }),
                } },
            });
        },
    };
    _ = try c.addToken(.r_paren, ")");
    return res;
}