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 › parseSwitchProng Private Function parseSwitchProng Doc Source Private Function std.zig.Parse.parseSwitchProng
fn parseSwitchProng (p : *Parse ) !?Node .Index Params File zig/Parse.zig: 2760
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800 fn parseSwitchProng (p : *Parse ) !?Node .Index {
const scratch_top = p .scratch .items .len ;
defer p .scratch .shrinkRetainingCapacity (scratch_top );
const is_inline = p .eatToken (.keyword_inline ) != null ;
if (p .eatToken (.keyword_else ) == null ) {
while (true ) {
const item = try p .parseSwitchItem () orelse break ;
try p .scratch .append (p .gpa , item );
if (p .eatToken (.comma ) == null ) break ;
}
if (scratch_top == p .scratch .items .len ) {
if (is_inline ) p .tok_i -= 1 ;
return null ;
}
}
const arrow_token = try p .expectToken (.equal_angle_bracket_right );
_ = try p .parsePtrIndexPayload ();
const items = p .scratch .items [scratch_top ..];
if (items .len <= 1 ) {
return try p .addNode (.{
.tag = if (is_inline ) .switch_case_inline_one else .switch_case_one ,
.main_token = arrow_token ,
.data = .{ .opt_node_and_node = .{
if (items .len >= 1 ) items [0 ].toOptional () else .none ,
try p .expectSingleAssignExpr (),
} },
});
} else {
return try p .addNode (.{
.tag = if (is_inline ) .switch_case_inline else .switch_case ,
.main_token = arrow_token ,
.data = .{ .extra_and_node = .{
try p .addExtra (try p .listToSpan (items )),
try p .expectSingleAssignExpr (),
} },
});
}
}