2019-07-08 02:03:55 +00:00
|
|
|
const std = @import("std");
|
|
|
|
|
2019-07-10 19:06:44 +00:00
|
|
|
const plugin = @import("plugin.zig");
|
|
|
|
|
2019-07-08 03:23:12 +00:00
|
|
|
pub const ParseError = error{
|
2019-09-09 02:28:09 +00:00
|
|
|
OutOfMemory,
|
2019-07-09 03:04:01 +00:00
|
|
|
ArgRequired,
|
2019-08-08 23:27:24 +00:00
|
|
|
ParseFail,
|
2019-07-08 03:23:12 +00:00
|
|
|
};
|
|
|
|
|
2019-07-08 02:03:55 +00:00
|
|
|
pub const CommandType = enum {
|
|
|
|
Noop,
|
|
|
|
Load,
|
2019-07-10 19:06:44 +00:00
|
|
|
Quicksave,
|
2019-07-11 00:43:23 +00:00
|
|
|
RunQS,
|
2019-07-10 19:06:44 +00:00
|
|
|
|
2019-07-08 02:03:55 +00:00
|
|
|
Amp,
|
2019-07-10 16:24:03 +00:00
|
|
|
RFlanger,
|
2019-07-10 19:06:44 +00:00
|
|
|
Eq,
|
2019-07-10 19:24:43 +00:00
|
|
|
Phaser,
|
2019-07-10 19:43:30 +00:00
|
|
|
Mbeq,
|
2019-07-10 19:59:15 +00:00
|
|
|
Chorus,
|
2019-07-10 20:31:18 +00:00
|
|
|
PitchScaler,
|
2019-07-10 23:19:40 +00:00
|
|
|
Reverb,
|
2019-07-10 23:41:17 +00:00
|
|
|
Highpass,
|
2019-07-11 13:20:09 +00:00
|
|
|
Delay,
|
2019-07-13 19:46:26 +00:00
|
|
|
Vinyl,
|
2019-07-13 20:20:14 +00:00
|
|
|
RevDelay,
|
2020-01-25 20:47:20 +00:00
|
|
|
Gate,
|
2020-01-25 21:52:45 +00:00
|
|
|
Detune,
|
|
|
|
Overdrive,
|
|
|
|
Degrade,
|
|
|
|
RePsycho,
|
|
|
|
TalkBox,
|
2019-07-29 14:51:40 +00:00
|
|
|
|
2019-07-13 20:42:46 +00:00
|
|
|
Noise,
|
2019-07-13 22:55:57 +00:00
|
|
|
WildNoise,
|
2019-07-29 14:51:40 +00:00
|
|
|
Write,
|
2019-10-22 20:08:19 +00:00
|
|
|
Embed,
|
2019-07-22 20:04:43 +00:00
|
|
|
|
|
|
|
Rotate,
|
2019-07-08 02:03:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
pub const Command = struct {
|
|
|
|
command: CommandType,
|
2019-07-08 03:09:34 +00:00
|
|
|
args: ArgList,
|
2019-07-10 23:46:22 +00:00
|
|
|
cur_idx: usize = 0,
|
2019-07-08 02:03:55 +00:00
|
|
|
|
2019-09-03 15:45:17 +00:00
|
|
|
pub fn print(self: Command) void {
|
2020-01-15 01:31:20 +00:00
|
|
|
std.debug.warn("cmd:{}\n", .{self.command});
|
2019-07-08 02:03:55 +00:00
|
|
|
}
|
2019-07-09 01:40:52 +00:00
|
|
|
|
2019-09-03 15:45:17 +00:00
|
|
|
pub fn argAt(self: Command, idx: usize) ![]const u8 {
|
2020-01-15 01:31:20 +00:00
|
|
|
std.debug.warn("{} {}", .{ idx, self.args.len });
|
2019-07-09 03:04:01 +00:00
|
|
|
|
2019-12-02 23:13:19 +00:00
|
|
|
if (idx > (self.args.len - 1)) {
|
2020-01-15 01:31:20 +00:00
|
|
|
std.debug.warn("Expected argument at index {}\n", .{idx});
|
2019-07-09 03:04:01 +00:00
|
|
|
return ParseError.ArgRequired;
|
|
|
|
}
|
|
|
|
|
2019-12-02 23:13:19 +00:00
|
|
|
const args = self.args.toSliceConst();
|
2019-07-09 03:04:01 +00:00
|
|
|
return args[idx];
|
|
|
|
}
|
|
|
|
|
2019-09-03 15:45:17 +00:00
|
|
|
pub fn usizeArgAt(self: Command, idx: usize) !usize {
|
2019-07-09 03:04:01 +00:00
|
|
|
var arg = try self.argAt(idx);
|
|
|
|
return try std.fmt.parseInt(usize, arg, 10);
|
|
|
|
}
|
|
|
|
|
2019-07-10 23:46:22 +00:00
|
|
|
pub fn consumePosition(self: *Command) !plugin.Position {
|
|
|
|
self.cur_idx = 2;
|
2019-07-10 19:06:44 +00:00
|
|
|
return plugin.Position{
|
|
|
|
.split = try self.usizeArgAt(0),
|
|
|
|
.index = try self.usizeArgAt(1),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-09-03 15:45:17 +00:00
|
|
|
pub fn intArgAt(self: Command, idx: usize) !i32 {
|
2019-07-09 03:04:01 +00:00
|
|
|
var arg = try self.argAt(idx);
|
2019-07-09 01:40:52 +00:00
|
|
|
return try std.fmt.parseInt(i32, arg, 10);
|
|
|
|
}
|
|
|
|
|
2019-09-03 15:45:17 +00:00
|
|
|
pub fn floatArgAt(self: Command, idx: usize) !f32 {
|
2019-07-09 03:04:01 +00:00
|
|
|
var arg = try self.argAt(idx);
|
2019-07-09 01:40:52 +00:00
|
|
|
return try std.fmt.parseFloat(f32, arg);
|
|
|
|
}
|
2019-07-10 19:43:30 +00:00
|
|
|
|
|
|
|
pub fn floatArgMany(
|
2019-09-03 15:45:17 +00:00
|
|
|
self: Command,
|
2019-07-10 19:43:30 +00:00
|
|
|
allocator: *std.mem.Allocator,
|
|
|
|
start_index: usize,
|
|
|
|
elements: usize,
|
|
|
|
default: f32,
|
|
|
|
) ![]const f32 {
|
|
|
|
var i: usize = start_index;
|
|
|
|
var arr = std.ArrayList(f32).init(allocator);
|
|
|
|
|
|
|
|
while (i < elements) : (i += 1) {
|
|
|
|
var value: f32 = self.floatArgAt(i) catch |err| blk: {
|
2020-01-15 01:31:20 +00:00
|
|
|
std.debug.warn("\tdoing default on arg {}\n", .{i});
|
2019-07-10 19:43:30 +00:00
|
|
|
break :blk default;
|
|
|
|
};
|
|
|
|
|
|
|
|
try arr.append(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return arr.toSliceConst();
|
|
|
|
}
|
2019-07-10 19:59:15 +00:00
|
|
|
|
|
|
|
pub fn appendParam(
|
2019-07-10 23:46:22 +00:00
|
|
|
self: *Command,
|
2019-07-10 19:59:15 +00:00
|
|
|
params: *plugin.ParamList,
|
|
|
|
symbol: []const u8,
|
|
|
|
) !void {
|
2019-07-10 23:46:22 +00:00
|
|
|
var val = try self.floatArgAt(self.cur_idx);
|
|
|
|
self.cur_idx += 1;
|
|
|
|
|
2019-07-10 19:59:15 +00:00
|
|
|
try params.append(plugin.Param{
|
|
|
|
.sym = symbol,
|
|
|
|
.value = val,
|
|
|
|
});
|
|
|
|
}
|
2019-07-13 21:17:44 +00:00
|
|
|
|
|
|
|
pub fn appendParamMap(
|
|
|
|
self: *Command,
|
|
|
|
map: *plugin.ParamMap,
|
|
|
|
symbol: []const u8,
|
|
|
|
) !void {
|
|
|
|
var val = try self.floatArgAt(self.cur_idx);
|
|
|
|
self.cur_idx += 1;
|
|
|
|
_ = try map.put(symbol, val);
|
|
|
|
}
|
2019-07-08 03:09:34 +00:00
|
|
|
|
2019-09-03 15:45:17 +00:00
|
|
|
pub fn copy(self: Command, allocator: *std.mem.Allocator) !*Command {
|
|
|
|
var cmd = try allocator.create(Command);
|
|
|
|
cmd.* = Command{
|
|
|
|
.command = self.command,
|
|
|
|
.args = self.args,
|
|
|
|
.cur_idx = self.cur_idx,
|
|
|
|
};
|
2019-08-09 21:40:11 +00:00
|
|
|
|
2019-09-03 15:45:17 +00:00
|
|
|
return cmd;
|
2019-08-09 21:40:11 +00:00
|
|
|
}
|
2019-09-03 15:45:17 +00:00
|
|
|
};
|
2019-08-09 21:40:11 +00:00
|
|
|
|
2019-09-03 15:45:17 +00:00
|
|
|
pub const CommandList = std.ArrayList(Command);
|
|
|
|
pub const ArgList = std.ArrayList([]const u8);
|
2019-08-09 21:40:11 +00:00
|
|
|
|
2019-09-03 15:45:17 +00:00
|
|
|
pub const KeywordMap = std.StringHashMap(CommandType);
|
2019-07-08 02:03:55 +00:00
|
|
|
|
2019-10-06 18:07:30 +00:00
|
|
|
/// A parser.
|
2019-07-08 02:03:55 +00:00
|
|
|
pub const Lang = struct {
|
|
|
|
allocator: *std.mem.Allocator,
|
2019-07-10 17:44:22 +00:00
|
|
|
keywords: KeywordMap,
|
2019-07-08 02:03:55 +00:00
|
|
|
|
2019-08-09 14:28:40 +00:00
|
|
|
has_error: bool = false,
|
|
|
|
line: usize = 0,
|
|
|
|
|
2019-07-08 02:03:55 +00:00
|
|
|
pub fn init(allocator: *std.mem.Allocator) Lang {
|
2019-07-10 17:44:22 +00:00
|
|
|
return Lang{
|
|
|
|
.allocator = allocator,
|
|
|
|
.keywords = KeywordMap.init(allocator),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-08-08 00:04:51 +00:00
|
|
|
pub fn deinit(self: *Lang) void {
|
|
|
|
self.keywords.deinit();
|
|
|
|
}
|
|
|
|
|
2019-09-10 15:12:10 +00:00
|
|
|
pub fn reset(self: *Lang) void {
|
|
|
|
self.has_error = false;
|
|
|
|
self.line = 0;
|
|
|
|
}
|
|
|
|
|
2019-07-10 17:44:22 +00:00
|
|
|
fn fillKeywords(self: *Lang) !void {
|
|
|
|
_ = try self.keywords.put("noop", .Noop);
|
|
|
|
_ = try self.keywords.put("load", .Load);
|
|
|
|
_ = try self.keywords.put("quicksave", .Quicksave);
|
2019-07-11 00:43:23 +00:00
|
|
|
_ = try self.keywords.put("runqs", .RunQS);
|
2019-07-10 17:44:22 +00:00
|
|
|
|
|
|
|
_ = try self.keywords.put("amp", .Amp);
|
|
|
|
_ = try self.keywords.put("rflanger", .RFlanger);
|
2019-07-10 19:06:44 +00:00
|
|
|
_ = try self.keywords.put("eq", .Eq);
|
2019-07-10 19:43:30 +00:00
|
|
|
_ = try self.keywords.put("mbeq", .Mbeq);
|
2019-07-10 19:24:43 +00:00
|
|
|
_ = try self.keywords.put("phaser", .Phaser);
|
2019-07-10 19:59:15 +00:00
|
|
|
_ = try self.keywords.put("chorus", .Chorus);
|
2019-07-10 20:31:18 +00:00
|
|
|
_ = try self.keywords.put("pitchscaler", .PitchScaler);
|
2019-07-10 23:19:40 +00:00
|
|
|
_ = try self.keywords.put("reverb", .Reverb);
|
2019-07-10 23:41:17 +00:00
|
|
|
_ = try self.keywords.put("highpass", .Highpass);
|
2019-07-11 13:20:09 +00:00
|
|
|
_ = try self.keywords.put("delay", .Delay);
|
2019-07-13 19:46:26 +00:00
|
|
|
_ = try self.keywords.put("vinyl", .Vinyl);
|
2019-07-13 20:20:14 +00:00
|
|
|
_ = try self.keywords.put("revdelay", .RevDelay);
|
2020-01-25 20:47:20 +00:00
|
|
|
_ = try self.keywords.put("gate", .Gate);
|
2020-01-25 21:52:45 +00:00
|
|
|
_ = try self.keywords.put("detune", .Detune);
|
|
|
|
_ = try self.keywords.put("overdrive", .Overdrive);
|
|
|
|
_ = try self.keywords.put("talkbox", .TalkBox);
|
2019-07-13 20:42:46 +00:00
|
|
|
|
|
|
|
// custom implementations (not lv2)
|
|
|
|
_ = try self.keywords.put("noise", .Noise);
|
2019-07-13 22:55:57 +00:00
|
|
|
_ = try self.keywords.put("wildnoise", .WildNoise);
|
2019-07-29 14:51:40 +00:00
|
|
|
_ = try self.keywords.put("write", .Write);
|
2019-10-22 20:08:19 +00:00
|
|
|
_ = try self.keywords.put("embed", .Embed);
|
2020-01-25 21:52:45 +00:00
|
|
|
_ = try self.keywords.put("degrade", .Degrade);
|
|
|
|
_ = try self.keywords.put("repsycho", .RePsycho);
|
2019-07-22 20:04:43 +00:00
|
|
|
|
|
|
|
// even more custom
|
|
|
|
_ = try self.keywords.put("rotate", .Rotate);
|
2019-07-08 02:03:55 +00:00
|
|
|
}
|
|
|
|
|
2019-08-07 02:34:11 +00:00
|
|
|
pub fn getCommand(self: *Lang, stmt: []const u8) ?CommandType {
|
2019-08-09 21:40:11 +00:00
|
|
|
var kv_opt = self.keywords.get(stmt);
|
|
|
|
|
|
|
|
if (kv_opt) |kv| {
|
|
|
|
return kv.value;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE this is fallback since std.AutoHashMap does not follow
|
|
|
|
// pointers anymore (in master).
|
|
|
|
fn oldGetCommand(self: *Lang, stmt: []const u8) ?CommandType {
|
2019-08-07 02:34:11 +00:00
|
|
|
const commands = [_][]const u8{
|
|
|
|
"noop",
|
|
|
|
"load",
|
|
|
|
"quicksave",
|
|
|
|
"runqs",
|
|
|
|
"amp",
|
|
|
|
"rflanger",
|
|
|
|
"eq",
|
|
|
|
"phaser",
|
|
|
|
"mbeq",
|
|
|
|
"chorus",
|
|
|
|
"pitchscaler",
|
|
|
|
"reverb",
|
|
|
|
"highpass",
|
|
|
|
"delay",
|
|
|
|
"vinyl",
|
|
|
|
"revdelay",
|
|
|
|
"noise",
|
|
|
|
"wildnoise",
|
|
|
|
"write",
|
2019-10-22 21:16:15 +00:00
|
|
|
"embed",
|
2019-08-07 02:34:11 +00:00
|
|
|
"rotate",
|
|
|
|
};
|
|
|
|
|
|
|
|
const command_types = [_]CommandType{
|
|
|
|
.Noop,
|
|
|
|
.Load,
|
|
|
|
.Quicksave,
|
|
|
|
.RunQS,
|
|
|
|
|
|
|
|
.Amp,
|
|
|
|
.RFlanger,
|
|
|
|
.Eq,
|
|
|
|
.Phaser,
|
|
|
|
.Mbeq,
|
|
|
|
.Chorus,
|
|
|
|
.PitchScaler,
|
|
|
|
.Reverb,
|
|
|
|
.Highpass,
|
|
|
|
.Delay,
|
|
|
|
.Vinyl,
|
|
|
|
.RevDelay,
|
|
|
|
|
|
|
|
.Noise,
|
|
|
|
.WildNoise,
|
|
|
|
.Write,
|
2019-10-22 21:16:15 +00:00
|
|
|
.Embed,
|
2019-08-07 02:34:11 +00:00
|
|
|
|
|
|
|
.Rotate,
|
|
|
|
};
|
|
|
|
|
|
|
|
std.debug.assert(commands.len == command_types.len);
|
|
|
|
|
|
|
|
for (commands) |command, idx| {
|
|
|
|
if (std.mem.eql(u8, stmt, command)) return command_types[idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-08-08 23:24:25 +00:00
|
|
|
fn expectAny(self: *Lang, count: usize, args: ArgList) !void {
|
|
|
|
if (args.len != count) {
|
2020-01-15 01:31:20 +00:00
|
|
|
self.doError("expected {} arguments, found {}", .{ count, args.len });
|
2019-08-08 23:13:49 +00:00
|
|
|
return error.ArgRequired;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-08 23:24:25 +00:00
|
|
|
fn expectSingle(self: *Lang, args: ArgList) !void {
|
|
|
|
return try self.expectAny(1, args);
|
|
|
|
}
|
|
|
|
|
2019-08-08 23:13:49 +00:00
|
|
|
fn expectFloat(self: *Lang, count: usize, args: ArgList) !void {
|
|
|
|
var i: usize = 0;
|
|
|
|
|
|
|
|
if (args.len != count) {
|
2020-01-15 01:31:20 +00:00
|
|
|
self.doError("expected {} arguments, found {}", .{ count, args.len });
|
2019-08-08 23:13:49 +00:00
|
|
|
return error.ArgRequired;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (i < count) : (i += 1) {
|
|
|
|
var arg = args.at(i);
|
|
|
|
|
|
|
|
_ = std.fmt.parseFloat(f32, arg) catch |err| {
|
2020-01-15 01:31:20 +00:00
|
|
|
std.debug.warn("failed to parse f32: {}\n", .{err});
|
2019-08-08 23:13:49 +00:00
|
|
|
return error.FloatParseFail;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-03 15:45:17 +00:00
|
|
|
fn validateCommand(self: *Lang, cmd: Command) !void {
|
2019-08-08 23:13:49 +00:00
|
|
|
switch (cmd.command) {
|
|
|
|
.Quicksave, .Noop => {},
|
|
|
|
.Load, .RunQS => try self.expectSingle(cmd.args),
|
|
|
|
.Amp => try self.expectFloat(3, cmd.args),
|
2019-08-08 23:24:25 +00:00
|
|
|
.RFlanger => try self.expectFloat(4, cmd.args),
|
|
|
|
.Eq => try self.expectFloat(5, cmd.args),
|
|
|
|
.Phaser => try self.expectFloat(6, cmd.args),
|
2019-08-12 16:07:06 +00:00
|
|
|
.Mbeq => try self.expectFloat(17, cmd.args),
|
2019-08-08 23:24:25 +00:00
|
|
|
.Chorus => try self.expectFloat(8, cmd.args),
|
|
|
|
.PitchScaler => try self.expectFloat(3, cmd.args),
|
|
|
|
.Reverb => try self.expectFloat(12, cmd.args),
|
|
|
|
.Highpass => try self.expectFloat(5, cmd.args),
|
|
|
|
.Delay => try self.expectFloat(12, cmd.args),
|
|
|
|
.Vinyl => try self.expectFloat(7, cmd.args),
|
2019-08-27 17:17:15 +00:00
|
|
|
.RevDelay => try self.expectFloat(7, cmd.args),
|
2019-08-08 23:24:25 +00:00
|
|
|
.Noise => try self.expectFloat(4, cmd.args),
|
|
|
|
.WildNoise => try self.expectFloat(4, cmd.args),
|
|
|
|
.Write => try self.expectFloat(3, cmd.args),
|
|
|
|
.Rotate => try self.expectAny(2, cmd.args),
|
2019-10-22 21:16:15 +00:00
|
|
|
.Embed => try self.expectAny(3, cmd.args),
|
2020-01-15 01:31:20 +00:00
|
|
|
else => std.debug.warn("WARN unchecked command {}\n", .{cmd.command}),
|
2019-08-08 23:13:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-15 01:31:20 +00:00
|
|
|
fn doError(self: *Lang, comptime fmt: []const u8, args: var) void {
|
|
|
|
std.debug.warn("error at line {}: ", .{self.line});
|
2019-08-09 14:28:40 +00:00
|
|
|
std.debug.warn(fmt, args);
|
2020-01-15 01:31:20 +00:00
|
|
|
std.debug.warn("\n", .{});
|
2019-08-09 14:28:40 +00:00
|
|
|
self.has_error = true;
|
|
|
|
}
|
|
|
|
|
2019-09-09 02:28:09 +00:00
|
|
|
pub fn parse(self: *Lang, data: []const u8) ParseError!CommandList {
|
2019-07-08 02:03:55 +00:00
|
|
|
var splitted_it = std.mem.separate(data, ";");
|
2019-07-10 17:44:22 +00:00
|
|
|
try self.fillKeywords();
|
2019-07-08 02:03:55 +00:00
|
|
|
var cmds = CommandList.init(self.allocator);
|
|
|
|
|
|
|
|
while (splitted_it.next()) |stmt_orig| {
|
2019-08-09 14:28:40 +00:00
|
|
|
self.line += 1;
|
2019-07-08 02:03:55 +00:00
|
|
|
var stmt = std.mem.trimRight(u8, stmt_orig, "\n");
|
2019-07-08 16:55:54 +00:00
|
|
|
stmt = std.mem.trimLeft(u8, stmt, "\n");
|
2019-07-08 02:03:55 +00:00
|
|
|
|
|
|
|
if (stmt.len == 0) continue;
|
2019-08-13 13:19:39 +00:00
|
|
|
if (std.mem.startsWith(u8, stmt, "#")) continue;
|
2019-07-08 02:03:55 +00:00
|
|
|
|
2019-07-08 03:09:34 +00:00
|
|
|
// TODO better tokenizer instead of just tokenize(" ");
|
|
|
|
var tok_it = std.mem.tokenize(stmt, " ");
|
|
|
|
|
2019-07-08 03:23:12 +00:00
|
|
|
var cmd_opt = tok_it.next();
|
2019-08-09 14:28:40 +00:00
|
|
|
if (cmd_opt == null) {
|
2020-01-15 01:31:20 +00:00
|
|
|
self.doError("No command given", .{});
|
2019-08-09 14:28:40 +00:00
|
|
|
continue;
|
|
|
|
}
|
2019-07-08 03:23:12 +00:00
|
|
|
var command = cmd_opt.?;
|
2019-07-10 17:44:22 +00:00
|
|
|
|
2019-08-07 02:34:11 +00:00
|
|
|
var ctype_opt = self.getCommand(command);
|
2019-07-10 17:44:22 +00:00
|
|
|
var ctype: CommandType = undefined;
|
2019-08-07 02:34:11 +00:00
|
|
|
if (ctype_opt) |ctype_val| {
|
|
|
|
ctype = ctype_val;
|
2019-07-10 17:44:22 +00:00
|
|
|
} else {
|
2020-01-15 01:31:20 +00:00
|
|
|
self.doError("Unknown command '{}' ({})", .{ command, command.len });
|
2019-08-09 14:28:40 +00:00
|
|
|
continue;
|
2019-07-10 17:44:22 +00:00
|
|
|
}
|
|
|
|
|
2019-07-08 03:09:34 +00:00
|
|
|
var args = ArgList.init(self.allocator);
|
2019-12-02 23:13:19 +00:00
|
|
|
errdefer args.deinit();
|
|
|
|
|
2019-07-08 03:09:34 +00:00
|
|
|
while (tok_it.next()) |arg| {
|
|
|
|
try args.append(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
// construct final Command based on command
|
2019-09-03 15:45:17 +00:00
|
|
|
var cmd = Command{ .command = ctype, .args = args };
|
|
|
|
self.validateCommand(cmd) catch |err| {
|
2019-09-09 02:28:09 +00:00
|
|
|
//self.doError("error validating command '{}': {}", command, err);
|
2019-08-09 14:28:40 +00:00
|
|
|
continue;
|
2019-08-08 23:27:24 +00:00
|
|
|
};
|
2019-08-08 23:13:49 +00:00
|
|
|
|
2019-09-03 15:45:17 +00:00
|
|
|
try cmds.append(cmd);
|
2019-07-08 02:03:55 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 14:28:40 +00:00
|
|
|
if (self.has_error) return ParseError.ParseFail;
|
2019-08-08 23:30:24 +00:00
|
|
|
|
2019-07-08 02:03:55 +00:00
|
|
|
return cmds;
|
|
|
|
}
|
|
|
|
};
|
2019-07-08 03:09:34 +00:00
|
|
|
|
2019-08-08 00:04:51 +00:00
|
|
|
test "noop" {
|
|
|
|
var lang = Lang.init(std.heap.direct_allocator);
|
2019-08-08 00:09:04 +00:00
|
|
|
defer lang.deinit();
|
|
|
|
|
2019-08-08 00:04:51 +00:00
|
|
|
var cmds = try lang.parse("noop;");
|
2019-08-08 00:09:04 +00:00
|
|
|
defer cmds.deinit();
|
|
|
|
|
2019-08-08 00:04:51 +00:00
|
|
|
std.testing.expectEqual(cmds.len, 1);
|
|
|
|
std.testing.expectEqual(cmds.at(0).command, .Noop);
|
|
|
|
}
|
|
|
|
|
|
|
|
test "load, phaser, quicksave" {
|
|
|
|
var lang = Lang.init(std.heap.direct_allocator);
|
2019-08-08 00:09:04 +00:00
|
|
|
defer lang.deinit();
|
|
|
|
|
2019-08-08 00:04:51 +00:00
|
|
|
const prog =
|
|
|
|
\\load :0;
|
|
|
|
\\phaser 3 1 25 0.25 0 1;
|
|
|
|
\\quicksave;
|
|
|
|
;
|
2019-08-08 00:09:04 +00:00
|
|
|
|
2019-08-08 00:04:51 +00:00
|
|
|
var cmds = try lang.parse(prog);
|
2019-08-08 00:09:04 +00:00
|
|
|
defer cmds.deinit();
|
2019-08-08 00:04:51 +00:00
|
|
|
|
|
|
|
std.testing.expectEqual(cmds.len, 3);
|
|
|
|
std.testing.expectEqual(cmds.at(0).command, .Load);
|
|
|
|
std.testing.expectEqual(cmds.at(1).command, .Phaser);
|
|
|
|
std.testing.expectEqual(cmds.at(2).command, .Quicksave);
|
|
|
|
}
|