Nolana
Molang superset with advanced features
Install / Use
/learn @arexon/NolanaREADME
🌺 Nolana
Nolana is an extremely fast parser for Molang.
Project goals, in roughly descending priority:
- Be fully compliant with Molang
- Optimize for speed while maintaining a user-friendly AST
- Ensure the parser can recover from most syntax errors
- Provide extra tools for code generation (printing), simple semantic analysis, and AST traversal
⚡ Performance
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.
📝 Example
use nolana::{semantic::SemanticChecker, Codegen, CodegenOptions, ParseResult, Parser};
let source_text = "math.cos(q.anim_time * 38) * v.rotation_scale + v.x * v.x * q.life_time";
// Parse the provided Molang source code.
let ParseResult { program, errors } = Parser::new(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:?}");
}
return;
}
// Pretty print the AST.
println!("AST: {:#?}", program);
For more info, check the examples directory or read the documentation.
📖 License
Nolana is free and open-source software distributed under the MIT License.
