From 87e5daf9156583072d9ccb9ff0fa074f65fa6836 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Fri, 17 Apr 2026 18:07:11 +0200 Subject: style(): rename alloc into gpa --- src/lexer/Lexed.zig | 12 ++++++------ src/lexer/Lexer.zig | 28 ++++++++++++++-------------- 2 files changed, 20 insertions(+), 20 deletions(-) (limited to 'src/lexer') diff --git a/src/lexer/Lexed.zig b/src/lexer/Lexed.zig index b7c3b2c..2ce6913 100644 --- a/src/lexer/Lexed.zig +++ b/src/lexer/Lexed.zig @@ -21,26 +21,26 @@ pub const Kind = enum { tag, }; -allocator: Allocator, +gpa: Allocator, kind: Kind, content: std.ArrayList(u8), const Self = @This(); -pub fn init(alloc: Allocator, kind: Kind, content: std.ArrayList(u8)) Self { +pub fn init(gpa: Allocator, kind: Kind, content: std.ArrayList(u8)) Self { return .{ - .allocator = alloc, + .gpa = gpa, .kind = kind, .content = content, }; } pub fn deinit(self: *Self) void { - self.content.deinit(self.allocator); + self.content.deinit(self.gpa); } -pub fn clone(self: *const Self, alloc: Allocator) Allocator.Error!std.ArrayList(u8) { - return self.content.clone(alloc); +pub fn clone(self: *const Self, gpa: Allocator) Allocator.Error!std.ArrayList(u8) { + return self.content.clone(gpa); } 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 2705347..2ccc065 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, alloc: Allocator) Error!?Lexed { - var acc = try std.ArrayList(u8).initCapacity(alloc, 2); - errdefer acc.deinit(alloc); +pub fn next(self: *Self, gpa: Allocator) Error!?Lexed { + var acc = try std.ArrayList(u8).initCapacity(gpa, 2); + errdefer acc.deinit(gpa); var current_kind: ?Lexed.Kind = null; while (self.iter.nextCodepointSlice()) |rune| { @@ -35,7 +35,7 @@ pub fn next(self: *Self, alloc: Allocator) Error!?Lexed { const res = self.getCurrentKind(current_kind, rune, acc.items); current_kind = res.kind; override_if = res.override_if; - try acc.appendSlice(alloc, rune); + try acc.appendSlice(gpa, 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, alloc: Allocator) Error!?Lexed { } } const kind = current_kind orelse { - acc.deinit(alloc); + acc.deinit(gpa); return null; }; - return .init(alloc, kind, acc); + return .init(gpa, kind, acc); } const kindRes = struct { @@ -149,8 +149,8 @@ fn requiresSpace(k: Lexed.Kind) bool { }; } -fn doTest(alloc: Allocator, l: *Self, k: Lexed.Kind, v: []const u8) !void { - var first = (try l.next(alloc)).?; +fn doTest(gpa: Allocator, l: *Self, k: Lexed.Kind, v: []const u8) !void { + var first = (try l.next(gpa)).?; 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 alloc = arena.allocator(); + const gpa = arena.allocator(); var l = try init("# hello world :)"); - try doTest(alloc, &l, .title, "#"); - try doTest(alloc, &l, .literal, "hello world "); - try doTest(alloc, &l, .ref, ":"); - try doTest(alloc, &l, .link, ")"); + try doTest(gpa, &l, .title, "#"); + try doTest(gpa, &l, .literal, "hello world "); + try doTest(gpa, &l, .ref, ":"); + try doTest(gpa, &l, .link, ")"); - try expect(try l.next(alloc) == null); + try expect(try l.next(gpa) == null); } -- cgit v1.2.3