diff options
| author | 2022-01-01 04:04:46 +0100 | |
|---|---|---|
| committer | 2022-01-02 13:44:40 +0100 | |
| commit | dd815d06920fead10d1315e86e974be8ac22f172 (patch) | |
| tree | 2c8ab7449890077d149fb96c0bee268d17e5de3f /query.zig | |
| parent | query: remove identifier from BindMarker (diff) | |
| download | zig-sqlite-dd815d06920fead10d1315e86e974be8ac22f172.tar.gz zig-sqlite-dd815d06920fead10d1315e86e974be8ac22f172.tar.xz zig-sqlite-dd815d06920fead10d1315e86e974be8ac22f172.zip | |
query: use snake_case for the states for consistency
Diffstat (limited to '')
| -rw-r--r-- | query.zig | 36 |
1 files changed, 18 insertions, 18 deletions
| @@ -27,7 +27,7 @@ pub const ParsedQuery = struct { | |||
| 27 | pub fn from(comptime query: []const u8) Self { | 27 | pub fn from(comptime query: []const u8) Self { |
| 28 | comptime var buf: [query.len]u8 = undefined; | 28 | comptime var buf: [query.len]u8 = undefined; |
| 29 | comptime var pos = 0; | 29 | comptime var pos = 0; |
| 30 | comptime var state = .Start; | 30 | comptime var state = .start; |
| 31 | 31 | ||
| 32 | comptime var current_bind_marker_type: [256]u8 = undefined; | 32 | comptime var current_bind_marker_type: [256]u8 = undefined; |
| 33 | comptime var current_bind_marker_type_pos = 0; | 33 | comptime var current_bind_marker_type_pos = 0; |
| @@ -40,17 +40,17 @@ pub const ParsedQuery = struct { | |||
| 40 | 40 | ||
| 41 | inline for (query) |c| { | 41 | inline for (query) |c| { |
| 42 | switch (state) { | 42 | switch (state) { |
| 43 | .Start => switch (c) { | 43 | .start => switch (c) { |
| 44 | '?', ':', '@', '$' => { | 44 | '?', ':', '@', '$' => { |
| 45 | parsed_query.bind_markers[parsed_query.nb_bind_markers] = BindMarker{}; | 45 | parsed_query.bind_markers[parsed_query.nb_bind_markers] = BindMarker{}; |
| 46 | current_bind_marker_type_pos = 0; | 46 | current_bind_marker_type_pos = 0; |
| 47 | current_bind_marker_id_pos = 0; | 47 | current_bind_marker_id_pos = 0; |
| 48 | state = .BindMarker; | 48 | state = .bind_marker; |
| 49 | buf[pos] = c; | 49 | buf[pos] = c; |
| 50 | pos += 1; | 50 | pos += 1; |
| 51 | }, | 51 | }, |
| 52 | '\'', '"' => { | 52 | '\'', '"' => { |
| 53 | state = .InsideString; | 53 | state = .inside_string; |
| 54 | buf[pos] = c; | 54 | buf[pos] = c; |
| 55 | pos += 1; | 55 | pos += 1; |
| 56 | }, | 56 | }, |
| @@ -59,9 +59,9 @@ pub const ParsedQuery = struct { | |||
| 59 | pos += 1; | 59 | pos += 1; |
| 60 | }, | 60 | }, |
| 61 | }, | 61 | }, |
| 62 | .InsideString => switch (c) { | 62 | .inside_string => switch (c) { |
| 63 | '\'', '"' => { | 63 | '\'', '"' => { |
| 64 | state = .Start; | 64 | state = .start; |
| 65 | buf[pos] = c; | 65 | buf[pos] = c; |
| 66 | pos += 1; | 66 | pos += 1; |
| 67 | }, | 67 | }, |
| @@ -70,19 +70,19 @@ pub const ParsedQuery = struct { | |||
| 70 | pos += 1; | 70 | pos += 1; |
| 71 | }, | 71 | }, |
| 72 | }, | 72 | }, |
| 73 | .BindMarker => switch (c) { | 73 | .bind_marker => switch (c) { |
| 74 | '?', ':', '@', '$' => @compileError("invalid multiple '?', ':', '$' or '@'."), | 74 | '?', ':', '@', '$' => @compileError("invalid multiple '?', ':', '$' or '@'."), |
| 75 | '{' => { | 75 | '{' => { |
| 76 | state = .BindMarkerType; | 76 | state = .bind_marker_type; |
| 77 | }, | 77 | }, |
| 78 | else => { | 78 | else => { |
| 79 | if (std.ascii.isAlpha(c) or std.ascii.isDigit(c)) { | 79 | if (std.ascii.isAlpha(c) or std.ascii.isDigit(c)) { |
| 80 | state = .BindMarkerIdentifier; | 80 | state = .bind_marker_identifier; |
| 81 | current_bind_marker_id[current_bind_marker_id_pos] = c; | 81 | current_bind_marker_id[current_bind_marker_id_pos] = c; |
| 82 | current_bind_marker_id_pos += 1; | 82 | current_bind_marker_id_pos += 1; |
| 83 | } else { | 83 | } else { |
| 84 | // This is a bind marker without a type. | 84 | // This is a bind marker without a type. |
| 85 | state = .Start; | 85 | state = .start; |
| 86 | 86 | ||
| 87 | parsed_query.bind_markers[parsed_query.nb_bind_markers].typed = null; | 87 | parsed_query.bind_markers[parsed_query.nb_bind_markers].typed = null; |
| 88 | parsed_query.nb_bind_markers += 1; | 88 | parsed_query.nb_bind_markers += 1; |
| @@ -91,10 +91,10 @@ pub const ParsedQuery = struct { | |||
| 91 | pos += 1; | 91 | pos += 1; |
| 92 | }, | 92 | }, |
| 93 | }, | 93 | }, |
| 94 | .BindMarkerIdentifier => switch (c) { | 94 | .bind_marker_identifier => switch (c) { |
| 95 | '?', ':', '@', '$' => @compileError("unregconised multiple '?', ':', '$' or '@'."), | 95 | '?', ':', '@', '$' => @compileError("unregconised multiple '?', ':', '$' or '@'."), |
| 96 | '{' => { | 96 | '{' => { |
| 97 | state = .BindMarkerType; | 97 | state = .bind_marker_type; |
| 98 | current_bind_marker_type_pos = 0; | 98 | current_bind_marker_type_pos = 0; |
| 99 | }, | 99 | }, |
| 100 | else => { | 100 | else => { |
| @@ -102,7 +102,7 @@ pub const ParsedQuery = struct { | |||
| 102 | current_bind_marker_id[current_bind_marker_id_pos] = c; | 102 | current_bind_marker_id[current_bind_marker_id_pos] = c; |
| 103 | current_bind_marker_id_pos += 1; | 103 | current_bind_marker_id_pos += 1; |
| 104 | } else { | 104 | } else { |
| 105 | state = .Start; | 105 | state = .start; |
| 106 | if (current_bind_marker_id_pos > 0) { | 106 | if (current_bind_marker_id_pos > 0) { |
| 107 | parsed_query.nb_bind_markers += 1; | 107 | parsed_query.nb_bind_markers += 1; |
| 108 | } | 108 | } |
| @@ -111,9 +111,9 @@ pub const ParsedQuery = struct { | |||
| 111 | pos += 1; | 111 | pos += 1; |
| 112 | }, | 112 | }, |
| 113 | }, | 113 | }, |
| 114 | .BindMarkerType => switch (c) { | 114 | .bind_marker_type => switch (c) { |
| 115 | '}' => { | 115 | '}' => { |
| 116 | state = .Start; | 116 | state = .start; |
| 117 | 117 | ||
| 118 | const typ = parseType(current_bind_marker_type[0..current_bind_marker_type_pos]); | 118 | const typ = parseType(current_bind_marker_type[0..current_bind_marker_type_pos]); |
| 119 | 119 | ||
| @@ -133,14 +133,14 @@ pub const ParsedQuery = struct { | |||
| 133 | 133 | ||
| 134 | // The last character was ? so this must be an untyped bind marker. | 134 | // The last character was ? so this must be an untyped bind marker. |
| 135 | switch (state) { | 135 | switch (state) { |
| 136 | .BindMarker => { | 136 | .bind_marker => { |
| 137 | parsed_query.bind_markers[parsed_query.nb_bind_markers].typed = null; | 137 | parsed_query.bind_markers[parsed_query.nb_bind_markers].typed = null; |
| 138 | parsed_query.nb_bind_markers += 1; | 138 | parsed_query.nb_bind_markers += 1; |
| 139 | }, | 139 | }, |
| 140 | .BindMarkerIdentifier => { | 140 | .bind_marker_identifier => { |
| 141 | parsed_query.nb_bind_markers += 1; | 141 | parsed_query.nb_bind_markers += 1; |
| 142 | }, | 142 | }, |
| 143 | .Start => {}, | 143 | .start => {}, |
| 144 | else => @compileError("invalid final state " ++ @tagName(state) ++ ", this means you wrote an incomplete bind marker type"), | 144 | else => @compileError("invalid final state " ++ @tagName(state) ++ ", this means you wrote an incomplete bind marker type"), |
| 145 | } | 145 | } |
| 146 | 146 | ||