Skip to content

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 are lowercase (expr, start) and produce tree nodes.
  • Terminals are UPPERCASE (NUMBER, NAME) and produce tokens.
  • %ignore drops a terminal (whitespace, comments); %import pulls in shared definitions; the ?, !, and _ modifiers change how a rule shapes the tree.
start: NUMBER (OP NUMBER)*
OP: "+" | "-" | "*" | "/"
NUMBER: /[0-9]+/
%ignore " "
import hyperlark as lark
p = lark.Lark(GRAMMAR, parser="lalr")
print(p.parse("1 + 2 * 3").pretty())

The grammar language follows Lark’s grammar reference — hyperlark implements it natively. See the feature matrix for any target-specific notes.