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.

renderFor

Render.renderFor
fn renderFor(r: *Render, for_node: Ast.full.For, space: Space) Error!void

File

lib/std/zig/Ast/Render.zig:1499

Code

fn renderFor(r: *Render, for_node: Ast.full.For, space: Space) Error!void {
    const tree = r.tree;
    const ais = r.ais;
    const token_tags = tree.tokens.items(.tag);

    if (for_node.label_token) |label| {
        try renderIdentifier(r, label, .none, .eagerly_unquote); // label
        try renderToken(r, label + 1, .space); // :
    }

    if (for_node.inline_token) |inline_token| {
        try renderToken(r, inline_token, .space); // inline
    }

    try renderToken(r, for_node.ast.for_token, .space); // if/for/while

    const lparen = for_node.ast.for_token + 1;
    try renderParamList(r, lparen, for_node.ast.inputs, .space);

    var cur = for_node.payload_token;
    const pipe = std.mem.findScalarPos(Token.Tag, token_tags, cur, .pipe).?;
    const capture_trailing_comma = token_tags[@intCast(pipe - 1)] == .comma;

    if (capture_trailing_comma)
        try ais.pushIndent(.normal);
    try renderToken(r, cur - 1, if (capture_trailing_comma) .newline else .none); // |
    while (true) {
        if (token_tags[cur] == .asterisk) {
            try renderToken(r, cur, .none); // *
            cur += 1;
        }
        try renderIdentifier(r, cur, .none, .preserve_when_shadowing); // identifier
        cur += 1;
        if (token_tags[cur] == .comma) {
            try renderToken(r, cur, if (capture_trailing_comma) .newline else .space); // ,
            cur += 1;
        }
        if (token_tags[cur] == .pipe) {
            break;
        }
    }
    if (capture_trailing_comma)
        ais.popIndent();

    try renderThenElse(
        r,
        cur,
        for_node.ast.then_expr,
        for_node.else_token,
        null,
        for_node.ast.else_expr,
        space,
    );
}