authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-08-13 23:09:30 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-08-13 23:09:30 -07:00
log4b343f8f237d08317246c709e97ccc2962d12e69
treeba1602e171485fd50c45d20ae98f5c74ccb4abd8
parentbd42c8bd18acf1e5548140e7e1002fd3861b045d

allow referencing `this` in nested block helpers


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

src/lib.zig+6-6
......@@ -87,12 +87,12 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype
8787 switch (v.name) {
8888 .each => {
8989 comptime assertEqual(v.args.len, 1);
90 const x = search(v.args[0], data);
90 const x = if (comptime std.mem.eql(u8, v.args[0][0], "this")) search(v.args[0][1..], data) else search(v.args[0], ctx);
9191 for (x) |item| try do(writer, body, item, ctx, indent, flag1);
9292 },
9393 .@"if" => {
9494 comptime assertEqual(v.args.len, 1);
95 const x = search(v.args[0], data);
95 const x = if (comptime std.mem.eql(u8, v.args[0][0], "this")) search(v.args[0][1..], data) else search(v.args[0], ctx);
9696 switch (@typeInfo(@TypeOf(x))) {
9797 .Bool => try doif(writer, body, bottom, data, ctx, indent, flag1, x, true),
9898 .Optional => try docap(writer, body, bottom, data, ctx, indent, flag1, x, true),
......@@ -101,7 +101,7 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype
101101 },
102102 .ifnot => {
103103 comptime assertEqual(v.args.len, 1);
104 const x = search(v.args[0], data);
104 const x = if (comptime std.mem.eql(u8, v.args[0][0], "this")) search(v.args[0][1..], data) else search(v.args[0], ctx);
105105 switch (@typeInfo(@TypeOf(x))) {
106106 .Bool => try doif(writer, body, bottom, data, ctx, indent, flag1, x, false),
107107 .Optional => try docap(writer, body, bottom, data, ctx, indent, flag1, x, false),
......@@ -110,14 +110,14 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype
110110 },
111111 .ifequal => {
112112 comptime assertEqual(v.args.len, 2);
113 const x = search(v.args[0], data);
113 const x = if (comptime std.mem.eql(u8, v.args[0][0], "this")) search(v.args[0][1..], data) else search(v.args[0], ctx);
114114 const y = search(v.args[1], data);
115115 if (x == y) try do(writer, body, data, ctx, indent, flag1);
116116 },
117117 .ifnotequal => {
118118 comptime assertEqual(v.args.len, 2);
119 const x = search(v.args[0], data);
120 const y = search(v.args[1], data);
119 const x = if (comptime std.mem.eql(u8, v.args[0][0], "this")) search(v.args[0][1..], data) else search(v.args[0], ctx);
120 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);
121121 if (x != y) try do(writer, body, data, ctx, indent, flag1);
122122 },
123123 }