Expand description
AST module.
§Lua Abstract Syntax Tree (AST)
This module defines the high-fidelity, strongly-typed AST for Lua. Built on the Green/Red tree architecture, it provides a lossless representation of the source code.
§🌳 Core Structures
LuaRoot: The entry point of the AST, representing a full Lua chunk or script.Statement: Enum covering all Lua statements (Local, Assignment, Call, If, For, etc.).Expression: Enum for all expression types (TableConstructor, FunctionDefinition, Binary, etc.).TableField: Represents entries in a table constructor, handling both list-style and record-style fields.
§✨ Key Features
- Lossless: Captures all comments and whitespace, making it ideal for formatters and refactoring tools.
- Type-Safe: Provides a convenient API to navigate the tree without manual type casting.
- Incremental Ready: Designed to work with the Oak framework’s partial tree updates.
§🔍 Usage
You can traverse the tree using the TypedNode traits:
let root = result.typed_root::<LuaRoot>();
for stmt in root.statements() {
match stmt {
Statement::Local(l) => println!("Found local: {:?}", l.names()),
_ => {}
}
}Structs§
- LuaAssignment
Statement - 赋值语句
- LuaBinary
Expression - 二元表达式
- LuaCall
Expression - 函数调用表达式
- LuaFunction
Expression - 匿名函数表达式
- LuaFunction
Statement - 函数定义语句
- LuaIf
Statement - If 语句
- LuaIndex
Expression - 索引访问表达式
- LuaLocal
Statement - 本地变量声明
- LuaMember
Expression - 成员访问表达式
- LuaRepeat
Statement - Repeat 语句
- LuaReturn
Statement - 返回语句
- LuaRoot
- Lua 根节点
- LuaTable
Constructor - 表构造器
- LuaUnary
Expression - 一元表达式
- LuaWhile
Statement - While 语句
Enums§
- LuaExpression
- Lua 表达式
- LuaFor
Statement - For 语句
- LuaStatement
- Lua 语句
- LuaTable
Field