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...@@ -87,12 +87,12 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype
87 switch (v.name) {87 switch (v.name) {
88 .each => {88 .each => {
89 comptime assertEqual(v.args.len, 1);89 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);
91 for (x) |item| try do(writer, body, item, ctx, indent, flag1);91 for (x) |item| try do(writer, body, item, ctx, indent, flag1);
92 },92 },
93 .@"if" => {93 .@"if" => {
94 comptime assertEqual(v.args.len, 1);94 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);
96 switch (@typeInfo(@TypeOf(x))) {96 switch (@typeInfo(@TypeOf(x))) {
97 .Bool => try doif(writer, body, bottom, data, ctx, indent, flag1, x, true),97 .Bool => try doif(writer, body, bottom, data, ctx, indent, flag1, x, true),
98 .Optional => try docap(writer, body, bottom, data, ctx, indent, flag1, x, true),98 .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...@@ -101,7 +101,7 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype
101 },101 },
102 .ifnot => {102 .ifnot => {
103 comptime assertEqual(v.args.len, 1);103 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);
105 switch (@typeInfo(@TypeOf(x))) {105 switch (@typeInfo(@TypeOf(x))) {
106 .Bool => try doif(writer, body, bottom, data, ctx, indent, flag1, x, false),106 .Bool => try doif(writer, body, bottom, data, ctx, indent, flag1, x, false),
107 .Optional => try docap(writer, body, bottom, data, ctx, indent, flag1, x, false),107 .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...@@ -110,14 +110,14 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype
110 },110 },
111 .ifequal => {111 .ifequal => {
112 comptime assertEqual(v.args.len, 2);112 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);
114 const y = search(v.args[1], data);114 const y = search(v.args[1], data);
115 if (x == y) try do(writer, body, data, ctx, indent, flag1);115 if (x == y) try do(writer, body, data, ctx, indent, flag1);
116 },116 },
117 .ifnotequal => {117 .ifnotequal => {
118 comptime assertEqual(v.args.len, 2);118 comptime assertEqual(v.args.len, 2);
119 const x = search(v.args[0], 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 = search(v.args[1], data);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);
121 if (x != y) try do(writer, body, data, ctx, indent, flag1);121 if (x != y) try do(writer, body, data, ctx, indent, flag1);
122 },122 },
123 }123 }