Compare commits
3 commits
a9e4c5823a
...
b28f208e65
Author | SHA1 | Date | |
---|---|---|---|
b28f208e65 | |||
2a801a129b | |||
78cc7fab4b |
1 changed files with 20 additions and 13 deletions
33
src/lang.zig
33
src/lang.zig
|
@ -527,9 +527,6 @@ pub const Lang = struct {
|
|||
else => true,
|
||||
};
|
||||
|
||||
// TODO: crash when no arguments are left but we still need
|
||||
// arguments...
|
||||
|
||||
if (is_lv2_command) {
|
||||
const split = tok_it.next();
|
||||
if (split == null) {
|
||||
|
@ -571,7 +568,14 @@ pub const Lang = struct {
|
|||
continue;
|
||||
}
|
||||
}
|
||||
const arg = tok_it.next().?;
|
||||
|
||||
const arg_opt = tok_it.next();
|
||||
if (arg_opt == null) {
|
||||
self.doError("Expected parameter for {s}, got nothing", .{cmd_field.name});
|
||||
return;
|
||||
}
|
||||
const arg = arg_opt.?;
|
||||
|
||||
const argument_value = switch (cmd_field.field_type) {
|
||||
usize => try std.fmt.parseInt(usize, arg, 10),
|
||||
i32 => try std.fmt.parseInt(i32, arg, 10),
|
||||
|
@ -643,7 +647,10 @@ pub const Lang = struct {
|
|||
// in a variable because then that variable must be comptime.
|
||||
|
||||
// the drawback of this approach is that our emitted code is basically linear
|
||||
// because we don't use the hashmap anymore. maybe #5359 can help.
|
||||
// because we don't use the hashmap anymore.
|
||||
//
|
||||
// Attempting to use ComptimeHashMap hits compiler bugs and I'm
|
||||
// not sure if we can map strings to *types* in it.
|
||||
|
||||
if (std.mem.eql(u8, &lowered_command_name, command_string)) {
|
||||
found = true;
|
||||
|
@ -665,18 +672,18 @@ pub const Lang = struct {
|
|||
};
|
||||
|
||||
test "noop" {
|
||||
var lang = Lang.init(std.heap.direct_allocator);
|
||||
var lang = Lang.init(std.testing.allocator);
|
||||
defer lang.deinit();
|
||||
|
||||
var cmds = try lang.parse("noop;");
|
||||
defer cmds.deinit();
|
||||
|
||||
std.testing.expectEqual(cmds.len, 1);
|
||||
std.testing.expectEqual(cmds.items[0].command, .Noop);
|
||||
std.testing.expectEqual(cmds.list.items.len, 1);
|
||||
std.testing.expectEqual(cmds.list.items[0].tag, .noop);
|
||||
}
|
||||
|
||||
test "load, phaser, quicksave" {
|
||||
var lang = Lang.init(std.heap.direct_allocator);
|
||||
var lang = Lang.init(std.testing.allocator);
|
||||
defer lang.deinit();
|
||||
|
||||
const prog =
|
||||
|
@ -688,8 +695,8 @@ test "load, phaser, quicksave" {
|
|||
var cmds = try lang.parse(prog);
|
||||
defer cmds.deinit();
|
||||
|
||||
std.testing.expectEqual(cmds.len, 3);
|
||||
std.testing.expectEqual(cmds.items[0].command, .Load);
|
||||
std.testing.expectEqual(cmds.items[1].command, .Phaser);
|
||||
std.testing.expectEqual(cmds.items[2].command, .Quicksave);
|
||||
std.testing.expectEqual(cmds.list.items.len, 3);
|
||||
std.testing.expectEqual(cmds.list.items[0].tag, .load);
|
||||
std.testing.expectEqual(cmds.list.items[1].tag, .phaser);
|
||||
std.testing.expectEqual(cmds.list.items[2].tag, .quicksave);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue