| author | |
| committer | |
| log | 08ae93da6fde7392d66bac2c34c4a4f530fe7696 |
| tree | 88ec00cbb9152b5fc5c8d845d7c195d2cf628eb5 |
| parent | 3dbac838d6bf37842a478d47e8fbdd15cddbde7a |
2 files changed, 13 insertions(+), 0 deletions(-)
src/astgen.zig+3| ... | ... | @@ -34,6 +34,7 @@ pub const Replacement = struct { |
| 34 | 34 | |
| 35 | 35 | pub const Block = struct { |
| 36 | 36 | name: Type, |
| 37 | func: ?string, | |
| 37 | 38 | args: []const []const string, |
| 38 | 39 | body: Body, |
| 39 | 40 | bttm: Body, |
| ... | ... | @@ -151,6 +152,7 @@ const Parser = struct { |
| 151 | 152 | std.debug.assert(w.len > 0); |
| 152 | 153 | std.debug.assert(w[0] != '_'); |
| 153 | 154 | if (std.meta.stringToEnum(Block.Type, w)) |name| { |
| 155 | const func = if (self.tryEatSymbol("#")) self.eat(.word) else null; | |
| 154 | 156 | const args = self.doArgs(); |
| 155 | 157 | var children: []const Value = &.{}; |
| 156 | 158 | var bottom: []const Value = &.{}; |
| ... | ... | @@ -171,6 +173,7 @@ const Parser = struct { |
| 171 | 173 | self.eatSymbol("/"); |
| 172 | 174 | return Value{ .block = Block{ |
| 173 | 175 | .name = name, |
| 176 | .func = func, | |
| 174 | 177 | .args = args, |
| 175 | 178 | .body = children, |
| 176 | 179 | .bttm = bottom, |
src/lib.zig+10| ... | ... | @@ -137,6 +137,11 @@ inline fn do(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.V |
| 137 | 137 | }, |
| 138 | 138 | .@"if" => { |
| 139 | 139 | comptime assertEqual(v.args.len, 1); |
| 140 | if (v.func) |n| { | |
| 141 | const x2 = try @field(opts.Ctx, "pek_" ++ n)(alloc, x); | |
| 142 | try doif(alloc, writer, body, bottom, data, ctx, opts, x2); | |
| 143 | return; | |
| 144 | } | |
| 140 | 145 | if (comptime std.meta.trait.isIndexable(T)) { |
| 141 | 146 | try doif(alloc, writer, body, bottom, data, ctx, opts, x.len > 0); |
| 142 | 147 | return; |
| ... | ... | @@ -149,6 +154,11 @@ inline fn do(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.V |
| 149 | 154 | }, |
| 150 | 155 | .ifnot => { |
| 151 | 156 | comptime assertEqual(v.args.len, 1); |
| 157 | if (v.func) |n| { | |
| 158 | const x2 = try @field(opts.Ctx, "pek_" ++ n)(alloc, x); | |
| 159 | try doif(alloc, writer, body, bottom, data, ctx, opts, !x2); | |
| 160 | return; | |
| 161 | } | |
| 152 | 162 | switch (comptime TI) { |
| 153 | 163 | .Bool => try doif(alloc, writer, body, bottom, data, ctx, opts, !x), |
| 154 | 164 | .Optional => try docap(alloc, writer, body, bottom, data, ctx, opts, !x), |