diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-01-17 12:30:34 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-01-17 12:55:26 +0900 |
| commit | 22811834abe3603e28128a17ac004b1aeea3d651 (patch) | |
| tree | 071fb87406565a5950f9936dab4d94bb68b14eb6 /src/jq/tokenize.zig | |
| parent | 11b20173316188f511f24dc4121412097da7848d (diff) | |
| download | zgjq-22811834abe3603e28128a17ac004b1aeea3d651.tar.gz zgjq-22811834abe3603e28128a17ac004b1aeea3d651.tar.zst zgjq-22811834abe3603e28128a17ac004b1aeea3d651.zip | |
implement identity filter
Diffstat (limited to 'src/jq/tokenize.zig')
| -rw-r--r-- | src/jq/tokenize.zig | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/jq/tokenize.zig b/src/jq/tokenize.zig new file mode 100644 index 0000000..0823ea1 --- /dev/null +++ b/src/jq/tokenize.zig @@ -0,0 +1,33 @@ +const std = @import("std"); + +pub const TokenizeError = error{ + UnexpectedEnd, +}; + +pub const TokenKind = enum { + end, + identity, +}; + +pub const Token = struct { + kind: TokenKind, +}; + +pub fn tokenize(allocator: std.mem.Allocator, query: []const u8) ![]Token { + var tokens = try std.array_list.Aligned(Token, null).initCapacity(allocator, 16); + + const len = query.len; + var i: usize = 0; + while (i < len) { + const c = query[i]; + if (c == '.') { + try tokens.append(allocator, .{ .kind = .identity }); + } else { + return TokenizeError.UnexpectedEnd; + } + i += 1; + } + + try tokens.append(allocator, .{ .kind = .end }); + return tokens.toOwnedSlice(allocator); +} |
