authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-08-08 22:13:34 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-08-08 22:13:34 -07:00
logbcb022592b5751ff9acd5b9ac18d0dfea8fe447f
tree1aeb54a6c2915e2c66993339f5ccafdad360c2de
parent10eb03e0c2a8597754a05f56c6b511f97c714a6a

fix if/else handling


1 files changed, 25 insertions(+), 10 deletions(-)

src/lib.zig+25-10
......@@ -74,6 +74,7 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype
7474 },
7575 .block => |v| {
7676 const body = astgen.Value{ .body = v.body };
77 const bottom = astgen.Value{ .body = v.bttm };
7778 switch (v.name) {
7879 .each => {
7980 comptime assertEqual(v.args.len, 1);
......@@ -83,22 +84,36 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype
8384 .@"if" => {
8485 comptime assertEqual(v.args.len, 1);
8586 const x = search(v.args[0], data);
86 const content = switch (@typeInfo(@TypeOf(x))) {
87 .Bool => if (x) v.body else v.bttm,
88 .Optional => if (x) |_| v.body else v.bttm,
87 switch (@typeInfo(@TypeOf(x))) {
88 .Bool => if (x) {
89 try do(writer, body, data, ctx, indent, flag1);
90 } else {
91 try do(writer, bottom, data, ctx, indent, flag1);
92 },
93 .Optional => if (x) |_| {
94 try do(writer, body, data, ctx, indent, flag1);
95 } else {
96 try do(writer, bottom, data, ctx, indent, flag1);
97 },
8998 else => unreachable,
90 };
91 try do(writer, body, content, ctx, indent, flag1);
99 }
92100 },
93101 .ifnot => {
94102 comptime assertEqual(v.args.len, 1);
95103 const x = search(v.args[0], data);
96 const content = switch (@typeInfo(@TypeOf(x))) {
97 .Bool => if (x) v.bttm else v.body,
98 .Optional => if (x) |_| v.bttm else v.body,
104 switch (@typeInfo(@TypeOf(x))) {
105 .Bool => if (x) {
106 try do(writer, bottom, data, ctx, indent, flag1);
107 } else {
108 try do(writer, body, data, ctx, indent, flag1);
109 },
110 .Optional => if (x) |_| {
111 try do(writer, bottom, data, ctx, indent, flag1);
112 } else {
113 try do(writer, body, data, ctx, indent, flag1);
114 },
99115 else => unreachable,
100 };
101 try do(writer, body, content, ctx, indent, flag1);
116 }
102117 },
103118 .ifequal => {
104119 comptime assertEqual(v.args.len, 2);