aboutsummaryrefslogtreecommitdiff
path: root/src/lexer/lexed.zig
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2026-04-15 12:48:54 +0200
committerAnhgelus Morhtuuzh <william@herges.fr>2026-04-15 12:48:54 +0200
commitde077d10359a3bed5259b766c37c94c1d7678a2b (patch)
tree27a948b0c576480ecafa3c28d77408eae07da46c /src/lexer/lexed.zig
parenta432d44d035508da5e0e67fde2327eaf1a41f382 (diff)
feat(lexer): simple separator
Diffstat (limited to 'src/lexer/lexed.zig')
-rw-r--r--src/lexer/lexed.zig47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/lexer/lexed.zig b/src/lexer/lexed.zig
new file mode 100644
index 0000000..3134705
--- /dev/null
+++ b/src/lexer/lexed.zig
@@ -0,0 +1,47 @@
+const std = @import("std");
+const Allocator = std.mem.Allocator;
+
+pub const Kind = enum {
+ literal,
+ delimiter,
+ operator,
+
+ const Self = @This();
+
+ pub fn string(self: *Self) []const u8 {
+ switch (*self) {
+ .literal => return "literal",
+ .delimiter => return "delimiter",
+ .operator => return "operator",
+ }
+ }
+};
+
+pub const Lexed = struct {
+ allocator: Allocator,
+ kind: Kind,
+ content: std.ArrayList(u8),
+
+ const Self = @This();
+
+ pub fn init(alloc: Allocator, kind: Kind, content: std.ArrayList(u8)) Lexed {
+ return Lexed{
+ .allocator = alloc,
+ .kind = kind,
+ .content = content,
+ };
+ }
+
+ pub fn deinit(self: *Self) void {
+ self.content.deinit(self.allocator);
+ }
+
+ pub fn clone(self: *const Self, alloc: Allocator) Allocator.Error!std.ArrayList(u8) {
+ return self.content.clone(alloc);
+ }
+
+ pub fn equals(self: *const Self, kind: Kind, content: []const u8) bool {
+ if (self.kind != kind) return false;
+ return std.mem.eql(u8, self.content.items, content);
+ }
+};