| ... | ... | @@ -26,7 +26,7 @@ pub fn compile(comptime Ctx: type, alloc: std.mem.Allocator, writer: anytype, co |
| 26 | 26 | try writer.writeAll("\n"); |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | | fn do(comptime Ctx: type, alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype, indent: usize, flag1: bool) anyerror!void { |
| 29 | inline fn do(comptime Ctx: type, alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype, indent: usize, flag1: bool) anyerror!void { |
| 30 | 30 | switch (comptime value) { |
| 31 | 31 | .element => |v| { |
| 32 | 32 | const hastext = for (v.children) |x| { |
| ... | ... | @@ -104,7 +104,7 @@ fn do(comptime Ctx: type, alloc: std.mem.Allocator, writer: anytype, comptime va |
| 104 | 104 | try writer.writeAll(try x.toString(alloc)); |
| 105 | 105 | return; |
| 106 | 106 | } |
| 107 | | @compileError("pek: print: unsupported type: " ++ @typeName(TO)); |
| 107 | @compileError(std.fmt.comptimePrint("pek: print {s}: unsupported type: {s}", .{ v, @typeName(TO) })); |
| 108 | 108 | }, |
| 109 | 109 | .block => |v| { |
| 110 | 110 | const body = astgen.Value{ .body = v.body }; |
| ... | ... | @@ -126,7 +126,7 @@ fn do(comptime Ctx: type, alloc: std.mem.Allocator, writer: anytype, comptime va |
| 126 | 126 | switch (comptime TI) { |
| 127 | 127 | .Bool => try doif(Ctx, alloc, writer, body, bottom, data, ctx, indent, flag1, x), |
| 128 | 128 | .Optional => try docap(Ctx, alloc, writer, body, bottom, data, ctx, indent, flag1, x), |
| 129 | | else => @compileError(comptime std.fmt.comptimePrint("pek: unable to use '{s}' in an #if block", .{@typeName(T)})), |
| 129 | else => @compileError(std.fmt.comptimePrint("pek: unable to use '{s}' in an #if block", .{@typeName(T)})), |
| 130 | 130 | } |
| 131 | 131 | }, |
| 132 | 132 | .ifnot => { |
| ... | ... | @@ -134,7 +134,7 @@ fn do(comptime Ctx: type, alloc: std.mem.Allocator, writer: anytype, comptime va |
| 134 | 134 | switch (comptime TI) { |
| 135 | 135 | .Bool => try doif(Ctx, alloc, writer, body, bottom, data, ctx, indent, flag1, !x), |
| 136 | 136 | .Optional => try docap(Ctx, alloc, writer, body, bottom, data, ctx, indent, flag1, !x), |
| 137 | | else => @compileError(comptime std.fmt.comptimePrint("pek: unable to use '{s}' in an #ifnot block", .{@typeName(T)})), |
| 137 | else => @compileError(std.fmt.comptimePrint("pek: unable to use '{s}' in an #ifnot block", .{@typeName(T)})), |
| 138 | 138 | } |
| 139 | 139 | }, |
| 140 | 140 | .ifequal => { |
| ... | ... | @@ -171,13 +171,13 @@ fn do(comptime Ctx: type, alloc: std.mem.Allocator, writer: anytype, comptime va |
| 171 | 171 | var args: std.meta.ArgsTuple(@TypeOf(func)) = undefined; |
| 172 | 172 | args.@"0" = alloc; |
| 173 | 173 | args.@"1" = list.writer(); |
| 174 | | inline for (v.args) |arg, i| { |
| 174 | inline for (v.args, 0..) |arg, i| { |
| 175 | 175 | const field_name = comptime std.fmt.comptimePrint("{d}", .{i + 2}); |
| 176 | 176 | @field(args, field_name) = if (comptime std.mem.eql(u8, arg[0], "this")) search(arg[1..], data) else search(arg, ctx); |
| 177 | 177 | } |
| 178 | 178 | const repvalue = astgen.Value{ .replacement = .{ .arms = &.{"this"} } }; |
| 179 | | try @call(.{}, func, args); |
| 180 | | try do(Ctx, alloc, writer, repvalue, list.toOwnedSlice(), ctx, indent, flag1); |
| 179 | try @call(.auto, func, args); |
| 180 | try do(Ctx, alloc, writer, repvalue, try list.toOwnedSlice(), ctx, indent, flag1); |
| 181 | 181 | return; |
| 182 | 182 | } |
| 183 | 183 | @compileError("pek: unknown custom function: " ++ v.name); |
| ... | ... | @@ -204,7 +204,7 @@ fn Field(comptime T: type, comptime field_name: string) type { |
| 204 | 204 | return usize; |
| 205 | 205 | } |
| 206 | 206 | inline for (std.meta.fields(T)) |fld| { |
| 207 | | if (std.mem.eql(u8, fld.name, field_name)) return fld.field_type; |
| 207 | if (comptime std.mem.eql(u8, fld.name, field_name)) return fld.type; |
| 208 | 208 | } |
| 209 | 209 | @compileError(std.fmt.comptimePrint("pek: unknown field {s} on type {s}", .{ field_name, @typeName(T) })); |
| 210 | 210 | } |