Something went wrong. Try again.
A YAML 1.2.2 parser and emitter for Zig 0.16 with the shape of std.json, built from the spec's grammar.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us>// SPDX-License-Identifier: MIT
//! Prints the events a YAML file parses to, in the yaml-test-suite's//! `test.event` notation, with aliases left unresolved://!//! zig build events -- file.yaml//!//! A syntax error is reported with the line and column the parser got//! furthest to, which is usually where the problem is.
const std = @import("std");const yaml = @import("yaml");const event_format = @import("event_format");
pub fn main(init: std.process.Init) !void { const io = init.io; const gpa = init.gpa;
var args: std.process.Args.Iterator = .init(init.minimal.args); _ = args.skip(); const path = args.next() orelse { std.debug.print("usage: yaml-events FILE\n", .{}); std.process.exit(2); }; const input = try std.Io.Dir.cwd().readFileAlloc(io, path, gpa, .unlimited); defer gpa.free(input);
var stdout_buffer: [4096]u8 = undefined; var stdout_file: std.Io.File.Writer = .init(.stdout(), io, &stdout_buffer); const out = &stdout_file.interface;
var scanner: yaml.Scanner = .initCompleteInput(gpa, input); defer scanner.deinit(); scanner.resolve_aliases = false; var diagnostics: yaml.Diagnostics = .{}; scanner.enableDiagnostics(&diagnostics); while (true) { const ev = scanner.next() catch |err| { try out.flush(); std.debug.print("{s}:{d}:{d}: {t}\n", .{ path, diagnostics.getLine(), diagnostics.getColumn(), err }); std.process.exit(1); }; try event_format.write(out, ev); if (ev == .stream_end) break; } try out.flush();}