fix command parsing

This commit is contained in:
Luna 2022-04-27 20:01:14 -03:00
parent 5d1bcf33ee
commit 1987c4d497

View file

@ -479,7 +479,7 @@ pub const CommandList = struct {
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {
for (self.list.items) |cmd_ptr| { for (self.list.items) |cmd_ptr| {
self.list.allocator.destroy(cmd_ptr); //self.list.allocator.destroy(cmd_ptr);
inline for (@typeInfo(Command.Tag).Enum.fields) |field| { inline for (@typeInfo(Command.Tag).Enum.fields) |field| {
if (cmd_ptr.tag == @field(Command.Tag, field.name)) { if (cmd_ptr.tag == @field(Command.Tag, field.name)) {
const actual_tag = const actual_tag =
@ -530,9 +530,9 @@ pub const Lang = struct {
} }
fn doError(self: *Lang, comptime fmt: []const u8, args: anytype) void { fn doError(self: *Lang, comptime fmt: []const u8, args: anytype) void {
log.debug("ERROR! at line {}: ", .{self.line}); log.err("ERROR! at line {}: ", .{self.line});
log.debug(fmt, args); log.err(fmt, args);
log.debug("\n", .{}); log.err("\n", .{});
self.has_error = true; self.has_error = true;
} }
@ -655,7 +655,16 @@ pub const Lang = struct {
const struct_name = cmd_struct_decl.name; const struct_name = cmd_struct_decl.name;
const cmd_struct_type = @field(Command, struct_name); const cmd_struct_type = @field(Command, struct_name);
switch (@typeInfo(@TypeOf(cmd_struct_type))) { const info_of_info = @typeInfo(@TypeOf(cmd_struct_type));
switch (info_of_info) {
.Type => {},
else => continue,
}
const info = @typeInfo(cmd_struct_type);
switch (info) {
.Struct => {}, .Struct => {},
else => continue, else => continue,
} }
@ -677,7 +686,7 @@ pub const Lang = struct {
// Attempting to use ComptimeHashMap hits compiler bugs and I'm // Attempting to use ComptimeHashMap hits compiler bugs and I'm
// not sure if we can map strings to *types* in it. // not sure if we can map strings to *types* in it.
if (std.mem.eql(u8, &lowered_command_name, command_string)) { if ((!found) and std.mem.eql(u8, &lowered_command_name, command_string)) {
found = true; found = true;
try self.parseCommandArguments(cmd_struct_type, &tok_it, &cmds); try self.parseCommandArguments(cmd_struct_type, &tok_it, &cmds);
} }