From cf347f91ee838759dc44ed34ec6ff320186e90ce Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 17 Nov 2026 01:44:36 -0300 Subject: One verb table: the flags, the console's, the script's and ctl's words are rows Six hand-kept lists said one vocabulary: root.zig's parser, its usage and its header; the console's completion list, its help strings and the execute chain; Host.zig's list of lines that do not move State; the script's header comment and its step chain; control.zig's names and its magic node numbers. Now each is a table, and the parser, the help, the completion and the dispatch read it. - root.zig: `Flag`, an enum, and `flags`, a row each (arg, doc): the loop looks the word up, takes its argument when the row names one, and a switch sets what it means; `usage` is made from the rows at compile time (the same text, and a line for --help). Errors say the flag and what it needs. - Console.zig: `Verb` and `verbs`, a row each (args, doc, moves_state): execute is a switch on the verb, a line whose first word is none goes to the sketch as before; Tab completes from the rows (a verb, and with each lowercase word its first argument may be: `seek start`); `help` prints the rows wrapped to the log's width, `help VERB` its line. - Host.zig: movesState asks the row; a sketch's command moves State. - script.zig: `Verb` and `verbs` (args, doc, frame, input): step is a switch, a row with `frame` is followed by one; the input verbs are `input`, which a 9P ctl will call live. - control.zig: `File` and `files` (mode, doc), a node being its number (the same numbers); `Verb` and `verbs` for ctl's own two words. Behaviour is unchanged but for help's text, completion's list (the same words, and `timing`, `play`, `seek`... alone) and errors' words. The diff adds more than it deletes (+630 -521): the rows carry a line of doc for every verb, which nothing had before. Tests: test-control, test-timing, test-setup, test-same, test-kill, test-past, test-import, test-paths: 70/70 steps, 29/29 tests. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- src/host/Host.zig | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/host/Host.zig') diff --git a/src/host/Host.zig b/src/host/Host.zig index 002c704..93c47c1 100644 --- a/src/host/Host.zig +++ b/src/host/Host.zig @@ -727,13 +727,12 @@ pub fn runLine(self: *Host, line: []const u8, now: u64) !void { } /// Whether a console line that succeeded may have changed State other than -/// through `update` (restoring a snapshot is caught apart from this). +/// through `update` (restoring a snapshot is caught apart from this): a +/// sketch's command may. fn movesState(line: []const u8) bool { var words = std.mem.tokenizeAny(u8, line, " \t"); - const verb = words.next() orelse return false; - const still = [_][]const u8{ "help", "overlay", "timing", "get", "snapshot", "recording", "diff", "stop", "pause", "save", "quit", "exit", "sessions", "marks", "clips", "export-session", "import" }; - for (still) |w| if (std.mem.eql(u8, verb, w)) return false; - return true; + const verb = std.meta.stringToEnum(Console.Verb, words.next() orelse return false) orelse return true; + return Console.verbs.get(verb).moves_state; } /// Offers a line to the sketch. -- cgit v1.3