feat: ast structure and utilities

This commit is contained in:
Brett Broadhurst 2026-02-26 18:46:16 -07:00
parent 662c38b360
commit 5268a53148
Failed to generate hash of commit
5 changed files with 970 additions and 5 deletions

View file

@ -1,15 +1,30 @@
const std = @import("std");
const tokenizer = @import("tokenizer.zig");
pub const Ast = @import("Ast.zig");
pub const Story = struct {
pub const LoadOptions = struct {};
pub const LoadOptions = struct {
stream_writer: *std.Io.Writer,
use_color: bool = true,
};
pub fn loadFromString(
_: std.mem.Allocator,
gpa: std.mem.Allocator,
source_bytes: [:0]const u8,
_: LoadOptions,
options: LoadOptions,
) !Story {
std.debug.print("{s}\n", .{source_bytes});
var ast = try Ast.parse(gpa, source_bytes, "<STDIN>", 0);
defer ast.deinit(gpa);
try ast.render(gpa, options.stream_writer, .{
.use_color = options.use_color,
});
if (ast.errors.len > 0) {
try ast.renderErrors(gpa, options.stream_writer, .{
.use_color = options.use_color,
});
return error.Invalid;
}
return .{};
}
pub fn deinit(_: *Story) void {}