From 7f27557ca253b8590205f1bd0eeaf2dd729f53fd Mon Sep 17 00:00:00 2001 From: MrBounty Date: Fri, 29 Nov 2024 21:20:12 +0100 Subject: [PATCH] Fix parsing array Before if the array is [ 1 ] I get [ 0, 1, 0] because I get 2 empty string that when I try to make into int, it become 0 --- lib/types/stringToType.zig | 13 ++++++++++++- src/ziqlParser.zig | 4 +++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/types/stringToType.zig b/lib/types/stringToType.zig index b7e3e9d..5872612 100644 --- a/lib/types/stringToType.zig +++ b/lib/types/stringToType.zig @@ -14,6 +14,7 @@ pub fn parseArrayInt(allocator: std.mem.Allocator, array_str: []const u8) ![]con var it = std.mem.splitAny(u8, array_str[1 .. array_str.len - 1], " "); while (it.next()) |x| { + if (std.mem.eql(u8, " ", x) or std.mem.eql(u8, "", x)) continue; try array.append(parseInt(x)); } @@ -29,6 +30,7 @@ pub fn parseArrayFloat(allocator: std.mem.Allocator, array_str: []const u8) ![]c var it = std.mem.splitAny(u8, array_str[1 .. array_str.len - 1], " "); while (it.next()) |x| { + if (std.mem.eql(u8, " ", x) or std.mem.eql(u8, "", x)) continue; try array.append(parseFloat(x)); } @@ -52,6 +54,7 @@ pub fn parseArrayDate(allocator: std.mem.Allocator, array_str: []const u8) ![]co var it = std.mem.splitAny(u8, array_str[1 .. array_str.len - 1], " "); while (it.next()) |x| { + if (std.mem.eql(u8, " ", x) or std.mem.eql(u8, "", x)) continue; try array.append(parseDate(x)); } @@ -63,6 +66,7 @@ pub fn parseArrayDateUnix(allocator: std.mem.Allocator, array_str: []const u8) ! var it = std.mem.splitAny(u8, array_str[1 .. array_str.len - 1], " "); while (it.next()) |x| { + if (std.mem.eql(u8, " ", x) or std.mem.eql(u8, "", x)) continue; try array.append(parseDate(x).toUnix()); } @@ -83,6 +87,7 @@ pub fn parseArrayTime(allocator: std.mem.Allocator, array_str: []const u8) ![]co var it = std.mem.splitAny(u8, array_str[1 .. array_str.len - 1], " "); while (it.next()) |x| { + if (std.mem.eql(u8, " ", x) or std.mem.eql(u8, "", x)) continue; try array.append(parseTime(x)); } @@ -94,6 +99,7 @@ pub fn parseArrayTimeUnix(allocator: std.mem.Allocator, array_str: []const u8) ! var it = std.mem.splitAny(u8, array_str[1 .. array_str.len - 1], " "); while (it.next()) |x| { + if (std.mem.eql(u8, " ", x) or std.mem.eql(u8, "", x)) continue; try array.append(parseTime(x).toUnix()); } @@ -117,6 +123,7 @@ pub fn parseArrayDatetime(allocator: std.mem.Allocator, array_str: []const u8) ! var it = std.mem.splitAny(u8, array_str[1 .. array_str.len - 1], " "); while (it.next()) |x| { + if (std.mem.eql(u8, " ", x) or std.mem.eql(u8, "", x)) continue; try array.append(parseDatetime(x)); } @@ -128,6 +135,7 @@ pub fn parseArrayDatetimeUnix(allocator: std.mem.Allocator, array_str: []const u var it = std.mem.splitAny(u8, array_str[1 .. array_str.len - 1], " "); while (it.next()) |x| { + if (std.mem.eql(u8, " ", x) or std.mem.eql(u8, "", x)) continue; try array.append(parseDatetime(x).toUnix()); } @@ -139,6 +147,7 @@ pub fn parseArrayBool(allocator: std.mem.Allocator, array_str: []const u8) ![]co var it = std.mem.splitAny(u8, array_str[1 .. array_str.len - 1], " "); while (it.next()) |x| { + if (std.mem.eql(u8, " ", x) or std.mem.eql(u8, "", x)) continue; try array.append(parseBool(x)); } @@ -150,6 +159,7 @@ pub fn parseArrayUUID(allocator: std.mem.Allocator, array_str: []const u8) ![]co var it = std.mem.splitAny(u8, array_str[1 .. array_str.len - 1], " "); while (it.next()) |x| { + if (std.mem.eql(u8, " ", x) or std.mem.eql(u8, "", x)) continue; const uuid = try UUID.parse(x); try array.append(uuid); } @@ -162,6 +172,7 @@ pub fn parseArrayUUIDBytes(allocator: std.mem.Allocator, array_str: []const u8) var it = std.mem.splitAny(u8, array_str[1 .. array_str.len - 1], " "); while (it.next()) |x| { + if (std.mem.eql(u8, " ", x) or std.mem.eql(u8, "", x)) continue; const uuid = try UUID.parse(x); try array.append(uuid.bytes); } @@ -176,7 +187,7 @@ pub fn parseArrayStr(allocator: std.mem.Allocator, array_str: []const u8) ![]con var it = std.mem.splitAny(u8, array_str[1 .. array_str.len - 1], "'"); _ = it.next(); // SSkip first token that is empty while (it.next()) |x| { - if (std.mem.eql(u8, " ", x)) continue; + if (std.mem.eql(u8, " ", x) or std.mem.eql(u8, "", x)) continue; try array.append(x); } diff --git a/src/ziqlParser.zig b/src/ziqlParser.zig index 4d5602c..c15fae3 100644 --- a/src/ziqlParser.zig +++ b/src/ziqlParser.zig @@ -1068,6 +1068,7 @@ test "ADD" { // This need to take the first User named Bob as it is a unique link try testParsing("ADD User (name = 'Bob', email='bob@email.com', age=-55, scores=[ 1 ], best_friend=none, friends=none, bday=2000/01/01, a_time=12:04:54.8741, last_order=2000/01/01-12:45)"); try testParsing("ADD User (name = 'Bou', email='bob@email.com', age=66, scores=[ 1 ], best_friend={name = 'Boba'}, friends={name = 'Bob'}, bday=2000/01/01, a_time=02:04:54.8741, last_order=2000/01/01-12:45)"); + try testParsing("ADD User (name = 'Bobibou', email='bob@email.com', age=66, scores=[ 1 ], best_friend={name = 'Boba'}, friends=[1]{name = 'Bob'}, bday=2000/01/01, a_time=02:04:54.8741, last_order=2000/01/01-12:45)"); try testParsing("GRAB User {}"); } @@ -1111,7 +1112,8 @@ test "Specific query" { // TODO: next step is to make this work test "UPDATE relationship" { - try testParsing("UPDATE User [1] {} TO (best_friend = {name='Boba'} )"); + try testParsing("UPDATE User [1] {name='Bob'} TO (best_friend = {name='Boba'} )"); + try testParsing("GRAB User {}"); } // Not yet working but dont trow an error