| ... | ... | @@ -11,6 +11,7 @@ const std = @import("std"); |
| 11 | 11 | const string = []const u8; |
| 12 | 12 | const htmlentities = @import("htmlentities"); |
| 13 | 13 | const root = @import("root"); |
| 14 | const tracer = @import("tracer"); |
| 14 | 15 | |
| 15 | 16 | const tokenize = @import("./tokenize.zig"); |
| 16 | 17 | const astgen = @import("./astgen.zig"); |
| ... | ... | @@ -20,6 +21,9 @@ pub fn parse(comptime input: string) astgen.Value { |
| 20 | 21 | } |
| 21 | 22 | |
| 22 | 23 | pub 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 | 27 | try writer.writeAll("<!DOCTYPE html>\n"); |
| 24 | 28 | try do(alloc, writer, value, data, data, .{ |
| 25 | 29 | .Ctx = Ctx, |
| ... | ... | @@ -30,6 +34,9 @@ pub fn compile(comptime Ctx: type, alloc: std.mem.Allocator, writer: anytype, co |
| 30 | 34 | } |
| 31 | 35 | |
| 32 | 36 | pub 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 | 40 | try do(alloc, writer, value, data, data, opts); |
| 34 | 41 | try writer.writeAll("\n"); |
| 35 | 42 | } |
| ... | ... | @@ -37,6 +44,9 @@ pub fn compileInner(alloc: std.mem.Allocator, writer: anytype, comptime value: a |
| 37 | 44 | pub const Writer = std.ArrayList(u8).Writer; |
| 38 | 45 | |
| 39 | 46 | fn 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 | 50 | switch (comptime value) { |
| 41 | 51 | .element => |v| { |
| 42 | 52 | const hastext = comptime for (v.children) |x| { |
| ... | ... | @@ -332,6 +342,9 @@ fn Field(comptime T: type, comptime field_name: string) type { |
| 332 | 342 | } |
| 333 | 343 | |
| 334 | 344 | pub fn writeEscaped(s: string, writer: anytype) !void { |
| 345 | const t = tracer.trace(@src()); |
| 346 | defer t.end(); |
| 347 | |
| 335 | 348 | const view = std.unicode.Utf8View.initUnchecked(s); |
| 336 | 349 | var iter = view.iterator(); |
| 337 | 350 | while (nextCodepointSliceLossy(&iter)) |sl| { |
| ... | ... | @@ -414,6 +427,9 @@ fn contains(haystack: []const string, needle: string) bool { |
| 414 | 427 | } |
| 415 | 428 | |
| 416 | 429 | 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 { |
| 430 | const t = tracer.trace(@src()); |
| 431 | defer t.end(); |
| 432 | |
| 417 | 433 | if (flag2) { |
| 418 | 434 | try do(alloc, writer, top, data, ctx, opts); |
| 419 | 435 | } else { |
| ... | ... | @@ -422,6 +438,9 @@ fn doif(alloc: std.mem.Allocator, writer: anytype, comptime top: astgen.Value, c |
| 422 | 438 | } |
| 423 | 439 | |
| 424 | 440 | 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 { |
| 441 | const t = tracer.trace(@src()); |
| 442 | defer t.end(); |
| 443 | |
| 425 | 444 | if (flag2) |_| { |
| 426 | 445 | try do(alloc, writer, top, data, ctx, opts); |
| 427 | 446 | } else { |