authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-08-23 00:22:55 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-08-23 00:22:55 -07:00
log3452a56e84fb1972e799e0b539a1b2e06bd6fa28
treee579b15b3f700a5ede076978085e92b2fd588aad
parentfd7533f6dad7cb1f6d390d3485a3d0ab832dc5d3

allow checking enum tag in `#ifequal` and `#ifnotequal`


1 files changed, 6 insertions(+), 0 deletions(-)

src/lib.zig+6
......@@ -124,11 +124,17 @@ fn do(alloc: *std.mem.Allocator, writer: anytype, comptime value: astgen.Value,
124124 .ifequal => {
125125 comptime assertEqual(v.args.len, 2);
126126 const y = if (comptime std.mem.eql(u8, v.args[1][0], "this")) search(v.args[1][1..], data) else search(v.args[1], ctx);
127 if (@typeInfo(@TypeOf(x)) == .Enum and comptime std.meta.trait.isZigString(@TypeOf(y))) {
128 return try doif(alloc, writer, body, bottom, data, ctx, indent, flag1, std.mem.eql(u8, @tagName(x), y));
129 }
127130 try doif(alloc, writer, body, bottom, data, ctx, indent, flag1, x == y);
128131 },
129132 .ifnotequal => {
130133 comptime assertEqual(v.args.len, 2);
131134 const y = if (comptime std.mem.eql(u8, v.args[1][0], "this")) search(v.args[1][1..], data) else search(v.args[1], ctx);
135 if (@typeInfo(@TypeOf(x)) == .Enum and comptime std.meta.trait.isZigString(@TypeOf(y))) {
136 return try doif(alloc, writer, body, bottom, data, ctx, indent, flag1, std.mem.eql(u8, @tagName(x), y));
137 }
132138 try doif(alloc, writer, body, bottom, data, ctx, indent, flag1, x != y);
133139 },
134140 }