tiny.zen.parseQuiz
Defined in tiny.zen.
Source
Source: lib/zen/src/quiz/parse.zig:6
zig
pub fn parse(storage: *storage_mod.Storage, source: []const u8) model.Error!model.Quiz { var regions = try storage.acquire(source); var iterator = scan.Iterator.init(source); var question_index: usize = 0; var option_index: usize = 0; var byte_index: usize = 0; var current: ?Current = null; while (iterator.next()) |token| switch (token) { .prompt => |text| { if (current) |active| active.finish(®ions, option_index); std.debug.assert(question_index < regions.questions.len); regions.questions[question_index] = .{ .prompt = text, .options = &.{}, .explanation = "", }; current = .{ .question = question_index, .option_start = option_index, .active = .{ .prompt = question_index }, }; question_index += 1; }, .option => |option| { std.debug.assert(current != null); var active = ¤t.?; std.debug.assert(option_index < regions.options.len); regions.options[option_index] = .{ .text = option.text, .correct = option.correct, }; active.active = .{ .option = option_index }; active.joined_start = null; option_index += 1; }, .explanation => |text| { std.debug.assert(current != null); var active = ¤t.?; switch (active.active) { .explanation => active.join(®ions, &byte_index, text), else => { regions.questions[active.question].explanation = text; active.active = .{ .explanation = active.question }; active.joined_start = null; }, } }, .continuation => |text| { std.debug.assert(current != null); var active = ¤t.?; active.join(®ions, &byte_index, text); }, }; std.debug.assert(current != null); current.?.finish(®ions, option_index); std.debug.assert(question_index == regions.questions.len); std.debug.assert(option_index == regions.options.len); std.debug.assert(byte_index == regions.joined_text.len); return .{ .questions = regions.questions };}Source: lib/zen/src/root.zig:166
zig
/// Parses into active storage; the quiz borrows it until `reset`.pub const parseQuiz = quiz.parse;Also reachable as
Audit
| Definitions | 1 |
|---|---|
| Public names | 2 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |