Expand description
§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
[dependencies]
luaparse-rs = { version = "0.1", features = ["luau"] }Available features: luau (default), lua51, lua52, lua53, lua54
§Usage
use luaparse_rs::{Parser, Luau};
let input = r#"
local function greet(name: string): string
return `hello {name}`
end
"#;
let parser = Parser::<Luau>::new(input).unwrap();
let ast = parser.parse().unwrap();
println!("{:#?}", ast);Switch versions at compile time:
use luaparse_rs::{Parser, Lua54};
let parser = Parser::<Lua54>::new("local x <const> = 5").unwrap();
let ast = parser.parse().unwrap();§AST Traversal
Walk the syntax tree with the visitor traits, or use the quick closures:
use luaparse_rs::{Parser, Luau};
let ast = Parser::<Luau>::new("local x = 1").unwrap().parse().unwrap();
ast.for_each_identifier(|ident| {
println!("{}", ident.name);
});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.
Re-exports§
pub use ast::Ast;pub use ast::AstWithTypes;pub use lexer::InterpolationPart;pub use marker::Lua51;pub use marker::Lua52;pub use marker::Lua53;pub use marker::Lua54;pub use marker::LuaVersion;pub use marker::Luau;pub use parser::Parser;
Modules§
- ast
- The syntax tree types: statements, expressions, types, and the visitor. All the types that make up a parsed Lua syntax tree.
- lexer
- The tokenizer that breaks source text into tokens. Turns source text into a stream of tokens.
- marker
- Lua version markers (
Luau,Lua51,Lua52,Lua53,Lua54). Lua version markers that control which syntax features the parser accepts. - parser
- The parser that turns source code into an
Ast.
Enums§
- LexError
- Something went wrong during lexing (tokenization).
- Parse
Error - Something went wrong while parsing.
Type Aliases§
- Span
- A byte range in the source code (
start..end).