I wrote pretty-printing code based on the Zig pretty printer (below).
The compiler is complaining that my Error
type is not including the the some IO error set(s). How do I, generally, figure out the error set in cases like this?
Thanks, Joel
const PPS = pprint.PrettyPrintingStream(ArrayList(u8).Writer);
fn dumpExpr(alloc: Allocator, expr: IR.Expr) Error!void {
const w = std.io.getStdOut().writer();
var bw = std.io.bufferedWriter(w);
const stdout = bw.writer();
var buffer = std.ArrayList(u8).init(alloc);
buffer = std.ArrayList(u8).init(alloc);
var stream = PPS{
.indent_delta = 2,
.w = buffer.writer(),
};
var pp: Printer.PrettyPrinter = .{
.gpa = buffer.allocator,
.pps = &stream,
.tree = undefined,
};
try Printer.printExpr(&pp, expr);
w.writeAll("\n") catch {};
_ = try stdout.write(buffer.items);
try bw.flush();
}
The code…
const PPS = pprint.PrettyPrintingStream(ArrayList(u8).Writer);
fn dumpExpr(alloc: Allocator, expr: IR.Expr) Error!void {
const w = std.io.getStdOut().writer();
var bw = std.io.bufferedWriter(w);
const stdout = bw.writer();
var buffer = std.ArrayList(u8).init(alloc);
buffer = std.ArrayList(u8).init(alloc);
var stream = PPS{
.indent_delta = 2,
.w = buffer.writer(),
};
var pp: Printer.PrettyPrinter = .{
.gpa = buffer.allocator,
.pps = &stream,
.tree = undefined,
};
try Printer.printExpr(&pp, expr);
try w.writeAll("\n");
_ = try stdout.write(buffer.items);
try bw.flush();
}