Lua.AST.PrettyPrinter (Lua v1.0.0-rc.1)

View Source

Converts 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

ast_node()

opts()

@type opts() :: [{:indent, pos_integer()}]

Functions

print(node, opts \\ [])

@spec print(ast_node(), opts()) :: String.t()

Converts an AST node to Lua source code.

Options

  • :indent - Number of spaces per indentation level (default: 2)

Examples

PrettyPrinter.print(ast)
PrettyPrinter.print(ast, indent: 4)