| ... | @@ -14,7 +14,7 @@ const tokenize = @import("./tokenize.zig"); | ... | @@ -14,7 +14,7 @@ const tokenize = @import("./tokenize.zig"); |
| 14 | const astgen = @import("./astgen.zig"); | 14 | const astgen = @import("./astgen.zig"); |
| 15 | | 15 | |
| 16 | pub fn parse(comptime input: []const u8) astgen.Value { | 16 | pub fn parse(comptime input: []const u8) astgen.Value { |
| 17 | return astgen.Value{ .element = astgen.do(tokenize.do(input, &.{ '[', '=', ']', '(', ')', '{', '}', '#', '/', '.' })) }; | 17 | return astgen.Value{ .element = astgen.do(tokenize.do(input, &.{ '[', '=', ']', '(', ')', '{', '}', '#', '/', '.', '<', '>' })) }; |
| 18 | } | 18 | } |
| 19 | | 19 | |
| 20 | pub fn compile(writer: anytype, comptime value: astgen.Value, data: anytype) !void { | 20 | pub fn compile(writer: anytype, comptime value: astgen.Value, data: anytype) !void { |
| ... | @@ -83,20 +83,22 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype | ... | @@ -83,20 +83,22 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype |
| 83 | .@"if" => { | 83 | .@"if" => { |
| 84 | comptime assertEqual(v.args.len, 1); | 84 | comptime assertEqual(v.args.len, 1); |
| 85 | const x = search(v.args[0], data); | 85 | const x = search(v.args[0], data); |
| 86 | switch (@typeInfo(@TypeOf(x))) { | 86 | const content = switch (@typeInfo(@TypeOf(x))) { |
| 87 | .Bool => if (x) try do(writer, body, data, ctx, indent, flag1), | 87 | .Bool => if (x) v.body else v.bttm, |
| 88 | .Optional => if (x) |_| try do(writer, body, data, ctx, indent, flag1), | 88 | .Optional => if (x) |_| v.body else v.bttm, |
| 89 | else => unreachable, | 89 | else => unreachable, |
| 90 | } | 90 | }; |
| | 91 | try do(writer, body, content, ctx, indent, flag1); |
| 91 | }, | 92 | }, |
| 92 | .ifnot => { | 93 | .ifnot => { |
| 93 | comptime assertEqual(v.args.len, 1); | 94 | comptime assertEqual(v.args.len, 1); |
| 94 | const x = search(v.args[0], data); | 95 | const x = search(v.args[0], data); |
| 95 | switch (@typeInfo(@TypeOf(x))) { | 96 | const content = switch (@typeInfo(@TypeOf(x))) { |
| 96 | .Bool => if (x) {} else try do(writer, body, data, ctx, indent, flag1), | 97 | .Bool => if (x) v.bttm else v.body, |
| 97 | .Optional => if (x) |_| {} else try do(writer, body, data, ctx, indent, flag1), | 98 | .Optional => if (x) |_| v.bttm else v.body, |
| 98 | else => unreachable, | 99 | else => unreachable, |
| 99 | } | 100 | }; |
| | 101 | try do(writer, body, content, ctx, indent, flag1); |
| 100 | }, | 102 | }, |
| 101 | .ifequal => { | 103 | .ifequal => { |
| 102 | comptime assertEqual(v.args.len, 2); | 104 | comptime assertEqual(v.args.len, 2); |