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 standard library.
std › zig › Parse › expectBuiltinCall Private Function expectBuiltinCall Doc Source Private Function std.zig.Parse.expectBuiltinCall
fn expectBuiltinCall (p : *Parse ) !Node .Index Params File zig/Parse.zig: 3223
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269 fn expectBuiltinCall (p : *Parse ) !Node .Index {
const builtin_token = p .assertToken (.builtin );
_ = p .eatToken (.l_paren ) orelse {
try p .warn (.expected_param_list );
// Pretend this was an identifier so we can continue parsing.
return p .addNode (.{
.tag = .identifier ,
.main_token = builtin_token ,
.data = undefined ,
});
};
const scratch_top = p .scratch .items .len ;
defer p .scratch .shrinkRetainingCapacity (scratch_top );
while (true ) {
if (p .eatToken (.r_paren )) |_ | break ;
const param = try p .expectExpr ();
try p .scratch .append (p .gpa , param );
switch (p .tokenTag (p .tok_i )) {
.comma => p .tok_i += 1 ,
.r_paren => {
p .tok_i += 1 ;
break ;
},
// Likely just a missing comma; give error but continue parsing.
else => try p .warn (.expected_comma_after_arg ),
}
}
const comma = (p .tokenTag (p .tok_i - 2 )) == .comma ;
const params = p .scratch .items [scratch_top ..];
if (params .len <= 2 ) {
return p .addNode (.{
.tag = if (comma ) .builtin_call_two_comma else .builtin_call_two ,
.main_token = builtin_token ,
.data = .{ .opt_node_and_opt_node = .{
if (params .len >= 1 ) .fromOptional (params [0 ]) else .none ,
if (params .len >= 2 ) .fromOptional (params [1 ]) else .none ,
} },
});
} else {
const span = try p .listToSpan (params );
return p .addNode (.{
.tag = if (comma ) .builtin_call_comma else .builtin_call ,
.main_token = builtin_token ,
.data = .{ .extra_range = span },
});
}
}