Grammar reference
The grammar language is identical across every target — you write a .lark
grammar once and parse with it from Python, Rust, TypeScript, or C.
Rules and terminals
Section titled “Rules and terminals”- Rules are lowercase (
expr,start) and produce tree nodes. - Terminals are UPPERCASE (
NUMBER,NAME) and produce tokens. %ignoredrops a terminal (whitespace, comments);%importpulls in shared definitions; the?,!, and_modifiers change how a rule shapes the tree.
start: NUMBER (OP NUMBER)*OP: "+" | "-" | "*" | "/"NUMBER: /[0-9]+/%ignore " "The same grammar, every target
Section titled “The same grammar, every target”import hyperlark as larkp = lark.Lark(GRAMMAR, parser="lalr")print(p.parse("1 + 2 * 3").pretty())use hyperlark::Lark;let p = Lark::new(GRAMMAR)?;println!("{}", p.parse("1 + 2 * 3")?.pretty());import { Lark } from "hyperlark";const p = new Lark(GRAMMAR);console.log(p.parse("1 + 2 * 3"));Lark *p = NULL;lark_from_source(GRAMMAR, strlen(GRAMMAR), LARK_OPT_NONE, &p);LarkParseResult *r = NULL;lark_parse(p, "1 + 2 * 3", 9, NULL, &r);Learn more
Section titled “Learn more”The grammar language follows Lark’s grammar reference — hyperlark implements it natively. See the feature matrix for any target-specific notes.