| ... | ... | @@ -9,6 +9,7 @@ |
| 9 | 9 | const std = @import("std"); |
| 10 | 10 | const range = @import("range").range; |
| 11 | 11 | const htmlentities = @import("htmlentities"); |
| 12 | const root = @import("root"); |
| 12 | 13 | |
| 13 | 14 | const tokenize = @import("./tokenize.zig"); |
| 14 | 15 | const astgen = @import("./astgen.zig"); |
| ... | ... | @@ -134,6 +135,27 @@ fn do(alloc: *std.mem.Allocator, writer: anytype, comptime value: astgen.Value, |
| 134 | 135 | try do(alloc, writer, val, data, ctx, indent, flag1); |
| 135 | 136 | } |
| 136 | 137 | }, |
| 138 | .function => |v| { |
| 139 | if (@hasDecl(root, "pek_" ++ v.name)) { |
| 140 | const func = @field(root, "pek_" ++ v.name); |
| 141 | var args: FnArgsTuple(func) = undefined; |
| 142 | args.@"0" = alloc; |
| 143 | inline for (v.args) |arg, i| { |
| 144 | const field_name = comptime std.fmt.comptimePrint("{d}", .{i + 1}); |
| 145 | @field(args, field_name) = if (comptime std.mem.eql(u8, arg[0], "this")) search(arg[1..], data) else search(arg, ctx); |
| 146 | } |
| 147 | const s: []const u8 = try @call(.{}, func, args); |
| 148 | for (s) |c| { |
| 149 | if (entityLookupBefore(&[_]u8{c})) |ent| { |
| 150 | try writer.writeAll(ent.entity); |
| 151 | } else { |
| 152 | try writer.writeAll(&[_]u8{c}); |
| 153 | } |
| 154 | } |
| 155 | return; |
| 156 | } |
| 157 | @compileError("pek: unknown custom function: " ++ v.name); |
| 158 | }, |
| 137 | 159 | else => unreachable, |
| 138 | 160 | } |
| 139 | 161 | } |