Working REMOVE and REMOVEAT
This commit is contained in:
parent
cd178ce53d
commit
8c6a6188dd
@ -171,11 +171,6 @@ fn append(allocator: std.mem.Allocator, input: *zid.Data, data: ConditionValue)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Change the array for a map to speed up thing
|
|
||||||
// And also I dont really need to realoc anything, only append need because here it can only go lower
|
|
||||||
// So I could just memcopy the remaining of the bytes at the current position, so it overwrite the value to remove
|
|
||||||
// Like if I want to re;ove 3 in [1 2 3 4 5], it would become [1 2 4 5 5]. Then I dont take the last value when I return.
|
|
||||||
// But that mean I keep in memory useless data, so maybe not
|
|
||||||
fn remove(allocator: std.mem.Allocator, input: *zid.Data, data: ConditionValue) !void {
|
fn remove(allocator: std.mem.Allocator, input: *zid.Data, data: ConditionValue) !void {
|
||||||
var iter = try zid.ArrayIterator.init(input.*);
|
var iter = try zid.ArrayIterator.init(input.*);
|
||||||
switch (input.*) {
|
switch (input.*) {
|
||||||
|
@ -49,6 +49,8 @@ pub fn parseNewData(
|
|||||||
var state: Self.State = .expect_member_OR_value;
|
var state: Self.State = .expect_member_OR_value;
|
||||||
var i: usize = 0;
|
var i: usize = 0;
|
||||||
|
|
||||||
|
var array_condition_buf: ArrayCondition = undefined;
|
||||||
|
|
||||||
while (state != .end) : ({
|
while (state != .end) : ({
|
||||||
token = if (!keep_next) self.toker.next() else token;
|
token = if (!keep_next) self.toker.next() else token;
|
||||||
keep_next = false;
|
keep_next = false;
|
||||||
@ -131,6 +133,7 @@ pub fn parseNewData(
|
|||||||
),
|
),
|
||||||
.keyword_append => if (for_update) {
|
.keyword_append => if (for_update) {
|
||||||
state = .expect_new_array;
|
state = .expect_new_array;
|
||||||
|
array_condition_buf = .append;
|
||||||
} else return printError(
|
} else return printError(
|
||||||
"Error: Can only manipulate array with UPDATE.",
|
"Error: Can only manipulate array with UPDATE.",
|
||||||
ZipponError.SynthaxError,
|
ZipponError.SynthaxError,
|
||||||
@ -140,6 +143,7 @@ pub fn parseNewData(
|
|||||||
),
|
),
|
||||||
.keyword_remove => if (for_update) {
|
.keyword_remove => if (for_update) {
|
||||||
state = .expect_new_array;
|
state = .expect_new_array;
|
||||||
|
array_condition_buf = .remove;
|
||||||
} else return printError(
|
} else return printError(
|
||||||
"Error: Can only manipulate array with UPDATE.",
|
"Error: Can only manipulate array with UPDATE.",
|
||||||
ZipponError.SynthaxError,
|
ZipponError.SynthaxError,
|
||||||
@ -149,6 +153,7 @@ pub fn parseNewData(
|
|||||||
),
|
),
|
||||||
.keyword_remove_at => if (for_update) {
|
.keyword_remove_at => if (for_update) {
|
||||||
state = .expect_new_array;
|
state = .expect_new_array;
|
||||||
|
array_condition_buf = .removeat;
|
||||||
} else return printError(
|
} else return printError(
|
||||||
"Error: Can only manipulate array with UPDATE.",
|
"Error: Can only manipulate array with UPDATE.",
|
||||||
ZipponError.SynthaxError,
|
ZipponError.SynthaxError,
|
||||||
@ -273,7 +278,10 @@ pub fn parseNewData(
|
|||||||
};
|
};
|
||||||
map.put(
|
map.put(
|
||||||
member_name,
|
member_name,
|
||||||
ValueOrArray{ .array = .{ .condition = .append, .data = try self.parseConditionValue(allocator, struct_name, member_name, new_data_type, &token) } },
|
ValueOrArray{ .array = .{
|
||||||
|
.condition = array_condition_buf,
|
||||||
|
.data = try self.parseConditionValue(allocator, struct_name, member_name, new_data_type, &token),
|
||||||
|
} },
|
||||||
) catch return ZipponError.MemoryError;
|
) catch return ZipponError.MemoryError;
|
||||||
if (member_data_type == .link or member_data_type == .link_array) {
|
if (member_data_type == .link or member_data_type == .link_array) {
|
||||||
token = self.toker.last_token;
|
token = self.toker.last_token;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user