| ... | ... | @@ -94,16 +94,8 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype |
| 94 | 94 | comptime assertEqual(v.args.len, 1); |
| 95 | 95 | const x = search(v.args[0], data); |
| 96 | 96 | switch (@typeInfo(@TypeOf(x))) { |
| 97 | | .Bool => if (x) { |
| 98 | | try do(writer, body, data, ctx, indent, flag1); |
| 99 | | } else { |
| 100 | | try do(writer, bottom, data, ctx, indent, flag1); |
| 101 | | }, |
| 102 | | .Optional => if (x) |_| { |
| 103 | | try do(writer, body, data, ctx, indent, flag1); |
| 104 | | } else { |
| 105 | | try do(writer, bottom, data, ctx, indent, flag1); |
| 106 | | }, |
| 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), |
| 107 | 99 | else => unreachable, |
| 108 | 100 | } |
| 109 | 101 | }, |
| ... | ... | @@ -111,16 +103,8 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype |
| 111 | 103 | comptime assertEqual(v.args.len, 1); |
| 112 | 104 | const x = search(v.args[0], data); |
| 113 | 105 | switch (@typeInfo(@TypeOf(x))) { |
| 114 | | .Bool => if (x) { |
| 115 | | try do(writer, bottom, data, ctx, indent, flag1); |
| 116 | | } else { |
| 117 | | try do(writer, body, data, ctx, indent, flag1); |
| 118 | | }, |
| 119 | | .Optional => if (x) |_| { |
| 120 | | try do(writer, bottom, data, ctx, indent, flag1); |
| 121 | | } else { |
| 122 | | try do(writer, body, data, ctx, indent, flag1); |
| 123 | | }, |
| 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), |
| 124 | 108 | else => unreachable, |
| 125 | 109 | } |
| 126 | 110 | }, |
| ... | ... | @@ -209,3 +193,19 @@ fn contains(haystack: []const []const u8, needle: []const u8) bool { |
| 209 | 193 | } |
| 210 | 194 | return false; |
| 211 | 195 | } |
| 196 | |
| 197 | fn doif(writer: anytype, comptime top: astgen.Value, comptime bottom: astgen.Value, data: anytype, ctx: anytype, indent: usize, flag1: bool, flag2: bool, flag3: bool) anyerror!void { |
| 198 | if (flag2 == flag3) { |
| 199 | try do(writer, top, data, ctx, indent, flag1); |
| 200 | } else { |
| 201 | try do(writer, bottom, data, ctx, indent, flag1); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | fn docap(writer: anytype, comptime top: astgen.Value, comptime bottom: astgen.Value, data: anytype, ctx: anytype, indent: usize, flag1: bool, flag2: bool, flag3: bool) anyerror!void { |
| 206 | if (flag2 == flag3) { |
| 207 | try do(writer, top, data, ctx, indent, flag1); |
| 208 | } else { |
| 209 | try do(writer, bottom, data, ctx, indent, flag1); |
| 210 | } |
| 211 | } |