| ... | @@ -113,6 +113,15 @@ inline fn do(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.V | ... | @@ -113,6 +113,15 @@ inline fn do(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.V |
| 113 | try writer.writeAll(try x.toString(alloc)); | 113 | try writer.writeAll(try x.toString(alloc)); |
| 114 | return; | 114 | return; |
| 115 | } | 115 | } |
| | 116 | if (comptime isArrayOf(u8)(TO)) { |
| | 117 | if (repl.raw) { |
| | 118 | try writer.writeAll(&x); |
| | 119 | return; |
| | 120 | } |
| | 121 | const s = std.mem.trim(u8, &x, "\n"); |
| | 122 | try writeEscaped(s, writer); |
| | 123 | return; |
| | 124 | } |
| 116 | @compileError(std.fmt.comptimePrint("pek: print {s}: unsupported type: {s}", .{ v, @typeName(TO) })); | 125 | @compileError(std.fmt.comptimePrint("pek: print {s}: unsupported type: {s}", .{ v, @typeName(TO) })); |
| 117 | }, | 126 | }, |
| 118 | .block => |v| { | 127 | .block => |v| { |
| ... | @@ -356,3 +365,15 @@ fn docap(alloc: std.mem.Allocator, writer: anytype, comptime top: astgen.Value, | ... | @@ -356,3 +365,15 @@ fn docap(alloc: std.mem.Allocator, writer: anytype, comptime top: astgen.Value, |
| 356 | try do(alloc, writer, bottom, data, ctx, opts); | 365 | try do(alloc, writer, bottom, data, ctx, opts); |
| 357 | } | 366 | } |
| 358 | } | 367 | } |
| | 368 | |
| | 369 | fn isArrayOf(comptime T: type) std.meta.trait.TraitFn { |
| | 370 | const Closure = struct { |
| | 371 | pub fn trait(comptime C: type) bool { |
| | 372 | return switch (@typeInfo(C)) { |
| | 373 | .Array => |ti| ti.child == T, |
| | 374 | else => false, |
| | 375 | }; |
| | 376 | } |
| | 377 | }; |
| | 378 | return Closure.trait; |
| | 379 | } |