Working multi struct schema with relationship!
Noce
This commit is contained in:
parent
71e5f6eb1e
commit
d533eaff98
@ -462,7 +462,7 @@ pub const FileEngine = struct {
|
||||
|
||||
// I then call parseEntitiesRelationMap on each
|
||||
// This will update the buff items to be the same Json but with {|<[16]u8>|} replaced with the right Json
|
||||
for (relation_maps) |*relation_map| try self.parseEntitiesRelationMap(struct_name, relation_map, &buff);
|
||||
for (relation_maps) |*relation_map| try self.parseEntitiesRelationMap(relation_map.struct_name, relation_map, &buff);
|
||||
|
||||
return buff.toOwnedSlice() catch return ZipponError.MemoryError;
|
||||
}
|
||||
@ -614,7 +614,7 @@ pub const FileEngine = struct {
|
||||
|
||||
// I then call parseEntitiesRelationMap on each
|
||||
// This will update the buff items to be the same Json but with {|<[16]u8>|} replaced with the right Json
|
||||
for (relation_maps) |*sub_relation_map| try self.parseEntitiesRelationMap(struct_name, sub_relation_map, buff);
|
||||
for (relation_maps) |*sub_relation_map| try self.parseEntitiesRelationMap(sub_relation_map.struct_name, sub_relation_map, buff);
|
||||
}
|
||||
|
||||
fn parseEntitiesRelationMapOneFile(
|
||||
|
@ -244,6 +244,7 @@ pub const SchemaEngine = struct {
|
||||
const map = alloc.create(std.AutoHashMap([16]u8, JsonString)) catch return ZipponError.MemoryError;
|
||||
map.* = std.AutoHashMap([16]u8, JsonString).init(alloc);
|
||||
array.append(RelationMap{
|
||||
.struct_name = sstruct.links.get(child.name).?,
|
||||
.member_name = child.name,
|
||||
.additional_data = child.additional_data, // Maybe I need to check if it exist, im not sure it always exist
|
||||
.map = map,
|
||||
|
@ -29,6 +29,7 @@ pub const JsonString = struct {
|
||||
};
|
||||
|
||||
pub const RelationMap = struct {
|
||||
struct_name: []const u8,
|
||||
member_name: []const u8,
|
||||
additional_data: AdditionalData,
|
||||
map: *std.AutoHashMap([16]u8, JsonString),
|
||||
|
@ -382,106 +382,105 @@ pub const Parser = struct {
|
||||
token = if (keep_next) token else self.toker.next();
|
||||
keep_next = false;
|
||||
if (PRINT_STATE) std.debug.print("parseFilter: {any}\n", .{state});
|
||||
})
|
||||
switch (state) {
|
||||
.expect_condition => switch (token.tag) {
|
||||
.r_brace => {
|
||||
if (!is_sub) {
|
||||
state = .end;
|
||||
} else {
|
||||
return printError(
|
||||
"Error: Expected ) not }",
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
);
|
||||
}
|
||||
},
|
||||
.r_paren => {
|
||||
if (is_sub) {
|
||||
state = .end;
|
||||
} else {
|
||||
return printError(
|
||||
"Error: Expected } not )",
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
);
|
||||
}
|
||||
},
|
||||
.l_paren => {
|
||||
var sub_filter = try self.parseFilter(allocator, struct_name, true);
|
||||
filter.addSubFilter(&sub_filter);
|
||||
token = self.toker.last();
|
||||
keep_next = true;
|
||||
state = .expect_ANDOR_OR_end;
|
||||
},
|
||||
.identifier => {
|
||||
const condition = try self.parseCondition(allocator, &token, struct_name);
|
||||
try filter.addCondition(condition);
|
||||
token = self.toker.last();
|
||||
keep_next = true;
|
||||
state = .expect_ANDOR_OR_end;
|
||||
},
|
||||
else => return printError(
|
||||
"Error: Expected ( or condition.",
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
),
|
||||
}) switch (state) {
|
||||
.expect_condition => switch (token.tag) {
|
||||
.r_brace => {
|
||||
if (!is_sub) {
|
||||
state = .end;
|
||||
} else {
|
||||
return printError(
|
||||
"Error: Expected ) not }",
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
.expect_ANDOR_OR_end => switch (token.tag) {
|
||||
.r_brace => {
|
||||
if (!is_sub) {
|
||||
state = .end;
|
||||
} else {
|
||||
return printError(
|
||||
"Error: Expected ) not }",
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
);
|
||||
}
|
||||
},
|
||||
.r_paren => {
|
||||
if (is_sub) {
|
||||
state = .end;
|
||||
} else {
|
||||
return printError(
|
||||
"Error: Expected } not )",
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
);
|
||||
}
|
||||
},
|
||||
.keyword_and => {
|
||||
try filter.addLogicalOperator(.AND);
|
||||
state = .expect_condition;
|
||||
},
|
||||
.keyword_or => {
|
||||
try filter.addLogicalOperator(.OR);
|
||||
state = .expect_condition;
|
||||
},
|
||||
else => return printError(
|
||||
"Error: Expected AND, OR, or }",
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
),
|
||||
.r_paren => {
|
||||
if (is_sub) {
|
||||
state = .end;
|
||||
} else {
|
||||
return printError(
|
||||
"Error: Expected } not )",
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
);
|
||||
}
|
||||
},
|
||||
.l_paren => {
|
||||
var sub_filter = try self.parseFilter(allocator, struct_name, true);
|
||||
filter.addSubFilter(&sub_filter);
|
||||
token = self.toker.last();
|
||||
keep_next = true;
|
||||
state = .expect_ANDOR_OR_end;
|
||||
},
|
||||
.identifier => {
|
||||
const condition = try self.parseCondition(allocator, &token, struct_name);
|
||||
try filter.addCondition(condition);
|
||||
token = self.toker.last();
|
||||
keep_next = true;
|
||||
state = .expect_ANDOR_OR_end;
|
||||
},
|
||||
else => return printError(
|
||||
"Error: Expected ( or condition.",
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
),
|
||||
},
|
||||
|
||||
.end => {},
|
||||
.expect_ANDOR_OR_end => switch (token.tag) {
|
||||
.r_brace => {
|
||||
if (!is_sub) {
|
||||
state = .end;
|
||||
} else {
|
||||
return printError(
|
||||
"Error: Expected ) not }",
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
);
|
||||
}
|
||||
},
|
||||
.r_paren => {
|
||||
if (is_sub) {
|
||||
state = .end;
|
||||
} else {
|
||||
return printError(
|
||||
"Error: Expected } not )",
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
);
|
||||
}
|
||||
},
|
||||
.keyword_and => {
|
||||
try filter.addLogicalOperator(.AND);
|
||||
state = .expect_condition;
|
||||
},
|
||||
.keyword_or => {
|
||||
try filter.addLogicalOperator(.OR);
|
||||
state = .expect_condition;
|
||||
},
|
||||
else => return printError(
|
||||
"Error: Expected AND, OR, or }",
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
),
|
||||
},
|
||||
|
||||
else => unreachable,
|
||||
};
|
||||
.end => {},
|
||||
|
||||
else => unreachable,
|
||||
};
|
||||
|
||||
return filter;
|
||||
}
|
||||
@ -1098,8 +1097,9 @@ pub const Parser = struct {
|
||||
token.* = self.toker.next();
|
||||
}
|
||||
|
||||
additional_data.limit = 1;
|
||||
|
||||
const link_sstruct = try self.schema_engine.linkedStructName(struct_name, member_name);
|
||||
std.debug.print("Link SchemaStruct: {s}\n", .{link_sstruct.name});
|
||||
if (token.tag == .l_brace) filter = try self.parseFilter( // FIXME: Look like the filter is empty after that (root node is Empty)
|
||||
allocator,
|
||||
link_sstruct.name,
|
||||
@ -1112,7 +1112,11 @@ pub const Parser = struct {
|
||||
token.loc.end,
|
||||
);
|
||||
|
||||
filter.?.debugPrint();
|
||||
filter = switch (filter.?.root.*) {
|
||||
.empty => null,
|
||||
else => filter,
|
||||
};
|
||||
std.debug.print("Filter: {any}\n", .{filter});
|
||||
|
||||
// Here I have the filter and additionalData
|
||||
const map = allocator.create(std.AutoHashMap(UUID, void)) catch return ZipponError.MemoryError;
|
||||
@ -1154,8 +1158,8 @@ pub const Parser = struct {
|
||||
token.* = self.toker.next();
|
||||
}
|
||||
|
||||
const sstruct = try self.schema_engine.structName2SchemaStruct(struct_name);
|
||||
if (token.tag == .l_brace) filter = try self.parseFilter(allocator, sstruct.links.get(member_name).?, false) else return printError(
|
||||
const link_sstruct = try self.schema_engine.linkedStructName(struct_name, member_name);
|
||||
if (token.tag == .l_brace) filter = try self.parseFilter(allocator, link_sstruct.name, false) else return printError(
|
||||
"Error: Expected filter",
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
@ -1163,6 +1167,11 @@ pub const Parser = struct {
|
||||
token.loc.end,
|
||||
);
|
||||
|
||||
filter = switch (filter.?.root.*) {
|
||||
.empty => null,
|
||||
else => filter,
|
||||
};
|
||||
|
||||
// Here I have the filter and additionalData
|
||||
const map = allocator.create(std.AutoHashMap(UUID, void)) catch return ZipponError.MemoryError;
|
||||
map.* = std.AutoHashMap(UUID, void).init(allocator);
|
||||
|
2
test.zig
2
test.zig
@ -139,7 +139,7 @@ test "3 struct ADD" {
|
||||
try testParsing(db, "DELETE User {}");
|
||||
try testParsing(db, "DELETE Post {}");
|
||||
try testParsing(db, "ADD User (name = 'Bob', email='bob@email.com', age=55, friends=none, posts=none, comments=none, bday=2000/01/01)");
|
||||
try testParsing(db, "ADD Post (text = 'Hello every body', at=NOW, from={}, comments=none)");
|
||||
try testParsing(db, "ADD Post (text = 'Hello every body', at=NOW, from=none, comments=none)");
|
||||
try testParsing(db, "ADD Post (text = 'Hello every body', at=NOW, from={}, comments=none)");
|
||||
try testParsing(db, "GRAB Post [id, text, at, from [id, name]] {}");
|
||||
try testParsing(db, "GRAB User [id, name] {}");
|
||||
|
Loading…
x
Reference in New Issue
Block a user