| Crates.io | nolana |
| lib.rs | nolana |
| version | 1.0.0 |
| created_at | 2024-12-13 09:33:19.154786+00 |
| updated_at | 2024-12-13 09:33:19.154786+00 |
| description | An extremely fast parser Molang parser. |
| homepage | |
| repository | https://github.com/arexon/nolana |
| max_upload_size | |
| id | 1482006 |
| size | 256,045 |
Nolana is an extremely fast parser for Molang.
Project goals, in roughly descending priority:
Run just bench to try the benchmarks.
test parser ... bench: 593 ns/iter (+/- 5)
test codegen ... bench: 182 ns/iter (+/- 1)
CPU: Intel Core i5-12400F
Nolana achieves this performance by leveraging logos as its lexer, avoiding unnecessary allocations by using an arena allocator, and ensuring the memory size of each AST node is small.
use nolana::{
allocator::Allocator,
codegen::{Codegen, CodegenOptions},
parser::{Parser, ParserReturn},
semantic::SemanticChecker,
};
let source_text = "math.cos(q.anim_time * 38) * v.rotation_scale + v.x * v.x * q.life_time";
// Create an arena allocator to store the AST nodes.
let allocator = Allocator::default();
// Parse the provided Molang source code.
let ParserReturn {
program,
errors,
panicked,
} = Parser::new(&allocator, source_text).parse();
// Check for syntax errors.
if !errors.is_empty() {
for error in errors {
let error = error.with_source_code(source_text);
print!("{error:?}");
}
if panicked {
println!("Encountered an unrecoverable error");
}
return;
}
// Pretty print the AST.
println!("AST: {:#?}", program);
For more examples, check the examples directory.
Nolana is free and open-source software distributed under the MIT License.