luaparse-rs
A multi-version Lua parser written in Rust with support for Lua 5.1, 5.2, 5.3, 5.4, and Luau via compile-time version selection.
Features
- Zero-copy parsing with full AST output
- Compile-time version selection; no runtime overhead
no_stdcompatible (withalloc)
Installation
[]
= { = "0.1", = ["luau"] }
Available features: luau (default), lua51, lua52, lua53, lua54
Usage
use ;
let input = r#"
local function greet(name: string): string
return `hello {name}`
end
"#;
let parser = new.unwrap;
let ast = parser.parse.unwrap;
println!;
Switch versions at compile time:
use ;
let parser = new.unwrap;
let ast = parser.parse.unwrap;
AST Traversal
Walk the syntax tree with the visitor traits, or use the quick closures:
use ;
let ast = new.unwrap.parse.unwrap;
ast.for_each_identifier;
For full control, implement Visitor or VisitorMut. See the visitor module docs for examples.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.