authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-09-20 19:31:06 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-09-20 19:31:06 -07:00
log642f1100f24f0bbab22fa458693870e33d40a3d1
treed7fea3b8bce4261408b1712c6031eb4e6fcdec6e
parent680b75544c8501bba5dad564945ac351c2bee9c0

add tracer calls


2 files changed, 20 insertions(+), 0 deletions(-)

src/lib.zig+19
......@@ -11,6 +11,7 @@ const std = @import("std");
1111const string = []const u8;
1212const htmlentities = @import("htmlentities");
1313const root = @import("root");
14const tracer = @import("tracer");
1415
1516const tokenize = @import("./tokenize.zig");
1617const astgen = @import("./astgen.zig");
......@@ -20,6 +21,9 @@ pub fn parse(comptime input: string) astgen.Value {
2021}
2122
2223pub fn compile(comptime Ctx: type, alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.Value, data: anytype) !void {
24 const t = tracer.trace(@src());
25 defer t.end();
26
2327 try writer.writeAll("<!DOCTYPE html>\n");
2428 try do(alloc, writer, value, data, data, .{
2529 .Ctx = Ctx,
......@@ -30,6 +34,9 @@ pub fn compile(comptime Ctx: type, alloc: std.mem.Allocator, writer: anytype, co
3034}
3135
3236pub fn compileInner(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.Value, comptime opts: DoOptions, data: anytype) !void {
37 const t = tracer.trace(@src());
38 defer t.end();
39
3340 try do(alloc, writer, value, data, data, opts);
3441 try writer.writeAll("\n");
3542}
......@@ -37,6 +44,9 @@ pub fn compileInner(alloc: std.mem.Allocator, writer: anytype, comptime value: a
3744pub const Writer = std.ArrayList(u8).Writer;
3845
3946fn do(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype, comptime opts: DoOptions) anyerror!void {
47 const t = tracer.trace(@src());
48 defer t.end();
49
4050 switch (comptime value) {
4151 .element => |v| {
4252 const hastext = comptime for (v.children) |x| {
......@@ -332,6 +342,9 @@ fn Field(comptime T: type, comptime field_name: string) type {
332342}
333343
334344pub fn writeEscaped(s: string, writer: anytype) !void {
345 const t = tracer.trace(@src());
346 defer t.end();
347
335348 const view = std.unicode.Utf8View.initUnchecked(s);
336349 var iter = view.iterator();
337350 while (nextCodepointSliceLossy(&iter)) |sl| {
......@@ -414,6 +427,9 @@ fn contains(haystack: []const string, needle: string) bool {
414427}
415428
416429fn 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 {
430 const t = tracer.trace(@src());
431 defer t.end();
432
417433 if (flag2) {
418434 try do(alloc, writer, top, data, ctx, opts);
419435 } else {
......@@ -422,6 +438,9 @@ fn doif(alloc: std.mem.Allocator, writer: anytype, comptime top: astgen.Value, c
422438}
423439
424440fn 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 {
441 const t = tracer.trace(@src());
442 defer t.end();
443
425444 if (flag2) |_| {
426445 try do(alloc, writer, top, data, ctx, opts);
427446 } else {
zig.mod+1
......@@ -6,3 +6,4 @@ description: An HTML preprocessor with a builtin template engine.
66dependencies:
77 - src: git https://github.com/kivikakk/htmlentities.zig
88 - src: git https://github.com/nektro/zig-extras
9 - src: git https://github.com/nektro/zig-tracer