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");...@@ -11,6 +11,7 @@ const std = @import("std");
11const string = []const u8;11const string = []const u8;
12const htmlentities = @import("htmlentities");12const htmlentities = @import("htmlentities");
13const root = @import("root");13const root = @import("root");
14const tracer = @import("tracer");
1415
15const tokenize = @import("./tokenize.zig");16const tokenize = @import("./tokenize.zig");
16const astgen = @import("./astgen.zig");17const astgen = @import("./astgen.zig");
...@@ -20,6 +21,9 @@ pub fn parse(comptime input: string) astgen.Value {...@@ -20,6 +21,9 @@ pub fn parse(comptime input: string) astgen.Value {
20}21}
2122
22pub fn compile(comptime Ctx: type, alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.Value, data: anytype) !void {23pub 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
23 try writer.writeAll("<!DOCTYPE html>\n");27 try writer.writeAll("<!DOCTYPE html>\n");
24 try do(alloc, writer, value, data, data, .{28 try do(alloc, writer, value, data, data, .{
25 .Ctx = Ctx,29 .Ctx = Ctx,
...@@ -30,6 +34,9 @@ pub fn compile(comptime Ctx: type, alloc: std.mem.Allocator, writer: anytype, co...@@ -30,6 +34,9 @@ pub fn compile(comptime Ctx: type, alloc: std.mem.Allocator, writer: anytype, co
30}34}
3135
32pub fn compileInner(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.Value, comptime opts: DoOptions, data: anytype) !void {36pub 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
33 try do(alloc, writer, value, data, data, opts);40 try do(alloc, writer, value, data, data, opts);
34 try writer.writeAll("\n");41 try writer.writeAll("\n");
35}42}
...@@ -37,6 +44,9 @@ pub fn compileInner(alloc: std.mem.Allocator, writer: anytype, comptime value: a...@@ -37,6 +44,9 @@ pub fn compileInner(alloc: std.mem.Allocator, writer: anytype, comptime value: a
37pub const Writer = std.ArrayList(u8).Writer;44pub const Writer = std.ArrayList(u8).Writer;
3845
39fn do(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype, comptime opts: DoOptions) anyerror!void {46fn 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
40 switch (comptime value) {50 switch (comptime value) {
41 .element => |v| {51 .element => |v| {
42 const hastext = comptime for (v.children) |x| {52 const hastext = comptime for (v.children) |x| {
...@@ -332,6 +342,9 @@ fn Field(comptime T: type, comptime field_name: string) type {...@@ -332,6 +342,9 @@ fn Field(comptime T: type, comptime field_name: string) type {
332}342}
333343
334pub fn writeEscaped(s: string, writer: anytype) !void {344pub fn writeEscaped(s: string, writer: anytype) !void {
345 const t = tracer.trace(@src());
346 defer t.end();
347
335 const view = std.unicode.Utf8View.initUnchecked(s);348 const view = std.unicode.Utf8View.initUnchecked(s);
336 var iter = view.iterator();349 var iter = view.iterator();
337 while (nextCodepointSliceLossy(&iter)) |sl| {350 while (nextCodepointSliceLossy(&iter)) |sl| {
...@@ -414,6 +427,9 @@ fn contains(haystack: []const string, needle: string) bool {...@@ -414,6 +427,9 @@ fn contains(haystack: []const string, needle: string) bool {
414}427}
415428
416fn 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 {429fn 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
417 if (flag2) {433 if (flag2) {
418 try do(alloc, writer, top, data, ctx, opts);434 try do(alloc, writer, top, data, ctx, opts);
419 } else {435 } else {
...@@ -422,6 +438,9 @@ fn doif(alloc: std.mem.Allocator, writer: anytype, comptime top: astgen.Value, c...@@ -422,6 +438,9 @@ fn doif(alloc: std.mem.Allocator, writer: anytype, comptime top: astgen.Value, c
422}438}
423439
424fn 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 {440fn 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
425 if (flag2) |_| {444 if (flag2) |_| {
426 try do(alloc, writer, top, data, ctx, opts);445 try do(alloc, writer, top, data, ctx, opts);
427 } else {446 } else {
zig.mod+1
...@@ -6,3 +6,4 @@ description: An HTML preprocessor with a builtin template engine....@@ -6,3 +6,4 @@ description: An HTML preprocessor with a builtin template engine.
6dependencies:6dependencies:
7 - src: git https://github.com/kivikakk/htmlentities.zig7 - src: git https://github.com/kivikakk/htmlentities.zig
8 - src: git https://github.com/nektro/zig-extras8 - src: git https://github.com/nektro/zig-extras
9 - src: git https://github.com/nektro/zig-tracer