31 lines
786 B
Zig
31 lines
786 B
Zig
|
const std = @import("std");
|
||
|
const lang = @import("lang.zig");
|
||
|
|
||
|
pub const RunError = error{UnknownCommand};
|
||
|
|
||
|
pub const Runner = struct {
|
||
|
allocator: *std.mem.Allocator,
|
||
|
|
||
|
pub fn init(allocator: *std.mem.Allocator) Runner {
|
||
|
return Runner{ .allocator = allocator };
|
||
|
}
|
||
|
|
||
|
fn runCommand(self: *Runner, cmd: *lang.Command) !void {
|
||
|
return switch (cmd.command) {
|
||
|
.Noop => {},
|
||
|
else => blk: {
|
||
|
std.debug.warn("Unknown command: {}\n", cmd.command);
|
||
|
break :blk RunError.UnknownCommand;
|
||
|
},
|
||
|
};
|
||
|
}
|
||
|
|
||
|
pub fn runCommands(self: *Runner, cmds: lang.CommandList) !void {
|
||
|
var it = cmds.iterator();
|
||
|
|
||
|
while (it.next()) |cmd| {
|
||
|
try self.runCommand(cmd);
|
||
|
}
|
||
|
}
|
||
|
};
|