scritcher/src/lang.zig

44 lines
982 B
Zig

const std = @import("std");
pub const CommandType = enum {
Noop,
Load,
Amp,
Quicksave,
};
pub const Command = struct {
command: CommandType,
args: []const u8,
pub fn print(self: *const Command) void {
std.debug.warn("cmd:{} args:{}\n", self.command, self.args);
}
};
pub const CommandList = std.ArrayList(Command);
pub const Lang = struct {
allocator: *std.mem.Allocator,
pub fn init(allocator: *std.mem.Allocator) Lang {
return Lang{ .allocator = allocator };
}
pub fn parse(self: *Lang, data: []const u8) CommandList {
var splitted_it = std.mem.separate(data, ";");
var cmds = CommandList.init(self.allocator);
while (splitted_it.next()) |stmt_orig| {
var stmt = std.mem.trimRight(u8, stmt_orig, "\n");
if (stmt.len == 0) continue;
// TODO parse stmt
std.debug.warn("full cmd: '{}'\n", stmt);
}
return cmds;
}
};