Initial import: Aji 0.1 draft spec and Zig scaffolding
Draft specification, RFCs, reference registries and examples, plus the reference-implementation skeleton: build.zig, diagnostic envelope with error-code registry synced to docs, aji CLI, conformance runner with seed tests, CI and contributor docs.
This commit is contained in:
commit
17a55a7fef
67 files changed
+4197
No files matched your search
@@ -0,0 +1,95 @@
|
||||
//! `aji` command-line driver.
|
||||
//!
|
||||
//! Output contract (stable, consumed by agents):
|
||||
//! - diagnostics go to stdout as JSON Lines, one object per line;
|
||||
//! - human-oriented notes go to stderr;
|
||||
//! - exit codes: 0 accepted, 1 rejected, 2 usage or I/O error,
|
||||
//! 3 input not decidable yet (pipeline stage unimplemented).
|
||||
|
||||
const std = @import("std");
|
||||
const aji = @import("aji");
|
||||
|
||||
const usage =
|
||||
\\usage: aji <command> [args]
|
||||
\\
|
||||
\\commands:
|
||||
\\ check <file.air> parse and verify a text AIR module
|
||||
\\ codes list diagnostic codes as JSON Lines
|
||||
\\ explain <code> show one diagnostic code
|
||||
\\ version print toolchain version
|
||||
\\
|
||||
;
|
||||
|
||||
const ExitCode = enum(u8) { accepted = 0, rejected = 1, usage = 2, unimplemented = 3 };
|
||||
|
||||
pub fn main(init: std.process.Init) !void {
|
||||
const arena = init.arena.allocator();
|
||||
const io = init.io;
|
||||
const args = try init.minimal.args.toSlice(arena);
|
||||
|
||||
var stdout_buf: [4096]u8 = undefined;
|
||||
var stdout_fw: std.Io.File.Writer = .init(.stdout(), io, &stdout_buf);
|
||||
const out = &stdout_fw.interface;
|
||||
|
||||
const code = run(io, arena, args, out) catch |err| switch (err) {
|
||||
error.WriteFailed => return stdout_fw.err.?,
|
||||
else => |e| return e,
|
||||
};
|
||||
try out.flush();
|
||||
std.process.exit(@backingInt(code));
|
||||
}
|
||||
|
||||
fn run(io: std.Io, arena: std.mem.Allocator, args: []const [:0]const u8, out: *std.Io.Writer) !ExitCode {
|
||||
if (args.len < 2) {
|
||||
std.debug.print("{s}", .{usage});
|
||||
return .usage;
|
||||
}
|
||||
const cmd = args[1];
|
||||
if (std.mem.eql(u8, cmd, "version")) {
|
||||
try out.print("aji {s} (air format {d})\n", .{ aji.version, aji.air.format_version });
|
||||
return .accepted;
|
||||
}
|
||||
if (std.mem.eql(u8, cmd, "codes")) {
|
||||
for (aji.diag.registry) |c| try writeCode(out, c);
|
||||
return .accepted;
|
||||
}
|
||||
if (std.mem.eql(u8, cmd, "explain")) {
|
||||
if (args.len != 3) return usageError("explain takes exactly one code");
|
||||
const c = aji.diag.lookup(args[2]) orelse return usageError("unknown diagnostic code");
|
||||
try writeCode(out, c.*);
|
||||
return .accepted;
|
||||
}
|
||||
if (std.mem.eql(u8, cmd, "check")) {
|
||||
if (args.len != 3) return usageError("check takes exactly one file");
|
||||
const path = args[2];
|
||||
const source = std.Io.Dir.cwd().readFileAlloc(io, path, arena, .limited(64 << 20)) catch |err| {
|
||||
std.debug.print("aji: cannot read {s}: {t}\n", .{ path, err });
|
||||
return .usage;
|
||||
};
|
||||
const report = try aji.check.checkAir(arena, path, source);
|
||||
for (report.diagnostics) |d| {
|
||||
try d.writeJson(out);
|
||||
try out.writeByte('\n');
|
||||
}
|
||||
return switch (report.status) {
|
||||
.accepted => .accepted,
|
||||
.rejected => .rejected,
|
||||
.unimplemented => {
|
||||
std.debug.print("aji: not implemented yet: {s}\n", .{report.missing_stage});
|
||||
return .unimplemented;
|
||||
},
|
||||
};
|
||||
}
|
||||
return usageError("unknown command");
|
||||
}
|
||||
|
||||
fn writeCode(out: *std.Io.Writer, c: aji.diag.Code) !void {
|
||||
var s: std.json.Stringify = .{ .writer = out };
|
||||
try s.write(.{ .code = c.id, .kind = c.kind, .meaning = c.meaning });
|
||||
try out.writeByte('\n');
|
||||
}
|
||||
|
||||
fn usageError(msg: []const u8) ExitCode {
|
||||
std.debug.print("aji: {s}\n\n{s}", .{ msg, usage });
|
||||
return .usage;
|
||||
}
|
||||
Reference in new issue
Block a user