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 - Assignment statement
- LuaBinary
Expression - Binary expression
- LuaCall
Expression - Function call expression
- LuaFunction
Expression - Anonymous function expression
- LuaFunction
Statement - Function definition statement
- LuaIf
Statement - If statement
- LuaIndex
Expression - Index access expression
- LuaLocal
Statement - Local variable declaration
- LuaMember
Expression - Member access expression
- LuaRepeat
Statement - Repeat statement
- LuaReturn
Statement - Return statement
- LuaRoot
- Lua root node
- LuaTable
Constructor - Table constructor
- LuaUnary
Expression - Unary expression
- LuaWhile
Statement - While statement
Enums§
- LuaExpression
- Lua expression
- LuaFor
Statement - For statement
- LuaStatement
- Lua statement
- LuaTable
Field - A field in a Lua table constructor.