| ... | @@ -114,7 +114,7 @@ fn do(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.Value, d | ... | @@ -114,7 +114,7 @@ fn do(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.Value, d |
| 114 | if (!opts.escaped) try writer.writeAll(s); | 114 | if (!opts.escaped) try writer.writeAll(s); |
| 115 | return; | 115 | return; |
| 116 | } | 116 | } |
| 117 | if (TI == .Int or TI == .Float or TI == .ComptimeInt or TI == .ComptimeFloat) { | 117 | if (TI == .int or TI == .float or TI == .comptime_int or TI == .comptime_float) { |
| 118 | try writer.print("{d}", .{x}); | 118 | try writer.print("{d}", .{x}); |
| 119 | return; | 119 | return; |
| 120 | } | 120 | } |
| ... | @@ -135,7 +135,7 @@ fn do(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.Value, d | ... | @@ -135,7 +135,7 @@ fn do(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.Value, d |
| 135 | if (!opts.escaped) try writer.writeAll(s); | 135 | if (!opts.escaped) try writer.writeAll(s); |
| 136 | return; | 136 | return; |
| 137 | } | 137 | } |
| 138 | if (TI == .Enum) { | 138 | if (TI == .@"enum") { |
| 139 | const s = @tagName(x); | 139 | const s = @tagName(x); |
| 140 | if (opts.escaped) try writeEscaped(s, writer); | 140 | if (opts.escaped) try writeEscaped(s, writer); |
| 141 | if (!opts.escaped) try writer.writeAll(s); | 141 | if (!opts.escaped) try writer.writeAll(s); |
| ... | @@ -157,7 +157,7 @@ fn do(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.Value, d | ... | @@ -157,7 +157,7 @@ fn do(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.Value, d |
| 157 | .@"if" => { | 157 | .@"if" => { |
| 158 | if (v.func) |n| { | 158 | if (v.func) |n| { |
| 159 | const f = @field(opts.Ctx, "pek_" ++ n); | 159 | const f = @field(opts.Ctx, "pek_" ++ n); |
| 160 | const x2 = try switch (@typeInfo(@TypeOf(f)).Fn.params.len) { | 160 | const x2 = try switch (@typeInfo(@TypeOf(f)).@"fn".params.len) { |
| 161 | 2 => f(alloc, x), | 161 | 2 => f(alloc, x), |
| 162 | 3 => blk: { | 162 | 3 => blk: { |
| 163 | const y = try resolveArg(v.args[1], alloc, data, ctx, opts); | 163 | const y = try resolveArg(v.args[1], alloc, data, ctx, opts); |
| ... | @@ -179,16 +179,16 @@ fn do(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.Value, d | ... | @@ -179,16 +179,16 @@ fn do(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.Value, d |
| 179 | return; | 179 | return; |
| 180 | } | 180 | } |
| 181 | switch (comptime TI) { | 181 | switch (comptime TI) { |
| 182 | .Bool => try doif(alloc, writer, body, bottom, data, ctx, opts, x), | 182 | .bool => try doif(alloc, writer, body, bottom, data, ctx, opts, x), |
| 183 | .Optional => try docap(alloc, writer, body, bottom, data, ctx, opts, x), | 183 | .optional => try docap(alloc, writer, body, bottom, data, ctx, opts, x), |
| 184 | .Int => try doif(alloc, writer, body, bottom, data, ctx, opts, x != 0), | 184 | .int => try doif(alloc, writer, body, bottom, data, ctx, opts, x != 0), |
| 185 | else => @compileError(std.fmt.comptimePrint("pek: unable to use '{s}' in an #if block", .{@typeName(T)})), | 185 | else => @compileError(std.fmt.comptimePrint("pek: unable to use '{s}' in an #if block", .{@typeName(T)})), |
| 186 | } | 186 | } |
| 187 | }, | 187 | }, |
| 188 | .ifnot => { | 188 | .ifnot => { |
| 189 | if (v.func) |n| { | 189 | if (v.func) |n| { |
| 190 | const f = @field(opts.Ctx, "pek_" ++ n); | 190 | const f = @field(opts.Ctx, "pek_" ++ n); |
| 191 | const x2 = try switch (@typeInfo(@TypeOf(f)).Fn.params.len) { | 191 | const x2 = try switch (@typeInfo(@TypeOf(f)).@"fn".params.len) { |
| 192 | 2 => f(alloc, x), | 192 | 2 => f(alloc, x), |
| 193 | 3 => blk: { | 193 | 3 => blk: { |
| 194 | const y = try resolveArg(v.args[1], alloc, data, ctx, opts); | 194 | const y = try resolveArg(v.args[1], alloc, data, ctx, opts); |
| ... | @@ -210,16 +210,16 @@ fn do(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.Value, d | ... | @@ -210,16 +210,16 @@ fn do(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.Value, d |
| 210 | return; | 210 | return; |
| 211 | } | 211 | } |
| 212 | switch (comptime TI) { | 212 | switch (comptime TI) { |
| 213 | .Bool => try doif(alloc, writer, body, bottom, data, ctx, opts, !x), | 213 | .bool => try doif(alloc, writer, body, bottom, data, ctx, opts, !x), |
| 214 | .Optional => try docap(alloc, writer, body, bottom, data, ctx, opts, !x), | 214 | .optional => try docap(alloc, writer, body, bottom, data, ctx, opts, !x), |
| 215 | .Int => try doif(alloc, writer, body, bottom, data, ctx, opts, x == 0), | 215 | .int => try doif(alloc, writer, body, bottom, data, ctx, opts, x == 0), |
| 216 | else => @compileError(std.fmt.comptimePrint("pek: unable to use '{s}' in an #ifnot block", .{@typeName(T)})), | 216 | else => @compileError(std.fmt.comptimePrint("pek: unable to use '{s}' in an #ifnot block", .{@typeName(T)})), |
| 217 | } | 217 | } |
| 218 | }, | 218 | }, |
| 219 | .ifequal => { | 219 | .ifequal => { |
| 220 | comptime assertEqual(v.args.len, 2); | 220 | comptime assertEqual(v.args.len, 2); |
| 221 | const y = try resolveArg(v.args[1], alloc, data, ctx, opts); | 221 | const y = try resolveArg(v.args[1], alloc, data, ctx, opts); |
| 222 | if (@typeInfo(@TypeOf(x)) == .Enum and comptime extras.isZigString(@TypeOf(y))) { | 222 | if (@typeInfo(@TypeOf(x)) == .@"enum" and comptime extras.isZigString(@TypeOf(y))) { |
| 223 | return try doif(alloc, writer, body, bottom, data, ctx, opts, std.mem.eql(u8, @tagName(x), y)); | 223 | return try doif(alloc, writer, body, bottom, data, ctx, opts, std.mem.eql(u8, @tagName(x), y)); |
| 224 | } | 224 | } |
| 225 | if (comptime extras.isSlice(@TypeOf(x, y))) { | 225 | if (comptime extras.isSlice(@TypeOf(x, y))) { |
| ... | @@ -230,7 +230,7 @@ fn do(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.Value, d | ... | @@ -230,7 +230,7 @@ fn do(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.Value, d |
| 230 | .ifnotequal => { | 230 | .ifnotequal => { |
| 231 | comptime assertEqual(v.args.len, 2); | 231 | comptime assertEqual(v.args.len, 2); |
| 232 | const y = try resolveArg(v.args[1], alloc, data, ctx, opts); | 232 | const y = try resolveArg(v.args[1], alloc, data, ctx, opts); |
| 233 | if (@typeInfo(@TypeOf(x)) == .Enum and comptime extras.isZigString(@TypeOf(y))) { | 233 | if (@typeInfo(@TypeOf(x)) == .@"enum" and comptime extras.isZigString(@TypeOf(y))) { |
| 234 | return try doif(alloc, writer, body, bottom, data, ctx, opts, !std.mem.eql(u8, @tagName(x), y)); | 234 | return try doif(alloc, writer, body, bottom, data, ctx, opts, !std.mem.eql(u8, @tagName(x), y)); |
| 235 | } | 235 | } |
| 236 | if (comptime extras.isSlice(@TypeOf(x, y))) { | 236 | if (comptime extras.isSlice(@TypeOf(x, y))) { |
| ... | @@ -338,7 +338,7 @@ fn search(comptime args: []const string, ctx: anytype) FieldSearch(@TypeOf(ctx), | ... | @@ -338,7 +338,7 @@ fn search(comptime args: []const string, ctx: anytype) FieldSearch(@TypeOf(ctx), |
| 338 | if (args[0][0] == '"') return std.mem.trim(u8, args[0], "\""); | 338 | if (args[0][0] == '"') return std.mem.trim(u8, args[0], "\""); |
| 339 | if (comptime std.mem.eql(u8, args[0], "true")) return true; | 339 | if (comptime std.mem.eql(u8, args[0], "true")) return true; |
| 340 | if (comptime std.mem.eql(u8, args[0], "false")) return false; | 340 | if (comptime std.mem.eql(u8, args[0], "false")) return false; |
| 341 | if (@typeInfo(@TypeOf(ctx)) == .Optional) return search(args, ctx.?); | 341 | if (@typeInfo(@TypeOf(ctx)) == .optional) return search(args, ctx.?); |
| 342 | const f = @field(ctx, args[0]); | 342 | const f = @field(ctx, args[0]); |
| 343 | if (args.len == 1) return f; | 343 | if (args.len == 1) return f; |
| 344 | return search(args[1..], f); | 344 | return search(args[1..], f); |
| ... | @@ -356,7 +356,7 @@ fn Field(comptime T: type, comptime field_name: string) type { | ... | @@ -356,7 +356,7 @@ fn Field(comptime T: type, comptime field_name: string) type { |
| 356 | return usize; | 356 | return usize; |
| 357 | } | 357 | } |
| 358 | switch (@typeInfo(T)) { | 358 | switch (@typeInfo(T)) { |
| 359 | .Optional => |info| return Field(info.child, field_name), | 359 | .optional => |info| return Field(info.child, field_name), |
| 360 | else => {}, | 360 | else => {}, |
| 361 | } | 361 | } |
| 362 | for (std.meta.fields(T)) |fld| { | 362 | for (std.meta.fields(T)) |fld| { |
| ... | @@ -480,7 +480,7 @@ fn isArrayOf(comptime T: type) fn (type) bool { | ... | @@ -480,7 +480,7 @@ fn isArrayOf(comptime T: type) fn (type) bool { |
| 480 | const Closure = struct { | 480 | const Closure = struct { |
| 481 | pub fn trait(comptime C: type) bool { | 481 | pub fn trait(comptime C: type) bool { |
| 482 | return switch (@typeInfo(C)) { | 482 | return switch (@typeInfo(C)) { |
| 483 | .Array => |ti| ti.child == T, | 483 | .array => |ti| ti.child == T, |
| 484 | else => false, | 484 | else => false, |
| 485 | }; | 485 | }; |
| 486 | } | 486 | } |