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...@@ -74,6 +74,7 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype
74 },74 },
75 .block => |v| {75 .block => |v| {
76 const body = astgen.Value{ .body = v.body };76 const body = astgen.Value{ .body = v.body };
77 const bottom = astgen.Value{ .body = v.bttm };
77 switch (v.name) {78 switch (v.name) {
78 .each => {79 .each => {
79 comptime assertEqual(v.args.len, 1);80 comptime assertEqual(v.args.len, 1);
...@@ -83,22 +84,36 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype...@@ -83,22 +84,36 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype
83 .@"if" => {84 .@"if" => {
84 comptime assertEqual(v.args.len, 1);85 comptime assertEqual(v.args.len, 1);
85 const x = search(v.args[0], data);86 const x = search(v.args[0], data);
86 const content = switch (@typeInfo(@TypeOf(x))) {87 switch (@typeInfo(@TypeOf(x))) {
87 .Bool => if (x) v.body else v.bttm,88 .Bool => if (x) {
88 .Optional => if (x) |_| v.body else v.bttm,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 },
89 else => unreachable,98 else => unreachable,
90 };99 }
91 try do(writer, body, content, ctx, indent, flag1);
92 },100 },
93 .ifnot => {101 .ifnot => {
94 comptime assertEqual(v.args.len, 1);102 comptime assertEqual(v.args.len, 1);
95 const x = search(v.args[0], data);103 const x = search(v.args[0], data);
96 const content = switch (@typeInfo(@TypeOf(x))) {104 switch (@typeInfo(@TypeOf(x))) {
97 .Bool => if (x) v.bttm else v.body,105 .Bool => if (x) {
98 .Optional => if (x) |_| v.bttm else v.body,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 },
99 else => unreachable,115 else => unreachable,
100 };116 }
101 try do(writer, body, content, ctx, indent, flag1);
102 },117 },
103 .ifequal => {118 .ifequal => {
104 comptime assertEqual(v.args.len, 2);119 comptime assertEqual(v.args.len, 2);