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 › forPrefix Private Function forPrefix Doc Source Private Function std.zig.Parse.forPrefix
fn forPrefix (p : *Parse ) Error !usize Params File zig/Parse.zig: 1976
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029 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 ),
// Likely just a missing comma; give error but continue parsing.
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 ;
},
// Likely just a missing comma; give error but continue parsing.
else => try p .warn (.expected_comma_after_capture ),
}
if (p .eatToken (.pipe )) |_ | break ;
}
return inputs ;
}