| Crates.io | oak-zig |
| lib.rs | oak-zig |
| version | 0.0.1 |
| created_at | 2025-10-21 12:32:02.830856+00 |
| updated_at | 2026-01-23 05:38:23.125761+00 |
| description | Zig language parser with support for modern Zig syntax and features. |
| homepage | https://github.com/ygg-lang/oaks |
| repository | https://github.com/ygg-lang/oaks |
| max_upload_size | |
| id | 1893738 |
| size | 64,158 |
High-performance incremental Zig parser for the oak ecosystem with flexible configuration, optimized for static analysis and code generation.
Oak Zig is a robust parser for Zig, designed to handle complete Zig syntax including modern features. Built on the solid foundation of oak-core, it provides both high-level convenience and detailed AST generation for static analysis and code generation.
Basic example:
use oak_zig::{Parser, ZigLanguage, SourceText};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let parser = Parser::new();
let source = SourceText::new(r#"
const std = @import("std");
pub fn main() void {
const message = "Hello, Zig!";
std.debug.print("{s}\n", .{message});
}
"#);
let result = parser.parse(&source);
println!("Parsed Zig successfully.");
Ok(())
}
use oak_zig::{Parser, ZigLanguage, SourceText};
let parser = Parser::new();
let source = SourceText::new(r#"
pub fn add(a: i32, b: i32) i32 {
return a + b;
}
pub fn main() void {
const result = add(5, 3);
std.debug.print("Result: {}\n", .{result});
}
"#);
let result = parser.parse(&source);
println!("Function parsed successfully.");
use oak_zig::{Parser, ZigLanguage, SourceText};
let parser = Parser::new();
let source = SourceText::new(r#"
const Point = struct {
x: f64,
y: f64,
pub fn distance(self: Point, other: Point) f64 {
const dx = self.x - other.x;
const dy = self.y - other.y;
return @sqrt(dx * dx + dy * dy);
}
};
"#);
let result = parser.parse(&source);
println!("Struct parsed successfully.");
use oak_zig::{Parser, ZigLanguage, SourceText};
let parser = Parser::new();
let source = SourceText::new("const x: i32 = 42;");
let result = parser.parse(&source);
println!("Token parsing completed.");
use oak_zig::{Parser, ZigLanguage, SourceText};
let parser = Parser::new();
let source = SourceText::new(r#"
// Invalid Zig code example
pub fn broken_function(
x: i32,
// Missing closing parenthesis and return type
"#);
let result = parser.parse(&source);
if let Some(errors) = result.result.err() {
println!("Parse errors found: {:?}", errors);
} else {
println!("Parsed successfully.");
}
The parser generates a comprehensive AST with the following main structures:
Oak Zig integrates seamlessly with:
Check out the examples directory for comprehensive examples:
Contributions are welcome!
Please feel free to submit pull requests at the project repository or open issues.