Compare commits
No commits in common. "90bc830a9a46186e19504164072c3bdac140f550" and "9fd41a61bf283850c444399380ab8a819a99893a" have entirely different histories.
90bc830a9a
...
9fd41a61bf
2 changed files with 2 additions and 65 deletions
|
@ -193,7 +193,7 @@ pub const Image = struct {
|
||||||
sseek(out_file, start);
|
sseek(out_file, start);
|
||||||
|
|
||||||
while (i <= end) : (i += buf.len) {
|
while (i <= end) : (i += buf.len) {
|
||||||
std.debug.warn("\t\ti={}, buf.len={}, end={}\n", i, buf.len, end);
|
std.debug.warn("i={}, buf.len={}, end={}\n", i, buf.len, end);
|
||||||
sseek(self.sndfile, i);
|
sseek(self.sndfile, i);
|
||||||
sseek(out_file, i);
|
sseek(out_file, i);
|
||||||
|
|
||||||
|
|
65
src/lang.zig
65
src/lang.zig
|
@ -6,8 +6,6 @@ pub const ParseError = error{
|
||||||
NoCommandGiven,
|
NoCommandGiven,
|
||||||
UnknownCommand,
|
UnknownCommand,
|
||||||
ArgRequired,
|
ArgRequired,
|
||||||
FloatParseFail,
|
|
||||||
ParseFail,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const CommandType = enum {
|
pub const CommandType = enum {
|
||||||
|
@ -234,64 +232,10 @@ pub const Lang = struct {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expectAny(self: *Lang, count: usize, args: ArgList) !void {
|
|
||||||
if (args.len != count) {
|
|
||||||
std.debug.warn("expected {} arguments, found {}\n", count, args.len);
|
|
||||||
return error.ArgRequired;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn expectSingle(self: *Lang, args: ArgList) !void {
|
|
||||||
return try self.expectAny(1, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn expectFloat(self: *Lang, count: usize, args: ArgList) !void {
|
|
||||||
var i: usize = 0;
|
|
||||||
|
|
||||||
if (args.len != count) {
|
|
||||||
std.debug.warn("expected {} arguments, found {}\n", count, args.len);
|
|
||||||
return error.ArgRequired;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (i < count) : (i += 1) {
|
|
||||||
var arg = args.at(i);
|
|
||||||
|
|
||||||
_ = std.fmt.parseFloat(f32, arg) catch |err| {
|
|
||||||
std.debug.warn("failed to parse f32: {}\n", err);
|
|
||||||
return error.FloatParseFail;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn validateCommand(self: *Lang, cmd: *Command) !void {
|
|
||||||
switch (cmd.command) {
|
|
||||||
.Quicksave, .Noop => {},
|
|
||||||
.Load, .RunQS => try self.expectSingle(cmd.args),
|
|
||||||
.Amp => try self.expectFloat(3, cmd.args),
|
|
||||||
.RFlanger => try self.expectFloat(4, cmd.args),
|
|
||||||
.Eq => try self.expectFloat(5, cmd.args),
|
|
||||||
.Phaser => try self.expectFloat(6, cmd.args),
|
|
||||||
.Mbeq => try self.expectFloat(15, cmd.args),
|
|
||||||
.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),
|
|
||||||
.RevDelay => try self.expectFloat(5, cmd.args),
|
|
||||||
.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),
|
|
||||||
else => std.debug.warn("WARN unchecked command {}\n", cmd.command),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn parse(self: *Lang, data: []const u8) !CommandList {
|
pub fn parse(self: *Lang, data: []const u8) !CommandList {
|
||||||
var splitted_it = std.mem.separate(data, ";");
|
var splitted_it = std.mem.separate(data, ";");
|
||||||
try self.fillKeywords();
|
try self.fillKeywords();
|
||||||
var cmds = CommandList.init(self.allocator);
|
var cmds = CommandList.init(self.allocator);
|
||||||
var idx: usize = 0;
|
|
||||||
|
|
||||||
while (splitted_it.next()) |stmt_orig| {
|
while (splitted_it.next()) |stmt_orig| {
|
||||||
var stmt = std.mem.trimRight(u8, stmt_orig, "\n");
|
var stmt = std.mem.trimRight(u8, stmt_orig, "\n");
|
||||||
|
@ -317,22 +261,15 @@ pub const Lang = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var args = ArgList.init(self.allocator);
|
var args = ArgList.init(self.allocator);
|
||||||
|
|
||||||
while (tok_it.next()) |arg| {
|
while (tok_it.next()) |arg| {
|
||||||
try args.append(arg);
|
try args.append(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// construct final Command based on command
|
// construct final Command based on command
|
||||||
var cmd_ptr = try self.allocator.create(Command);
|
var cmd_ptr = try self.allocator.create(Command);
|
||||||
errdefer self.allocator.destroy(cmd_ptr);
|
|
||||||
|
|
||||||
cmd_ptr.* = Command{ .command = ctype, .args = args };
|
cmd_ptr.* = Command{ .command = ctype, .args = args };
|
||||||
self.validateCommand(cmd_ptr) catch |err| {
|
|
||||||
std.debug.warn("error at line {}: {}\n", idx, err);
|
|
||||||
return ParseError.ParseFail;
|
|
||||||
};
|
|
||||||
|
|
||||||
try cmds.append(cmd_ptr);
|
try cmds.append(cmd_ptr);
|
||||||
idx += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmds;
|
return cmds;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue