diff --git a/src/astgen.zig b/src/astgen.zig index 51eecb097244819dffb789f9b46d3f8ade6007ed..38464245214f696d4612a50adbc91a21258ba982 100644 --- a/src/astgen.zig +++ b/src/astgen.zig @@ -34,6 +34,7 @@ pub const Replacement = struct { pub const Block = struct { name: Type, + func: ?string, args: []const []const string, body: Body, bttm: Body, @@ -151,6 +152,7 @@ const Parser = struct { std.debug.assert(w.len > 0); std.debug.assert(w[0] != '_'); if (std.meta.stringToEnum(Block.Type, w)) |name| { + const func = if (self.tryEatSymbol("#")) self.eat(.word) else null; const args = self.doArgs(); var children: []const Value = &.{}; var bottom: []const Value = &.{}; @@ -171,6 +173,7 @@ const Parser = struct { self.eatSymbol("/"); return Value{ .block = Block{ .name = name, + .func = func, .args = args, .body = children, .bttm = bottom, diff --git a/src/lib.zig b/src/lib.zig index bd218cfd86db59dcf41d2368e555521abb8e62b2..e5048a0e8ccbba8055fbe85e815d685f38d5c437 100644 --- a/src/lib.zig +++ b/src/lib.zig @@ -137,6 +137,11 @@ inline fn do(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.V }, .@"if" => { comptime assertEqual(v.args.len, 1); + if (v.func) |n| { + const x2 = try @field(opts.Ctx, "pek_" ++ n)(alloc, x); + try doif(alloc, writer, body, bottom, data, ctx, opts, x2); + return; + } if (comptime std.meta.trait.isIndexable(T)) { try doif(alloc, writer, body, bottom, data, ctx, opts, x.len > 0); return; @@ -149,6 +154,11 @@ inline fn do(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.V }, .ifnot => { comptime assertEqual(v.args.len, 1); + if (v.func) |n| { + const x2 = try @field(opts.Ctx, "pek_" ++ n)(alloc, x); + try doif(alloc, writer, body, bottom, data, ctx, opts, !x2); + return; + } switch (comptime TI) { .Bool => try doif(alloc, writer, body, bottom, data, ctx, opts, !x), .Optional => try docap(alloc, writer, body, bottom, data, ctx, opts, !x),