| Crates.io | oak-wat |
| lib.rs | oak-wat |
| version | 0.0.1 |
| created_at | 2025-10-21 19:32:08.202297+00 |
| updated_at | 2026-01-23 05:22:26.052603+00 |
| description | WebAssembly Text (WAT) language parser with support for web platform development and portable code generation. |
| homepage | https://github.com/ygg-lang/oaks |
| repository | https://github.com/ygg-lang/oaks |
| max_upload_size | |
| id | 1894327 |
| size | 49,123 |
High-performance incremental WAT (WebAssembly Text) parser for the oak ecosystem with flexible configuration, optimized for WebAssembly text format processing.
Oak WAT is a robust parser for WAT (WebAssembly Text), designed to handle complete WAT syntax including modern specifications. Built on the solid foundation of oak-core, it provides both high-level convenience and detailed AST generation for WebAssembly text format analysis and code generation.
Basic example:
use oak_wat::{Parser, WatLanguage, SourceText};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let parser = Parser::new();
let source = SourceText::new(r#"
(module
(func $add (param $a i32) (param $b i32) (result i32)
local.get $a
local.get $b
i32.add
)
(export "add" (func $add))
)
"#);
let result = parser.parse(&source);
println!("Parsed WAT successfully.");
Ok(())
}
use oak_wat::{Parser, WatLanguage, SourceText};
let parser = Parser::new();
let source = SourceText::new(r#"
(module
(func $multiply (param $a i32) (param $b i32) (result i32)
local.get $a
local.get $b
i32.mul
)
(export "multiply" (func $multiply))
)
"#);
let result = parser.parse(&source);
println!("Module parsed successfully.");
use oak_wat::{Parser, WatLanguage, SourceText};
let parser = Parser::new();
let source = SourceText::new(r#"
(func $factorial (param $n i32) (result i32)
local.get $n
i32.const 1
i32.le_s
if (result i32)
i32.const 1
else
local.get $n
local.get $n
i32.const 1
i32.sub
call $factorial
i32.mul
end
)
"#);
let result = parser.parse(&source);
println!("Function parsed successfully.");
use oak_wat::{Parser, WatLanguage, SourceText};
let parser = Parser::new();
let source = SourceText::new("(module (func $test))");
let result = parser.parse(&source);
println!("Token parsing completed.");
use oak_wat::{Parser, WatLanguage, SourceText};
let parser = Parser::new();
let source = SourceText::new(r#"
(module
(func $invalid
local.get $x
// Missing closing parenthesis
"#);
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 WAT 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.