Skip to main content

Full Moon

Full Moon is a lossless parser for Lua, supporting Lua 5.1, 5.2, 5.3, 5.4, and Luau. Unlike traditional parsers, Full Moon preserves every detail of your source code including comments, whitespace, and style choices.

What Makes Full Moon “Lossless”?

With Full Moon, you can:
  1. Parse Lua code into an Abstract Syntax Tree (AST)
  2. Modify the AST programmatically
  3. Convert it back to valid Lua code exactly as it was written
This means all your formatting preferences, comments, and code style are preserved throughout the transformation process.

Why Use Full Moon?

Static Analysis

Build tools like linters and code quality checkers similar to Luacheck or rust-clippy

Code Formatting

Create automatic code formatters that respect the original structure, similar to rustfmt or Prettier

Code Refactoring

Perform mass code transformations and refactoring operations similar to jscodeshift

Language Tooling

Build LSP servers, type checkers, and other language tools for Lua development

Key Features

Full Moon supports multiple Lua versions through feature flags:
  • Lua 5.1 (default)
  • Lua 5.2
  • Lua 5.3
  • Lua 5.4
  • Luau (Roblox’s Lua dialect)
  • LuaJIT
  • CfxLua (FiveM’s Lua runtime)
Access every part of your code through a comprehensive AST API:
  • Statements and expressions
  • Token references with position information
  • Trivia (whitespace and comments)
  • Function calls, assignments, and control flow
Traverse and transform ASTs using the powerful visitor pattern:
  • Visitor trait for read-only traversal
  • VisitorMut trait for mutable transformations
  • Automatic traversal of all child nodes
Full Moon provides robust error handling:
  • Detailed error messages with position information
  • Partial AST generation for error recovery
  • Both strict and fallible parsing modes

Quick Example

Here’s a taste of what Full Moon can do:
use full_moon::parse;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let ast = parse("local x = 1")?;
    
    // The AST preserves everything about your code
    println!("Parsed: {}", ast);
    
    // Prints: local x = 1
    // Exactly as it was written!
    
    Ok(())
}
Full Moon is heavily inspired by mab and the possibilities enabled by recast.

Next Steps

Installation

Add Full Moon to your Rust project

Quick Start

Parse your first Lua file in minutes

Build docs developers (and LLMs) love