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 › expectWhileExpr Private Function expectWhileExpr Doc Source Private Function std.zig.Parse.expectWhileExpr
fn expectWhileExpr (p : *Parse ) !Node .Index Params File zig/Parse.zig: 2031
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078 fn expectWhileExpr (p : *Parse ) !Node .Index {
const while_token = p .assertToken (.keyword_while );
_ = try p .expectToken (.l_paren );
const condition = try p .expectExpr ();
_ = try p .expectToken (.r_paren );
_ = try p .parsePtrPayload ();
const cont_expr = try p .parseWhileContinueExpr ();
const then_expr = try p .expectExpr ();
_ = p .eatToken (.keyword_else ) orelse {
if (cont_expr == null ) {
return try p .addNode (.{
.tag = .while_simple ,
.main_token = while_token ,
.data = .{ .node_and_node = .{
condition ,
then_expr ,
} },
});
} else {
return try p .addNode (.{
.tag = .while_cont ,
.main_token = while_token ,
.data = .{ .node_and_extra = .{
condition ,
try p .addExtra (Node .WhileCont {
.cont_expr = cont_expr .?,
.then_expr = then_expr ,
}),
} },
});
}
};
_ = try p .parsePayload ();
const else_expr = try p .expectExpr ();
return try p .addNode (.{
.tag = .@"while" ,
.main_token = while_token ,
.data = .{ .node_and_extra = .{
condition ,
try p .addExtra (Node .While {
.cont_expr = .fromOptional (cont_expr ),
.then_expr = then_expr ,
.else_expr = else_expr ,
}),
} },
});
}