Compilable array manipulation, still some errors
This commit is contained in:
+9
-16
@@ -7,13 +7,8 @@ const Tokenizer = @import("tokenizer.zig").Tokenizer;
|
||||
const dtype = @import("dtype");
|
||||
const UUID = dtype.UUID;
|
||||
|
||||
const Filter = @import("../dataStructure/filter.zig").Filter;
|
||||
const Condition = @import("../dataStructure/filter.zig").Condition;
|
||||
const ConditionValue = @import("../dataStructure/filter.zig").ConditionValue;
|
||||
const ComparisonOperator = @import("../dataStructure/filter.zig").ComparisonOperator;
|
||||
|
||||
const ValueOrArray = @import("parts/newData.zig").ValueOrArray;
|
||||
const AdditionalData = @import("../dataStructure/additionalData.zig").AdditionalData;
|
||||
const AdditionalDataMember = @import("../dataStructure/additionalData.zig").AdditionalDataMember;
|
||||
const send = @import("../utils.zig").send;
|
||||
const printError = @import("../utils.zig").printError;
|
||||
|
||||
@@ -74,8 +69,6 @@ pub usingnamespace @import("parts/filter.zig");
|
||||
pub usingnamespace @import("parts/additionalData.zig");
|
||||
pub usingnamespace @import("utils.zig");
|
||||
|
||||
var toker: Tokenizer = undefined;
|
||||
|
||||
toker: *Tokenizer = undefined,
|
||||
file_engine: *FileEngine,
|
||||
schema_engine: *SchemaEngine,
|
||||
@@ -94,7 +87,7 @@ pub fn parse(self: *Self, buffer: [:0]const u8) ZipponError!void {
|
||||
|
||||
try @import("parts/value.zig").initZeroMap();
|
||||
|
||||
toker = Tokenizer.init(buffer);
|
||||
var toker = Tokenizer.init(buffer);
|
||||
self.toker = &toker;
|
||||
|
||||
var state: State = .start;
|
||||
@@ -241,9 +234,9 @@ pub fn parse(self: *Self, buffer: [:0]const u8) ZipponError!void {
|
||||
defer members.deinit();
|
||||
members.appendSlice(sstruct.members[1..]) catch return ZipponError.MemoryError;
|
||||
|
||||
var data_map = std.StringHashMap(ConditionValue).init(allocator);
|
||||
var data_map = std.StringHashMap(ValueOrArray).init(allocator);
|
||||
defer data_map.deinit();
|
||||
try self.parseNewData(allocator, &data_map, struct_name, &members);
|
||||
try self.parseNewData(allocator, &data_map, struct_name, &members, true);
|
||||
|
||||
var buff = std.ArrayList(u8).init(allocator);
|
||||
defer buff.deinit();
|
||||
@@ -267,9 +260,9 @@ pub fn parse(self: *Self, buffer: [:0]const u8) ZipponError!void {
|
||||
defer members.deinit();
|
||||
members.appendSlice(sstruct.members[1..]) catch return ZipponError.MemoryError;
|
||||
|
||||
var data_map = std.StringHashMap(ConditionValue).init(allocator);
|
||||
var data_map = std.StringHashMap(ValueOrArray).init(allocator);
|
||||
defer data_map.deinit();
|
||||
try self.parseNewData(allocator, &data_map, struct_name, &members);
|
||||
try self.parseNewData(allocator, &data_map, struct_name, &members, true);
|
||||
|
||||
var buff = std.ArrayList(u8).init(allocator);
|
||||
defer buff.deinit();
|
||||
@@ -340,19 +333,19 @@ pub fn parse(self: *Self, buffer: [:0]const u8) ZipponError!void {
|
||||
defer buff.deinit();
|
||||
buff.writer().writeAll("[") catch return ZipponError.WriteError;
|
||||
|
||||
var maps = std.ArrayList(std.StringHashMap(ConditionValue)).init(allocator);
|
||||
var maps = std.ArrayList(std.StringHashMap(ValueOrArray)).init(allocator);
|
||||
defer maps.deinit();
|
||||
|
||||
var local_arena = std.heap.ArenaAllocator.init(allocator);
|
||||
defer local_arena.deinit();
|
||||
const local_allocator = arena.allocator();
|
||||
|
||||
var data_map = std.StringHashMap(ConditionValue).init(allocator);
|
||||
var data_map = std.StringHashMap(ValueOrArray).init(allocator);
|
||||
defer data_map.deinit();
|
||||
|
||||
while (true) { // I could multithread that as it do take a long time for big benchmark
|
||||
data_map.clearRetainingCapacity();
|
||||
try self.parseNewData(local_allocator, &data_map, struct_name, &order);
|
||||
try self.parseNewData(local_allocator, &data_map, struct_name, &order, false);
|
||||
|
||||
var error_message_buffer = std.ArrayList(u8).init(local_allocator);
|
||||
defer error_message_buffer.deinit();
|
||||
|
||||
@@ -8,15 +8,34 @@ const ZipponError = @import("error").ZipponError;
|
||||
|
||||
const Self = @import("../parser.zig");
|
||||
|
||||
// Ok so now for array how do I do. Because the map will not work anymore.
|
||||
// I guess I change the map member_name -> ConditionValue. The ConditionValue can become an enum, either COnditionValue either a new struct
|
||||
// The new struct need to have the operation (append, clear, etc) and a piece of data. The data can either be a single ConditionValue or an array of it.
|
||||
// Or maybe just an array, it can be an array of 1 value.
|
||||
// Like that I just need do add some switch on the enum to make it work
|
||||
|
||||
pub const ValueOrArray = union(enum) {
|
||||
value: ConditionValue,
|
||||
array: ArrayUpdate,
|
||||
};
|
||||
|
||||
pub const ArrayCondition = enum { append, clear, pop, remove, removeat };
|
||||
|
||||
pub const ArrayUpdate = struct {
|
||||
condition: ArrayCondition,
|
||||
data: []ConditionValue,
|
||||
};
|
||||
|
||||
/// Take the tokenizer and return a map of the ADD action.
|
||||
/// Keys are the member name and value are the string of the value in the query. E.g. 'Adrien' or '10'
|
||||
/// Entry token need to be (
|
||||
pub fn parseNewData(
|
||||
self: Self,
|
||||
allocator: Allocator,
|
||||
map: *std.StringHashMap(ConditionValue),
|
||||
map: *std.StringHashMap(ValueOrArray),
|
||||
struct_name: []const u8,
|
||||
order: *std.ArrayList([]const u8),
|
||||
for_update: bool,
|
||||
) !void {
|
||||
var token = self.toker.next();
|
||||
var keep_next = false;
|
||||
@@ -80,8 +99,43 @@ pub fn parseNewData(
|
||||
.expect_equal => switch (token.tag) {
|
||||
// TODO: Implement stuff to manipulate array like APPEND or REMOVE
|
||||
.equal => state = .expect_new_value,
|
||||
.keyword_pop => if (for_update) {} else return printError(
|
||||
"Error: Can only manipulate array with UPDATE.",
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
),
|
||||
.keyword_clear => if (for_update) {} else return printError(
|
||||
"Error: Can only manipulate array with UPDATE.",
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
),
|
||||
.keyword_append => if (for_update) {} else return printError(
|
||||
"Error: Can only manipulate array with UPDATE.",
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
),
|
||||
.keyword_remove => if (for_update) {} else return printError(
|
||||
"Error: Can only manipulate array with UPDATE.",
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
),
|
||||
.keyword_remove_at => if (for_update) {} else return printError(
|
||||
"Error: Can only manipulate array with UPDATE.",
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
),
|
||||
else => return printError(
|
||||
"Error: Expected =",
|
||||
"Error: Expected = or array manipulation keyword (APPEND, CLEAR, POP, REMOVE, REMOVEAT)",
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
@@ -91,7 +145,10 @@ pub fn parseNewData(
|
||||
|
||||
.expect_new_value => {
|
||||
const data_type = self.schema_engine.memberName2DataType(struct_name, member_name) catch return ZipponError.StructNotFound;
|
||||
map.put(member_name, try self.parseConditionValue(allocator, struct_name, member_name, data_type, &token)) catch return ZipponError.MemoryError;
|
||||
map.put(
|
||||
member_name,
|
||||
ValueOrArray{ .value = try self.parseConditionValue(allocator, struct_name, member_name, data_type, &token) },
|
||||
) catch return ZipponError.MemoryError;
|
||||
if (data_type == .link or data_type == .link_array) {
|
||||
token = self.toker.last_token;
|
||||
keep_next = true;
|
||||
|
||||
Reference in New Issue
Block a user