Condition with index instead of member_name
Condition now store the index of the value in the file instead of the member_name. So when I parse, I can just use the list array []Data and the index to compare both value
This commit is contained in:
parent
304ec89167
commit
294d4f7a2c
@ -1069,7 +1069,7 @@ pub const FileEngine = struct {
|
|||||||
|
|
||||||
/// Get the type of the member
|
/// Get the type of the member
|
||||||
pub fn memberName2DataType(self: *FileEngine, struct_name: []const u8, member_name: []const u8) FileEngineError!DataType {
|
pub fn memberName2DataType(self: *FileEngine, struct_name: []const u8, member_name: []const u8) FileEngineError!DataType {
|
||||||
var i: u16 = 0;
|
var i: usize = 0;
|
||||||
|
|
||||||
for (try self.structName2structMembers(struct_name)) |mn| {
|
for (try self.structName2structMembers(struct_name)) |mn| {
|
||||||
const dtypes = try self.structName2DataType(struct_name);
|
const dtypes = try self.structName2DataType(struct_name);
|
||||||
@ -1080,9 +1080,20 @@ pub const FileEngine = struct {
|
|||||||
return FileEngineError.MemberNotFound;
|
return FileEngineError.MemberNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn memberName2DataIndex(self: *FileEngine, struct_name: []const u8, member_name: []const u8) FileEngineError!usize {
|
||||||
|
var i: usize = 0;
|
||||||
|
|
||||||
|
for (try self.structName2structMembers(struct_name)) |mn| {
|
||||||
|
if (std.mem.eql(u8, mn, member_name)) return i;
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FileEngineError.MemberNotFound;
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the list of all member name for a struct name
|
/// Get the list of all member name for a struct name
|
||||||
pub fn structName2structMembers(self: *FileEngine, struct_name: []const u8) FileEngineError![][]const u8 {
|
pub fn structName2structMembers(self: *FileEngine, struct_name: []const u8) FileEngineError![][]const u8 {
|
||||||
var i: u16 = 0;
|
var i: usize = 0;
|
||||||
|
|
||||||
while (i < self.struct_array.items.len) : (i += 1) if (std.mem.eql(u8, self.struct_array.items[i].name, struct_name)) break;
|
while (i < self.struct_array.items.len) : (i += 1) if (std.mem.eql(u8, self.struct_array.items[i].name, struct_name)) break;
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ pub const Parser = struct {
|
|||||||
name: []const u8,
|
name: []const u8,
|
||||||
members: std.ArrayList([]const u8),
|
members: std.ArrayList([]const u8),
|
||||||
types: std.ArrayList(DataType),
|
types: std.ArrayList(DataType),
|
||||||
links: std.StringHashMap([]const u8),
|
links: std.StringHashMap([]const u8), // Map key as member_name and value as struct_name, like a dtype
|
||||||
|
|
||||||
pub fn init(allocator: Allocator, name: []const u8) SchemaStruct {
|
pub fn init(allocator: Allocator, name: []const u8) SchemaStruct {
|
||||||
return SchemaStruct{
|
return SchemaStruct{
|
||||||
|
@ -47,11 +47,10 @@ const LogicalOperator = enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub const Condition = struct {
|
pub const Condition = struct {
|
||||||
member_name: []const u8 = undefined,
|
|
||||||
value: []const u8 = undefined,
|
value: []const u8 = undefined,
|
||||||
operation: ComparisonOperator = undefined,
|
operation: ComparisonOperator = undefined,
|
||||||
data_type: DataType = undefined,
|
data_type: DataType = undefined,
|
||||||
// data_index: usize TODO: add this member, this is the position in the row of the value, to use in the evaluate method
|
data_index: usize = undefined, // Index in the file
|
||||||
};
|
};
|
||||||
|
|
||||||
const FilterNode = union(enum) {
|
const FilterNode = union(enum) {
|
||||||
@ -196,8 +195,8 @@ pub const Filter = struct {
|
|||||||
self.printNode(logical.right.*);
|
self.printNode(logical.right.*);
|
||||||
std.debug.print(" ) ", .{});
|
std.debug.print(" ) ", .{});
|
||||||
},
|
},
|
||||||
.condition => |condition| std.debug.print("{s} {s} {s} |{any}|", .{
|
.condition => |condition| std.debug.print("{d} {s} {s} |{any}|", .{
|
||||||
condition.member_name,
|
condition.data_index,
|
||||||
condition.operation.str(),
|
condition.operation.str(),
|
||||||
condition.value,
|
condition.value,
|
||||||
condition.data_type,
|
condition.data_type,
|
||||||
|
@ -542,7 +542,10 @@ pub const Parser = struct {
|
|||||||
struct_name,
|
struct_name,
|
||||||
self.toker.getTokenSlice(token),
|
self.toker.getTokenSlice(token),
|
||||||
) catch return ZiQlParserError.MemberNotFound;
|
) catch return ZiQlParserError.MemberNotFound;
|
||||||
condition.member_name = self.toker.getTokenSlice(token);
|
condition.data_index = self.file_engine.memberName2DataIndex(
|
||||||
|
struct_name,
|
||||||
|
self.toker.getTokenSlice(token),
|
||||||
|
) catch return ZiQlParserError.MemberNotFound;
|
||||||
state = State.expect_operation;
|
state = State.expect_operation;
|
||||||
},
|
},
|
||||||
else => return printError(
|
else => return printError(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user