| ... | @@ -40,7 +40,7 @@ pub fn compileInner(alloc: std.mem.Allocator, writer: anytype, comptime value: a | ... | @@ -40,7 +40,7 @@ pub fn compileInner(alloc: std.mem.Allocator, writer: anytype, comptime value: a |
| 40 | try do(alloc, writer, value, data, data, opts); | 40 | try do(alloc, writer, value, data, data, opts); |
| 41 | } | 41 | } |
| 42 | | 42 | |
| 43 | pub const Writer = *std.Io.Writer; | 43 | pub const Writer = *nio.AllocatingWriter; |
| 44 | | 44 | |
| 45 | fn do(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype, comptime opts: DoOptions) anyerror!void { | 45 | fn do(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype, comptime opts: DoOptions) anyerror!void { |
| 46 | comptime var skipindent = false; | 46 | comptime var skipindent = false; |
| ... | @@ -303,34 +303,34 @@ fn doInner(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.Val | ... | @@ -303,34 +303,34 @@ fn doInner(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.Val |
| 303 | if (!v.raw) { | 303 | if (!v.raw) { |
| 304 | if (@hasDecl(opts.Ctx, "pek__" ++ v.name)) @compileError("pek: attempted to call raw custom function: '_" ++ v.name ++ "' but did not use '{#" ++ v.name ++ "}'"); | 304 | if (@hasDecl(opts.Ctx, "pek__" ++ v.name)) @compileError("pek: attempted to call raw custom function: '_" ++ v.name ++ "' but did not use '{#" ++ v.name ++ "}'"); |
| 305 | const func = @field(opts.Ctx, "pek_" ++ v.name); | 305 | const func = @field(opts.Ctx, "pek_" ++ v.name); |
| 306 | var list = std.Io.Writer.Allocating.init(alloc); | 306 | var list: nio.AllocatingWriter = .init(alloc); |
| 307 | defer list.deinit(); | 307 | defer list.deinit(); |
| 308 | comptime var types: [v.args.len]type = @splat(void); | 308 | comptime var types: [v.args.len]type = @splat(void); |
| 309 | inline for (v.args, &types) |arg, *T| T.* = ResolveArg(arg, @TypeOf(data), @TypeOf(ctx)); | 309 | inline for (v.args, &types) |arg, *T| T.* = ResolveArg(arg, @TypeOf(data), @TypeOf(ctx)); |
| 310 | var args: std.meta.Tuple(&types) = undefined; | 310 | var args: std.meta.Tuple(&types) = undefined; |
| 311 | inline for (v.args, 0..) |arg, i| args[i] = try resolveArg(arg, alloc, data, ctx, opts); | 311 | inline for (v.args, 0..) |arg, i| args[i] = try resolveArg(arg, alloc, data, ctx, opts); |
| 312 | try @call(.auto, func, .{ alloc, &list.writer } ++ args); | 312 | try @call(.auto, func, .{ alloc, &list } ++ args); |
| 313 | try writeReplacementString(writer, v.raw, opts.escaped, try list.toOwnedSlice()); | 313 | try writeReplacementString(writer, v.raw, opts.escaped, list.items); |
| 314 | return; | 314 | return; |
| 315 | } | 315 | } |
| 316 | if (v.raw) { | 316 | if (v.raw) { |
| 317 | if (@hasDecl(opts.Ctx, "pek_" ++ v.name)) @compileError("pek: attempted to call safe custom function: '" ++ v.name ++ "' but did not use '{" ++ v.name ++ "}'"); | 317 | if (@hasDecl(opts.Ctx, "pek_" ++ v.name)) @compileError("pek: attempted to call safe custom function: '" ++ v.name ++ "' but did not use '{" ++ v.name ++ "}'"); |
| 318 | const func = @field(opts.Ctx, "pek__" ++ v.name); | 318 | const func = @field(opts.Ctx, "pek__" ++ v.name); |
| 319 | var list = std.Io.Writer.Allocating.init(alloc); | 319 | var list: nio.AllocatingWriter = .init(alloc); |
| 320 | defer list.deinit(); | 320 | defer list.deinit(); |
| 321 | const Tup = @typeInfo(@TypeOf(func)).@"fn".params[3].type.?; | 321 | const Tup = @typeInfo(@TypeOf(func)).@"fn".params[3].type.?; |
| 322 | if (@typeInfo(Tup).@"struct".fields.len == 0) { | 322 | if (@typeInfo(Tup).@"struct".fields.len == 0) { |
| 323 | // edge case branch because 'struct {}' is counted as a non-tuple | 323 | // edge case branch because 'struct {}' is counted as a non-tuple |
| 324 | try @call(.auto, func, .{ alloc, &list.writer, opts, Tup{} }); | 324 | try @call(.auto, func, .{ alloc, &list, opts, Tup{} }); |
| 325 | try writeReplacementString(writer, v.raw, opts.escaped, list.written()); | 325 | try writeReplacementString(writer, v.raw, opts.escaped, list.items); |
| 326 | return; | 326 | return; |
| 327 | } | 327 | } |
| 328 | comptime var types: [v.args.len]type = @splat(void); | 328 | comptime var types: [v.args.len]type = @splat(void); |
| 329 | inline for (v.args, &types) |arg, *T| T.* = ResolveArg(arg, @TypeOf(data), @TypeOf(ctx)); | 329 | inline for (v.args, &types) |arg, *T| T.* = ResolveArg(arg, @TypeOf(data), @TypeOf(ctx)); |
| 330 | var args: std.meta.Tuple(&types) = undefined; | 330 | var args: std.meta.Tuple(&types) = undefined; |
| 331 | inline for (v.args, 0..) |arg, i| args[i] = try resolveArg(arg, alloc, data, ctx, opts); | 331 | inline for (v.args, 0..) |arg, i| args[i] = try resolveArg(arg, alloc, data, ctx, opts); |
| 332 | try @call(.auto, func, .{ alloc, &list.writer, opts, args }); | 332 | try @call(.auto, func, .{ alloc, &list, opts, args }); |
| 333 | try writeReplacementString(writer, v.raw, opts.escaped, list.written()); | 333 | try writeReplacementString(writer, v.raw, opts.escaped, list.items); |
| 334 | return; | 334 | return; |
| 335 | } | 335 | } |
| 336 | comptime unreachable; | 336 | comptime unreachable; |
| ... | @@ -353,11 +353,11 @@ fn resolveArg(comptime arg: astgen.Arg, alloc: std.mem.Allocator, data: anytype, | ... | @@ -353,11 +353,11 @@ fn resolveArg(comptime arg: astgen.Arg, alloc: std.mem.Allocator, data: anytype, |
| 353 | .lookup => |av| search(av, ctx), | 353 | .lookup => |av| search(av, ctx), |
| 354 | .int => |av| av, | 354 | .int => |av| av, |
| 355 | .value => |av| { | 355 | .value => |av| { |
| 356 | var list = std.Io.Writer.Allocating.init(alloc); | 356 | var list: nio.AllocatingWriter = .init(alloc); |
| 357 | comptime var newopts = opts; | 357 | comptime var newopts = opts; |
| 358 | newopts.escaped = false; | 358 | newopts.escaped = false; |
| 359 | try do(alloc, &list.writer, astgen.Value{ .body = av }, data, ctx, newopts); | 359 | try do(alloc, &list, astgen.Value{ .body = av }, data, ctx, newopts); |
| 360 | return list.written(); | 360 | return list.items; |
| 361 | }, | 361 | }, |
| 362 | }; | 362 | }; |
| 363 | } | 363 | } |