Python
hyperlark is a fast parsing toolkit for Python: write a grammar in the .lark
language and parse it with a native (Rust) engine — no runtime dependencies.
Install
Section titled “Install”pip install hyperlarkYour first parser
Section titled “Your first parser”import hyperlark
parser = hyperlark.Lark(r""" start: "hello" NAME NAME: /\w+/ %ignore " """", parser="lalr")
tree = parser.parse("hello world")print(tree.pretty())Working with the result
Section titled “Working with the result”parse returns a Tree. Walk its .children, read a node’s .data name, and
inspect leaf Tokens: they compare by value (tok == "world") and support the
usual string operations, but — by default (fast_tokens=True) — are not str
subclasses; pass fast_tokens=False for lark-identical str-subclass tokens:
tree = parser.parse("hello world")name = tree.children[0] # Token('NAME', 'world')print(name, name.line, name.column)Transform the tree with the Transformer / Visitor / Interpreter toolkit —
see the transformers guide.
Type checking
Section titled “Type checking”The package ships py.typed, so mypy and pyright read its annotations rather
than falling back to Any. Tree is generic in its leaf type and ParseTree
is Tree[Token], which is the type parse() returns — the same shape lark
uses, so annotations written against lark carry over unchanged:
from hyperlark import Lark, ParseTree, Token
def first_token(tree: ParseTree) -> Token: leaf = tree.children[0] assert isinstance(leaf, Token) return leaf
parser = Lark("start: WORD+\n%import common.WORD\n%ignore \" \"\n")print(first_token(parser.parse("hello world")))Next steps
Section titled “Next steps”- Grammar reference — the
.larkgrammar language. - Transformers & visitors — turn trees into values.
- Feature matrix — what’s supported.
- Alternatives — hyperlark vs lark, sly, parsimonious.