Lua.AST.PrettyPrinter (Lua v1.0.0-rc.0)
View SourceConverts AST back to Lua source code.
Produces readable, properly indented Lua code from AST structures. Useful for:
- Round-trip testing (parse → print → parse)
- Debugging AST transformations
- Code generation
Examples
ast = Parser.parse("local x = 2 + 2")
code = PrettyPrinter.print(ast)
# => "local x = 2 + 2\n"
# With custom indentation
PrettyPrinter.print(ast, indent: 4)
Summary
Functions
Converts an AST node to Lua source code.
Types
@type ast_node() :: Lua.AST.Chunk.t() | Lua.AST.Block.t() | Lua.AST.Expr.t() | Lua.AST.Statement.t()
@type opts() :: [{:indent, pos_integer()}]