| ... | ... | @@ -135,12 +135,25 @@ inline fn do(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.V |
| 135 | 135 | for (x) |item| try do(alloc, writer, body, item, ctx, opts); |
| 136 | 136 | }, |
| 137 | 137 | .@"if" => { |
| 138 | | comptime assertEqual(v.args.len, 1); |
| 139 | 138 | if (v.func) |n| { |
| 140 | | const x2 = try @field(opts.Ctx, "pek_" ++ n)(alloc, x); |
| 139 | const f = @field(opts.Ctx, "pek_" ++ n); |
| 140 | const x2 = try switch (@typeInfo(@TypeOf(f)).Fn.params.len) { |
| 141 | 2 => f(alloc, x), |
| 142 | 3 => blk: { |
| 143 | const y = resolveArg(v.args[1], data, ctx); |
| 144 | break :blk f(alloc, x, y); |
| 145 | }, |
| 146 | 4 => blk: { |
| 147 | const y = resolveArg(v.args[1], data, ctx); |
| 148 | const z = resolveArg(v.args[2], data, ctx); |
| 149 | break :blk f(alloc, x, y, z); |
| 150 | }, |
| 151 | else => unreachable, // TODO |
| 152 | }; |
| 141 | 153 | try doif(alloc, writer, body, bottom, data, ctx, opts, x2); |
| 142 | 154 | return; |
| 143 | 155 | } |
| 156 | comptime assertEqual(v.args.len, 1); |
| 144 | 157 | if (comptime std.meta.trait.isIndexable(T)) { |
| 145 | 158 | try doif(alloc, writer, body, bottom, data, ctx, opts, x.len > 0); |
| 146 | 159 | return; |
| ... | ... | @@ -152,12 +165,25 @@ inline fn do(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.V |
| 152 | 165 | } |
| 153 | 166 | }, |
| 154 | 167 | .ifnot => { |
| 155 | | comptime assertEqual(v.args.len, 1); |
| 156 | 168 | if (v.func) |n| { |
| 157 | | const x2 = try @field(opts.Ctx, "pek_" ++ n)(alloc, x); |
| 169 | const f = @field(opts.Ctx, "pek_" ++ n); |
| 170 | const x2 = try switch (@typeInfo(@TypeOf(f)).Fn.params.len) { |
| 171 | 2 => f(alloc, x), |
| 172 | 3 => blk: { |
| 173 | const y = resolveArg(v.args[1], data, ctx); |
| 174 | break :blk f(alloc, x, y); |
| 175 | }, |
| 176 | 4 => blk: { |
| 177 | const y = resolveArg(v.args[1], data, ctx); |
| 178 | const z = resolveArg(v.args[2], data, ctx); |
| 179 | break :blk f(alloc, x, y, z); |
| 180 | }, |
| 181 | else => unreachable, // TODO |
| 182 | }; |
| 158 | 183 | try doif(alloc, writer, body, bottom, data, ctx, opts, !x2); |
| 159 | 184 | return; |
| 160 | 185 | } |
| 186 | comptime assertEqual(v.args.len, 1); |
| 161 | 187 | switch (comptime TI) { |
| 162 | 188 | .Bool => try doif(alloc, writer, body, bottom, data, ctx, opts, !x), |
| 163 | 189 | .Optional => try docap(alloc, writer, body, bottom, data, ctx, opts, !x), |