feat: ast structure and utilities
This commit is contained in:
parent
662c38b360
commit
5268a53148
5 changed files with 970 additions and 5 deletions
23
src/root.zig
23
src/root.zig
|
|
@ -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 {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue