From 58c92dce9e4e81373ec0d8c0668b09697338e653 Mon Sep 17 00:00:00 2001 From: Vincent Rischmann Date: Tue, 3 May 2022 00:24:40 +0200 Subject: allow parsing optional types in bind marker types --- query.zig | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'query.zig') diff --git a/query.zig b/query.zig index 45577a1..70ffde7 100644 --- a/query.zig +++ b/query.zig @@ -112,7 +112,18 @@ pub const ParsedQuery = struct { '}' => { state = .start; - const typ = parseType(current_bind_marker_type[0..current_bind_marker_type_pos]); + const type_info_string = current_bind_marker_type[0..current_bind_marker_type_pos]; + // Handles optional types + const typ = if (type_info_string[0] == '?') blk: { + const child_type = parseType(type_info_string[1..]); + break :blk @Type(std.builtin.TypeInfo{ + .Optional = .{ + .child = child_type, + }, + }); + } else blk: { + break :blk parseType(type_info_string); + }; parsed_query.bind_markers[parsed_query.nb_bind_markers].typed = typ; parsed_query.nb_bind_markers += 1; @@ -252,6 +263,10 @@ test "parsed query: bind markers types" { .query = "foobar " ++ prefix, .expected_marker = .{ .typed = null }, }, + .{ + .query = "foobar " ++ prefix ++ "{?[]const u8}", + .expected_marker = .{ .typed = ?[]const u8 }, + }, }; inline for (testCases) |tc| { -- cgit v1.2.3