https://github.com/sssooonnnggg/rslua
Yet another Lua lexer and Lua parser for Lua 5.3 written in pure Rust.
https://github.com/sssooonnnggg/rslua
ast handwritten lexer lua parser rust transpiler
Last synced: 7 months ago
JSON representation
Yet another Lua lexer and Lua parser for Lua 5.3 written in pure Rust.
- Host: GitHub
- URL: https://github.com/sssooonnnggg/rslua
- Owner: sssooonnnggg
- Created: 2020-05-10T01:21:55.000Z (over 5 years ago)
- Default Branch: dev
- Last Pushed: 2023-09-24T03:43:26.000Z (about 2 years ago)
- Last Synced: 2025-02-28T03:47:31.814Z (7 months ago)
- Topics: ast, handwritten, lexer, lua, parser, rust, transpiler
- Language: Rust
- Homepage:
- Size: 310 KB
- Stars: 59
- Watchers: 6
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# rslua
[](https://crates.io/crates/rslua)
Yet another Lua lexer and Lua parser for Lua 5.3 written in pure Rust.
## Lexer
- **input** str
- **output** Result, LexError>```rust
use rslua::lexer::Lexer;
let mut lexer = Lexer::default();
let tokens = lexer.run(input_lua_code)?;
```### Lexer Config
| Key | Type | Default | Descripten |
| --- | --- | --- | --- |
| `use_origin_string` | bool | false | Use origin string as token value instead of escaped one. |
| `reserve_comments` | bool | false | Reserve comments as tokens. |## Parser
- **input** Vec\
- **output** Result```rust
let mut parser = Parser::default();
let block = parser.run(tokens)?;
```## AST walker
Use `ast_walker` to travel the AST, implement the `AstVisitor` trait to run custom logic.
## A complete example
Read Lua source files from `./lua` folder, parse them, generate ASTs and walk them through, use a `LuaWritter` struct which impletements the `AstVisitor` trait to re-generate formatted Lua source again to `./tmp` folder.
See [tests/lua_to_lua.rs](tests/lua_to_lua.rs)