summaryrefslogtreecommitdiff
path: root/src/config.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.zig')
-rw-r--r--src/config.zig21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/config.zig b/src/config.zig
index 50009660..8166954d 100644
--- a/src/config.zig
+++ b/src/config.zig
@@ -2170,10 +2170,12 @@ pub const User = struct {
defer gpa.free(one_path);
const bytes = try std.Io.Dir.cwd().readFileAlloc(io, one_path, gpa, .limited(4096));
defer gpa.free(bytes);
- const source = try gpa.dupeZ(u8, bytes);
+ const source = try gpa.dupeSentinel(u8, bytes, 0);
defer gpa.free(source);
- const parsed = try std.zon.parse.fromSliceAlloc(Sample, gpa, source, null, .{});
- defer std.zon.parse.free(gpa, parsed);
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ var diagnostics: std.zon.parse.Diagnostics = undefined;
+ const parsed = try std.zon.parse.fromSlice(Sample, .{ .gpa = gpa, .arena = arena.allocator(), .source = source, .diagnostics = &diagnostics });
try std.testing.expectEqualStrings("one", parsed.name);
try std.testing.expectEqual([3]u8{ 1, 2, 3 }, parsed.rgb);
}
@@ -2239,25 +2241,26 @@ const doc_typ = struct {
fn hasChordField(T: type) bool {
if (@typeInfo(T) != .array or @typeInfo(@typeInfo(T).array.child) != .@"struct") return false;
- for (@typeInfo(@typeInfo(T).array.child).@"struct".fields) |f| if (f.type == Chord) return true;
+ for (@typeInfo(@typeInfo(T).array.child).@"struct".field_types) |F| if (F == Chord) return true;
return false;
}
/// Bound somewhere in this file: a binding, a prefix or a key list.
fn bound(c: Chord) bool {
const config = @import("config.zig");
- inline for (@typeInfo(config).@"struct".decls) |d| {
- const v = @field(config, d.name);
+ inline for (@typeInfo(config).@"struct".decl_names) |d| {
+ const v = @field(config, d);
const T = @TypeOf(v);
if (T == []const Chord) {
for (v) |b| if (same(b, c)) return true;
} else if (T == comptime_int or T == u21 or T == u8) {
// a prefix or a bare key; only the tty toggle carries Ctrl
- const plain = !c.alt and !c.shift and (!c.ctrl or comptime std.mem.indexOf(u8, d.name, "toggle") != null);
+ const plain = !c.alt and !c.shift and (!c.ctrl or comptime std.mem.indexOf(u8, d, "toggle") != null);
if (plain and v >= 0x20 and v < 0x7f and v == c.cp) return true;
} else if (comptime hasChordField(T)) {
- for (v) |e| inline for (@typeInfo(@TypeOf(e)).@"struct".fields) |f|
- if (f.type == Chord and same(@field(e, f.name), c)) return true;
+ const info = @typeInfo(@TypeOf(v[0])).@"struct";
+ for (v) |e| inline for (info.field_names, info.field_types) |name, F|
+ if (F == Chord and same(@field(e, name), c)) return true;
}
}
return false;