authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-08-14 16:56:21 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-08-14 16:56:21 -07:00
log089c19bcf6051fde10e69b458d68c2ac79c6e49b
tree92fc899b1dd6f9ea7d85292161e9e28f385d82a9
parentba4a1369104d2ea073b4e62973a814e0d80c0cad

allow passing just `this` as the args to a replacement


1 files changed, 2 insertions(+), 1 deletions(-)

src/lib.zig+2-1
...@@ -164,13 +164,14 @@ fn do(alloc: *std.mem.Allocator, writer: anytype, comptime value: astgen.Value,...@@ -164,13 +164,14 @@ fn do(alloc: *std.mem.Allocator, writer: anytype, comptime value: astgen.Value,
164}164}
165165
166fn search(comptime args: []const []const u8, ctx: anytype) FieldSearch(@TypeOf(ctx), args) {166fn search(comptime args: []const []const u8, ctx: anytype) FieldSearch(@TypeOf(ctx), args) {
167 if (args.len == 0) return ctx;
167 const f = @field(ctx, args[0]);168 const f = @field(ctx, args[0]);
168 if (args.len == 1) return f;169 if (args.len == 1) return f;
169 return search(args[1..], f);170 return search(args[1..], f);
170}171}
171172
172fn FieldSearch(comptime T: type, comptime args: []const []const u8) type {173fn FieldSearch(comptime T: type, comptime args: []const []const u8) type {
173 return if (args.len == 1) Field(T, args[0]) else FieldSearch(Field(T, args[0]), args[1..]);174 return if (args.len == 0) T else if (args.len == 1) Field(T, args[0]) else FieldSearch(Field(T, args[0]), args[1..]);
174}175}
175176
176fn Field(comptime T: type, comptime field_name: []const u8) type {177fn Field(comptime T: type, comptime field_name: []const u8) type {