30 lines
811 B
Zig
30 lines
811 B
Zig
|
const std = @import("std");
|
||
|
|
||
|
const nice = @import("nice");
|
||
|
|
||
|
pub fn main() !void {
|
||
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||
|
defer _ = gpa.deinit();
|
||
|
const allocator = gpa.allocator();
|
||
|
|
||
|
const args = try std.process.argsAlloc(allocator);
|
||
|
defer std.process.argsFree(allocator, args);
|
||
|
if (args.len < 2) return;
|
||
|
|
||
|
const data = try std.fs.cwd().readFileAlloc(allocator, args[1], 4_294_967_295);
|
||
|
var needfree = true;
|
||
|
defer if (needfree) allocator.free(data);
|
||
|
|
||
|
var parser = nice.Parser{ .allocator = allocator };
|
||
|
|
||
|
const document = try parser.parseBuffer(data);
|
||
|
defer document.deinit();
|
||
|
|
||
|
// free data memory to ensure that the parsed document is not holding
|
||
|
// references to it.
|
||
|
allocator.free(data);
|
||
|
needfree = false;
|
||
|
|
||
|
document.printDebug();
|
||
|
}
|