Skip to content

Rust

Rust is hyperlark’s native engine — the same core the Python, WASM, and C bindings wrap. The hyperlark crate builds grammar tables at runtime (no code generation) and returns a self-describing parse result.

Terminal window
cargo add hyperlark
use hyperlark::Lark;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let lark = Lark::new(
"start: \"hello\" NAME\nNAME: /\\w+/\n%ignore \" \"",
)?;
let result = lark.parse("hello world")?;
println!("{}", result.pretty());
Ok(())
}

Lark::new builds an LALR parser under all-defaults; Lark::lalr / Lark::earley name the engine, and any other option is a field-init LarkOptions passed to Lark::from_lark_source.

parse returns a ParseResult — an owned tree plus the table its ids index. Walk it with a Cursor, or query by name:

let result = lark.parse("hello world")?;
for tok in result.find_token("NAME") {
println!("NAME = {}", tok.value);
}