#lua #glr #parser

lua_semantics

semantic analysis and enhanced AST converter for lua_parser crate

2 unstable releases

new 0.2.0 Sep 18, 2024
0.1.0 Sep 16, 2024

#1381 in Parser implementations

Download history 137/week @ 2024-09-10

137 downloads per month

MIT/Apache

375KB
10K SLoC

lua_rust

lua syntax parser in Rust

project structure

  • tokenizer: tokenizing lua code string.
  • parser: parsing tokenized lua code into AST.
  • semantics: semantic analysis of generated AST. It generates a Enhanced AST which contains more information than the original AST.
    • stack offset of local variables
    • scope checking for return, break, goto, label, ...
    • split function definition into separated Chunks
  • lua_ir : generate IRs from enhanced AST, and run on virtual machine.

Cargo Features

  • 32bit: use 32bit integer and float for lua numeric type
  • diag: enable to_diag() function for ParseError

how to run

$ cargo run <source_file.lua>

will print the pretty-formatted Debug output of the AST ( "{:#?}" )


lib.rs:

// type of `lua_parser::Block`
let block = lua_parser::parse_str( ... )?;

// semantic analysis, and generate enhanced AST for later use.
let enhanced_ast = lua_semantics::process(block)?;

Dependencies

~1–8MB
~53K SLoC