add basic runner
This commit is contained in:
parent
eeed063d0d
commit
41a8b18d66
2 changed files with 33 additions and 0 deletions
|
@ -17,6 +17,7 @@
|
|||
|
||||
const std = @import("std");
|
||||
const langs = @import("lang.zig");
|
||||
const runners = @import("runner.zig");
|
||||
|
||||
const c = @cImport({
|
||||
@cInclude("assert.h");
|
||||
|
@ -304,6 +305,7 @@ pub fn main() !void {
|
|||
const allocator = &arena.allocator;
|
||||
|
||||
var lang = langs.Lang.init(allocator);
|
||||
var runner = runners.Runner.init(allocator);
|
||||
//defer lang.deinit();
|
||||
|
||||
var args_it = std.process.args();
|
||||
|
@ -324,6 +326,7 @@ pub fn main() !void {
|
|||
_ = try file.read(data);
|
||||
|
||||
var cmds = try lang.parse(data);
|
||||
try runner.runCommands(cmds);
|
||||
var it = cmds.iterator();
|
||||
while (it.next()) |cmd| {
|
||||
cmd.print();
|
||||
|
|
30
src/runner.zig
Normal file
30
src/runner.zig
Normal file
|
@ -0,0 +1,30 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
};
|
Loading…
Reference in a new issue