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
|
// 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
|
// 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;
|
return buff.toOwnedSlice() catch return ZipponError.MemoryError;
|
||||||
}
|
}
|
||||||
@ -614,7 +614,7 @@ pub const FileEngine = struct {
|
|||||||
|
|
||||||
// I then call parseEntitiesRelationMap on each
|
// 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
|
// 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(
|
fn parseEntitiesRelationMapOneFile(
|
||||||
|
@ -244,6 +244,7 @@ pub const SchemaEngine = struct {
|
|||||||
const map = alloc.create(std.AutoHashMap([16]u8, JsonString)) catch return ZipponError.MemoryError;
|
const map = alloc.create(std.AutoHashMap([16]u8, JsonString)) catch return ZipponError.MemoryError;
|
||||||
map.* = std.AutoHashMap([16]u8, JsonString).init(alloc);
|
map.* = std.AutoHashMap([16]u8, JsonString).init(alloc);
|
||||||
array.append(RelationMap{
|
array.append(RelationMap{
|
||||||
|
.struct_name = sstruct.links.get(child.name).?,
|
||||||
.member_name = 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
|
.additional_data = child.additional_data, // Maybe I need to check if it exist, im not sure it always exist
|
||||||
.map = map,
|
.map = map,
|
||||||
|
@ -29,6 +29,7 @@ pub const JsonString = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub const RelationMap = struct {
|
pub const RelationMap = struct {
|
||||||
|
struct_name: []const u8,
|
||||||
member_name: []const u8,
|
member_name: []const u8,
|
||||||
additional_data: AdditionalData,
|
additional_data: AdditionalData,
|
||||||
map: *std.AutoHashMap([16]u8, JsonString),
|
map: *std.AutoHashMap([16]u8, JsonString),
|
||||||
|
@ -382,106 +382,105 @@ pub const Parser = struct {
|
|||||||
token = if (keep_next) token else self.toker.next();
|
token = if (keep_next) token else self.toker.next();
|
||||||
keep_next = false;
|
keep_next = false;
|
||||||
if (PRINT_STATE) std.debug.print("parseFilter: {any}\n", .{state});
|
if (PRINT_STATE) std.debug.print("parseFilter: {any}\n", .{state});
|
||||||
})
|
}) switch (state) {
|
||||||
switch (state) {
|
.expect_condition => switch (token.tag) {
|
||||||
.expect_condition => switch (token.tag) {
|
.r_brace => {
|
||||||
.r_brace => {
|
if (!is_sub) {
|
||||||
if (!is_sub) {
|
state = .end;
|
||||||
state = .end;
|
} else {
|
||||||
} else {
|
return printError(
|
||||||
return printError(
|
"Error: Expected ) not }",
|
||||||
"Error: Expected ) not }",
|
ZipponError.SynthaxError,
|
||||||
ZipponError.SynthaxError,
|
self.toker.buffer,
|
||||||
self.toker.buffer,
|
token.loc.start,
|
||||||
token.loc.start,
|
token.loc.end,
|
||||||
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,
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
|
.r_paren => {
|
||||||
.expect_ANDOR_OR_end => switch (token.tag) {
|
if (is_sub) {
|
||||||
.r_brace => {
|
state = .end;
|
||||||
if (!is_sub) {
|
} else {
|
||||||
state = .end;
|
return printError(
|
||||||
} else {
|
"Error: Expected } not )",
|
||||||
return printError(
|
ZipponError.SynthaxError,
|
||||||
"Error: Expected ) not }",
|
self.toker.buffer,
|
||||||
ZipponError.SynthaxError,
|
token.loc.start,
|
||||||
self.toker.buffer,
|
token.loc.end,
|
||||||
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,
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
|
.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;
|
return filter;
|
||||||
}
|
}
|
||||||
@ -1098,8 +1097,9 @@ pub const Parser = struct {
|
|||||||
token.* = self.toker.next();
|
token.* = self.toker.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
additional_data.limit = 1;
|
||||||
|
|
||||||
const link_sstruct = try self.schema_engine.linkedStructName(struct_name, member_name);
|
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)
|
if (token.tag == .l_brace) filter = try self.parseFilter( // FIXME: Look like the filter is empty after that (root node is Empty)
|
||||||
allocator,
|
allocator,
|
||||||
link_sstruct.name,
|
link_sstruct.name,
|
||||||
@ -1112,7 +1112,11 @@ pub const Parser = struct {
|
|||||||
token.loc.end,
|
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
|
// Here I have the filter and additionalData
|
||||||
const map = allocator.create(std.AutoHashMap(UUID, void)) catch return ZipponError.MemoryError;
|
const map = allocator.create(std.AutoHashMap(UUID, void)) catch return ZipponError.MemoryError;
|
||||||
@ -1154,8 +1158,8 @@ pub const Parser = struct {
|
|||||||
token.* = self.toker.next();
|
token.* = self.toker.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
const sstruct = try self.schema_engine.structName2SchemaStruct(struct_name);
|
const link_sstruct = try self.schema_engine.linkedStructName(struct_name, member_name);
|
||||||
if (token.tag == .l_brace) filter = try self.parseFilter(allocator, sstruct.links.get(member_name).?, false) else return printError(
|
if (token.tag == .l_brace) filter = try self.parseFilter(allocator, link_sstruct.name, false) else return printError(
|
||||||
"Error: Expected filter",
|
"Error: Expected filter",
|
||||||
ZipponError.SynthaxError,
|
ZipponError.SynthaxError,
|
||||||
self.toker.buffer,
|
self.toker.buffer,
|
||||||
@ -1163,6 +1167,11 @@ pub const Parser = struct {
|
|||||||
token.loc.end,
|
token.loc.end,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
filter = switch (filter.?.root.*) {
|
||||||
|
.empty => null,
|
||||||
|
else => filter,
|
||||||
|
};
|
||||||
|
|
||||||
// Here I have the filter and additionalData
|
// Here I have the filter and additionalData
|
||||||
const map = allocator.create(std.AutoHashMap(UUID, void)) catch return ZipponError.MemoryError;
|
const map = allocator.create(std.AutoHashMap(UUID, void)) catch return ZipponError.MemoryError;
|
||||||
map.* = std.AutoHashMap(UUID, void).init(allocator);
|
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 User {}");
|
||||||
try testParsing(db, "DELETE Post {}");
|
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 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, "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 Post [id, text, at, from [id, name]] {}");
|
||||||
try testParsing(db, "GRAB User [id, name] {}");
|
try testParsing(db, "GRAB User [id, name] {}");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user