Lua Parser

4.0.0 · active · verified Fri Apr 17

luaparser is a Python library for parsing Lua code into an Abstract Syntax Tree (AST). It provides a programmatic interface to analyze, manipulate, and generate Lua code. The current version is 4.0.0, and it maintains an active, though irregular, release cadence addressing bugs and adding features.

Common errors

Warnings

Install

Imports

Quickstart

Parses a simple Lua script string and prints its Abstract Syntax Tree (AST) representation to the console.

from luaparser import parse

lua_code = """
-- This is a simple Lua script
local function greet(name)
    print("Hello, " .. name .. "!")
end

greet("World")
"""

# Parse the Lua code into an AST
ast = parse(lua_code)

# Print a representation of the AST
# In luaparser 3.3.1+, parse() no longer prints directly
print(ast.show())

view raw JSON →