#lua #glr #parser

lua_parser

syntax parser for lua language

5 releases (3 breaking)

new 0.4.0 Sep 10, 2024
0.3.0 Sep 9, 2024
0.2.0 Sep 9, 2024
0.1.1 Sep 9, 2024
0.1.0 Sep 8, 2024

#594 in Parser implementations

Download history 709/week @ 2024-09-08

709 downloads per month
Used in lua_semantics

MIT/Apache

390KB
11K SLoC

lua_rust

crates.io docs.rs

lua syntax parser in Rust

project structure

  • tokenizer: tokenizing lua code string
  • parser: parsing tokenized lua code into AST
  • exec: executable version of the parser

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:

let source = " <lua source code> ";

let block = match lua_parser::parse_str(&source) {
    Ok(block) => block,
    Err(err) => {
        println!("{}", err);
        return;
    }
};

println!("AST:\n{:#?}", block);

Dependencies

~1–7.5MB
~50K SLoC