authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-08-13 23:06:32 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-08-13 23:06:32 -07:00
log4ee83638fba28b550486a34e5570cb450375538c
tree4c864cc50c816c2c305c6cdd513c8d8d3cec65e2
parentdfe3e182e320f2d6e73a6f4f77ae6517bf755450

add formatting support for numbers


1 files changed, 5 insertions(+), 0 deletions(-)

src/lib.zig+5
...@@ -58,6 +58,7 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype...@@ -58,6 +58,7 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype
58 .replacement => |v| {58 .replacement => |v| {
59 const x = if (comptime std.mem.eql(u8, v[0], "this")) search(v[1..], data) else search(v, ctx);59 const x = if (comptime std.mem.eql(u8, v[0], "this")) search(v[1..], data) else search(v, ctx);
60 const TO = @TypeOf(x);60 const TO = @TypeOf(x);
61 const TI = @typeInfo(TO);
6162
62 if (comptime std.meta.trait.isZigString(TO)) {63 if (comptime std.meta.trait.isZigString(TO)) {
63 const s: []const u8 = x;64 const s: []const u8 = x;
...@@ -70,6 +71,10 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype...@@ -70,6 +71,10 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype
70 }71 }
71 return;72 return;
72 }73 }
74 if (TI == .Int or TI == .Float or TI == .ComptimeInt or TI == .ComptimeFloat) {
75 try writer.print("{d}", .{x});
76 return;
77 }
73 @compileError("pek: print: unsupported type: " ++ @typeName(TO));78 @compileError("pek: print: unsupported type: " ++ @typeName(TO));
74 },79 },
75 .block => |v| {80 .block => |v| {