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,...@@ -124,11 +124,17 @@ fn do(alloc: *std.mem.Allocator, writer: anytype, comptime value: astgen.Value,
124 .ifequal => {124 .ifequal => {
125 comptime assertEqual(v.args.len, 2);125 comptime assertEqual(v.args.len, 2);
126 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);126 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 }
127 try doif(alloc, writer, body, bottom, data, ctx, indent, flag1, x == y);130 try doif(alloc, writer, body, bottom, data, ctx, indent, flag1, x == y);
128 },131 },
129 .ifnotequal => {132 .ifnotequal => {
130 comptime assertEqual(v.args.len, 2);133 comptime assertEqual(v.args.len, 2);
131 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);134 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 }
132 try doif(alloc, writer, body, bottom, data, ctx, indent, flag1, x != y);138 try doif(alloc, writer, body, bottom, data, ctx, indent, flag1, x != y);
133 },139 },
134 }140 }