| ... | @@ -84,16 +84,17 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype | ... | @@ -84,16 +84,17 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype |
| 84 | .block => |v| { | 84 | .block => |v| { |
| 85 | const body = astgen.Value{ .body = v.body }; | 85 | const body = astgen.Value{ .body = v.body }; |
| 86 | const bottom = astgen.Value{ .body = v.bttm }; | 86 | const bottom = astgen.Value{ .body = v.bttm }; |
| | 87 | 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); |
| | 88 | const T = @TypeOf(x); |
| | 89 | const TI = @typeInfo(T); |
| 87 | switch (v.name) { | 90 | switch (v.name) { |
| 88 | .each => { | 91 | .each => { |
| 89 | comptime assertEqual(v.args.len, 1); | 92 | comptime assertEqual(v.args.len, 1); |
| 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); | 93 | for (x) |item| try do(writer, body, item, ctx, indent, flag1); |
| 92 | }, | 94 | }, |
| 93 | .@"if" => { | 95 | .@"if" => { |
| 94 | comptime assertEqual(v.args.len, 1); | 96 | comptime assertEqual(v.args.len, 1); |
| 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); | 97 | switch (TI) { |
| 96 | switch (@typeInfo(@TypeOf(x))) { | | |
| 97 | .Bool => try doif(writer, body, bottom, data, ctx, indent, flag1, x, true), | 98 | .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), | 99 | .Optional => try docap(writer, body, bottom, data, ctx, indent, flag1, x, true), |
| 99 | else => unreachable, | 100 | else => unreachable, |
| ... | @@ -101,8 +102,7 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype | ... | @@ -101,8 +102,7 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype |
| 101 | }, | 102 | }, |
| 102 | .ifnot => { | 103 | .ifnot => { |
| 103 | comptime assertEqual(v.args.len, 1); | 104 | comptime assertEqual(v.args.len, 1); |
| 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 (TI) { |
| 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), |
| 108 | else => unreachable, | 108 | else => unreachable, |
| ... | @@ -110,13 +110,11 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype | ... | @@ -110,13 +110,11 @@ 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 = 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); | 113 | const y = search(v.args[1], data); |
| 115 | if (x == y) try do(writer, body, data, ctx, indent, flag1); | 114 | if (x == y) try do(writer, body, data, ctx, indent, flag1); |
| 116 | }, | 115 | }, |
| 117 | .ifnotequal => { | 116 | .ifnotequal => { |
| 118 | comptime assertEqual(v.args.len, 2); | 117 | comptime assertEqual(v.args.len, 2); |
| 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); | 118 | 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); | 119 | if (x != y) try do(writer, body, data, ctx, indent, flag1); |
| 122 | }, | 120 | }, |