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.
Zig › std/ › zig/ › Parse.zig › forPrefix
forPrefix
Parse.forPrefix
fn forPrefix (p : *Parse ) Error !usize
File
Code
fn forPrefix (p : *Parse ) Error !usize {
const start = p .scratch .items .len ;
_ = try p .expectToken (.l_paren );
while (true ) {
var input = try p .expectExpr ();
if (p .eatToken (.ellipsis2 )) |ellipsis | {
input = try p .addNode (.{
.tag = .for_range ,
.main_token = ellipsis ,
.data = .{ .node_and_opt_node = .{
input ,
.fromOptional (try p .parseExpr ()),
} },
});
}
try p .scratch .append (p .gpa , input );
switch (p .tokenTag (p .tok_i )) {
.comma => p .tok_i += 1 ,
.r_paren => {
p .tok_i += 1 ;
break ;
},
.colon , .r_brace , .r_bracket => return p .failExpected (.r_paren ),
else => try p .warn (.expected_comma_after_for_operand ),
}
if (p .eatToken (.r_paren )) |_ | break ;
}
const inputs = p .scratch .items .len - start ;
_ = p .eatToken (.pipe ) orelse {
try p .warn (.expected_loop_payload );
return inputs ;
};
while (true ) {
_ = p .eatToken (.asterisk );
_ = try p .expectToken (.identifier );
switch (p .tokenTag (p .tok_i )) {
.comma => p .tok_i += 1 ,
.pipe => {
p .tok_i += 1 ;
break ;
},
else => try p .warn (.expected_comma_after_capture ),
}
if (p .eatToken (.pipe )) |_ | break ;
}
return inputs ;
}