feature. See also
. The project being documented here (as the example) is the Zig library itself.
Render.renderFor
fn renderFor(r: *Render, for_node: Ast.full.For, space: Space) Error!void
File
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);
try renderToken(r, label + 1, .space);
}
if (for_node.inline_token) |inline_token| {
try renderToken(r, inline_token, .space);
}
try renderToken(r, for_node.ast.for_token, .space);
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);
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,
);
}