diff --git a/src/lib.zig b/src/lib.zig index 14cd77ca84fee0aaed0a267e39bda15296ae052f..7a5fecdd60c83e92afbe332a9028127c5f6dbb04 100644 --- a/src/lib.zig +++ b/src/lib.zig @@ -11,6 +11,7 @@ const std = @import("std"); const string = []const u8; const htmlentities = @import("htmlentities"); const root = @import("root"); +const tracer = @import("tracer"); const tokenize = @import("./tokenize.zig"); const astgen = @import("./astgen.zig"); @@ -20,6 +21,9 @@ pub fn parse(comptime input: string) astgen.Value { } pub fn compile(comptime Ctx: type, alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.Value, data: anytype) !void { + const t = tracer.trace(@src()); + defer t.end(); + try writer.writeAll("\n"); try do(alloc, writer, value, data, data, .{ .Ctx = Ctx, @@ -30,6 +34,9 @@ pub fn compile(comptime Ctx: type, alloc: std.mem.Allocator, writer: anytype, co } pub fn compileInner(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.Value, comptime opts: DoOptions, data: anytype) !void { + const t = tracer.trace(@src()); + defer t.end(); + try do(alloc, writer, value, data, data, opts); try writer.writeAll("\n"); } @@ -37,6 +44,9 @@ pub fn compileInner(alloc: std.mem.Allocator, writer: anytype, comptime value: a pub const Writer = std.ArrayList(u8).Writer; fn do(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype, comptime opts: DoOptions) anyerror!void { + const t = tracer.trace(@src()); + defer t.end(); + switch (comptime value) { .element => |v| { const hastext = comptime for (v.children) |x| { @@ -332,6 +342,9 @@ fn Field(comptime T: type, comptime field_name: string) type { } pub fn writeEscaped(s: string, writer: anytype) !void { + const t = tracer.trace(@src()); + defer t.end(); + const view = std.unicode.Utf8View.initUnchecked(s); var iter = view.iterator(); while (nextCodepointSliceLossy(&iter)) |sl| { @@ -414,6 +427,9 @@ fn contains(haystack: []const string, needle: string) bool { } fn doif(alloc: std.mem.Allocator, writer: anytype, comptime top: astgen.Value, comptime bottom: astgen.Value, data: anytype, ctx: anytype, comptime opts: DoOptions, flag2: bool) anyerror!void { + const t = tracer.trace(@src()); + defer t.end(); + if (flag2) { try do(alloc, writer, top, data, ctx, opts); } else { @@ -422,6 +438,9 @@ fn doif(alloc: std.mem.Allocator, writer: anytype, comptime top: astgen.Value, c } fn docap(alloc: std.mem.Allocator, writer: anytype, comptime top: astgen.Value, comptime bottom: astgen.Value, data: anytype, ctx: anytype, comptime opts: DoOptions, flag2: anytype) anyerror!void { + const t = tracer.trace(@src()); + defer t.end(); + if (flag2) |_| { try do(alloc, writer, top, data, ctx, opts); } else { diff --git a/zig.mod b/zig.mod index 99df6e038a5d483d14e8990d08d0b975db28321c..2c38cf8c2dd928622327dc9b6b8ea54028a0d822 100644 --- a/zig.mod +++ b/zig.mod @@ -6,3 +6,4 @@ description: An HTML preprocessor with a builtin template engine. dependencies: - src: git https://github.com/kivikakk/htmlentities.zig - src: git https://github.com/nektro/zig-extras + - src: git https://github.com/nektro/zig-tracer