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