tiny.zen.QuizPlan
Defined in tiny.zen.
API (6)
Actions
Public operations.
Fields and members
Public fields and members.
Source
Source: lib/zen/src/quiz/plan.zig:17
zig
pub const Plan = struct { input_bytes: usize, questions: usize, options: usize, joined_text_bytes: usize, pub fn inspect(source: []const u8, limits: Limits) model.Error!Plan { var state: State = .{}; var iterator = scan.Iterator.init(source); while (iterator.next()) |token| switch (token) { .prompt => |text| { if (state.current.started()) try state.current.finish(); state.questions = try added(state.questions, 1); if (state.questions > limits.max_questions) { return error.QuestionCapacityExceeded; } state.current = .{ .element = .prompt, .element_bytes = text.len, }; }, .option => |option| { if (!state.current.started() or state.current.element == .explanation) { return error.InvalidQuizDirective; } state.options = try added(state.options, 1); if (state.options > limits.max_options) return error.OptionCapacityExceeded; state.current.options = try added(state.current.options, 1); if (option.correct) { state.current.correct = try added(state.current.correct, 1); } state.current.element = .option; state.current.element_bytes = option.text.len; state.current.element_joined = false; }, .explanation => |text| { if (!state.current.started()) return error.InvalidQuizDirective; if (state.current.element == .explanation) { try state.join(text, limits.max_joined_text_bytes); } else { state.current.element = .explanation; state.current.element_bytes = text.len; state.current.element_joined = false; state.current.explanation_bytes = text.len; } }, .continuation => |text| { if (!state.current.started()) return error.InvalidQuizDirective; try state.join(text, limits.max_joined_text_bytes); }, }; if (state.current.started()) try state.current.finish(); if (state.questions == 0) return error.InvalidQuizDirective; std.debug.assert(state.questions <= limits.max_questions); std.debug.assert(state.options <= limits.max_options); std.debug.assert(state.joined_text_bytes <= limits.max_joined_text_bytes); return .{ .input_bytes = source.len, .questions = state.questions, .options = state.options, .joined_text_bytes = state.joined_text_bytes, }; } pub fn exactLimits(self: Plan) Limits { return .{ .max_questions = self.questions, .max_options = self.options, .max_joined_text_bytes = self.joined_text_bytes, }; }};Source: lib/zen/src/root.zig:150
zig
/// Exact quiz storage demand measured before allocation.pub const QuizPlan = quiz.Plan;Also reachable as
Audit
| Definitions | 3 |
|---|---|
| Public names | 6 |
| Members | 4 |
| Version | 26.7.0 |
| Revision | daab053ee433 |