renderFor
Function parameters
Parameters
Type definitions in this namespace
Types
Functions in this namespace
Functions
Error sets in this namespace
Error Sets
Source
Implementation
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.indexOfScalarPos(std.zig.Token.Tag, token_tags, cur, .pipe).?;
if (tree.tokenTag(@intCast(pipe - 1)) == .comma) {
try ais.pushIndent(.normal);
try renderToken(r, cur - 1, .newline); // |
while (true) {
if (tree.tokenTag(cur) == .asterisk) {
try renderToken(r, cur, .none); // *
cur += 1;
}
try renderIdentifier(r, cur, .none, .preserve_when_shadowing); // identifier
cur += 1;
if (tree.tokenTag(cur) == .comma) {
try renderToken(r, cur, .newline); // ,
cur += 1;
}
if (tree.tokenTag(cur) == .pipe) {
break;
}
}
ais.popIndent();
} else {
try renderToken(r, cur - 1, .none); // |
while (true) {
if (tree.tokenTag(cur) == .asterisk) {
try renderToken(r, cur, .none); // *
cur += 1;
}
try renderIdentifier(r, cur, .none, .preserve_when_shadowing); // identifier
cur += 1;
if (tree.tokenTag(cur) == .comma) {
try renderToken(r, cur, .space); // ,
cur += 1;
}
if (tree.tokenTag(cur) == .pipe) {
break;
}
}
}
try renderThenElse(
r,
cur,
for_node.ast.then_expr,
for_node.else_token,
null,
for_node.ast.else_expr,
space,
);
}