diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2026-04-18 13:58:30 +0200 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2026-04-18 13:58:56 +0200 |
| commit | 08fc9545420b6cc11002cd8a82896881d0793aac (patch) | |
| tree | 80a918b8213f04a0312c513b9a360212837ad012 /src/lexer | |
| parent | 87e5daf9156583072d9ccb9ff0fa074f65fa6836 (diff) | |
Revert "style(): rename alloc into gpa"
This reverts commit 87e5daf9156583072d9ccb9ff0fa074f65fa6836.
Diffstat (limited to 'src/lexer')
| -rw-r--r-- | src/lexer/Lexed.zig | 12 | ||||
| -rw-r--r-- | src/lexer/Lexer.zig | 28 |
2 files changed, 20 insertions, 20 deletions
diff --git a/src/lexer/Lexed.zig b/src/lexer/Lexed.zig index 2ce6913..b7c3b2c 100644 --- a/src/lexer/Lexed.zig +++ b/src/lexer/Lexed.zig @@ -21,26 +21,26 @@ pub const Kind = enum { tag, }; -gpa: Allocator, +allocator: Allocator, kind: Kind, content: std.ArrayList(u8), const Self = @This(); -pub fn init(gpa: Allocator, kind: Kind, content: std.ArrayList(u8)) Self { +pub fn init(alloc: Allocator, kind: Kind, content: std.ArrayList(u8)) Self { return .{ - .gpa = gpa, + .allocator = alloc, .kind = kind, .content = content, }; } pub fn deinit(self: *Self) void { - self.content.deinit(self.gpa); + self.content.deinit(self.allocator); } -pub fn clone(self: *const Self, gpa: Allocator) Allocator.Error!std.ArrayList(u8) { - return self.content.clone(gpa); +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 { diff --git a/src/lexer/Lexer.zig b/src/lexer/Lexer.zig index 2ccc065..2705347 100644 --- a/src/lexer/Lexer.zig +++ b/src/lexer/Lexer.zig @@ -18,9 +18,9 @@ pub fn init(content: []const u8) Error!Self { return .{ .iter = view.iterator() }; } -pub fn next(self: *Self, gpa: Allocator) Error!?Lexed { - var acc = try std.ArrayList(u8).initCapacity(gpa, 2); - errdefer acc.deinit(gpa); +pub fn next(self: *Self, alloc: Allocator) Error!?Lexed { + var acc = try std.ArrayList(u8).initCapacity(alloc, 2); + errdefer acc.deinit(alloc); var current_kind: ?Lexed.Kind = null; while (self.iter.nextCodepointSlice()) |rune| { @@ -35,7 +35,7 @@ pub fn next(self: *Self, gpa: Allocator) Error!?Lexed { const res = self.getCurrentKind(current_kind, rune, acc.items); current_kind = res.kind; override_if = res.override_if; - try acc.appendSlice(gpa, rune); + try acc.appendSlice(alloc, rune); } // conds here to avoid creating complex condition in while const next_rune = self.iter.peek(1); @@ -57,10 +57,10 @@ pub fn next(self: *Self, gpa: Allocator) Error!?Lexed { } } const kind = current_kind orelse { - acc.deinit(gpa); + acc.deinit(alloc); return null; }; - return .init(gpa, kind, acc); + return .init(alloc, kind, acc); } const kindRes = struct { @@ -149,8 +149,8 @@ fn requiresSpace(k: Lexed.Kind) bool { }; } -fn doTest(gpa: Allocator, l: *Self, k: Lexed.Kind, v: []const u8) !void { - var first = (try l.next(gpa)).?; +fn doTest(alloc: Allocator, l: *Self, k: Lexed.Kind, v: []const u8) !void { + var first = (try l.next(alloc)).?; defer first.deinit(); std.testing.expect(first.equals(k, v)) catch |err| { std.debug.print("{}({s})\n", .{ first.kind, first.content.items }); @@ -178,14 +178,14 @@ test "lexer common" { var arena = std.heap.DebugAllocator(.{}).init; defer _ = arena.deinit(); - const gpa = arena.allocator(); + const alloc = arena.allocator(); var l = try init("# hello world :)"); - try doTest(gpa, &l, .title, "#"); - try doTest(gpa, &l, .literal, "hello world "); - try doTest(gpa, &l, .ref, ":"); - try doTest(gpa, &l, .link, ")"); + try doTest(alloc, &l, .title, "#"); + try doTest(alloc, &l, .literal, "hello world "); + try doTest(alloc, &l, .ref, ":"); + try doTest(alloc, &l, .link, ")"); - try expect(try l.next(gpa) == null); + try expect(try l.next(alloc) == null); } |
