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 › expectFor
expectFor
Parse.expectFor
fn expectFor (p : *Parse , comptime bodyParseFn : fn (p : *Parse ) Error !Node .Index ) !Node .Index
File
Code
fn expectFor (p : *Parse , comptime bodyParseFn : fn (p : *Parse ) Error !Node .Index ) !Node .Index {
const for_token = p .assertToken (.keyword_for );
const scratch_top = p .scratch .items .len ;
defer p .scratch .shrinkRetainingCapacity (scratch_top );
const inputs = try p .forPrefix ();
const then_expr = try bodyParseFn (p );
var has_else = false ;
if (p .eatToken (.keyword_else )) |_ | {
try p .scratch .append (p .gpa , then_expr );
const else_expr = try bodyParseFn (p );
try p .scratch .append (p .gpa , else_expr );
has_else = true ;
} else if (inputs == 1 ) {
return try p .addNode (.{
.tag = .for_simple ,
.main_token = for_token ,
.data = .{ .node_and_node = .{
p .scratch .items [scratch_top ],
then_expr ,
} },
});
} else {
try p .scratch .append (p .gpa , then_expr );
}
return try p .addNode (.{
.tag = .@"for" ,
.main_token = for_token ,
.data = .{ .@"for" = .{
(try p .listToSpan (p .scratch .items [scratch_top ..])).start ,
.{ .inputs = @intCast (inputs ), .has_else = has_else },
} },
});
}