Rantlr
The Modern, Lightweight Parser Generator.
No Java. No Boilerplate. Just Clean Code.
Rantlr turns readable .gr grammars into idiomatic parsers for TypeScript, Python, Go, and Java — powered by a single Rust binary.
Why Rantlr?
- Universal — Generates clean, idiomatic code for TS, Python, Go, Java, and more.
- Fast — Written in Rust. Single binary, minimal host dependencies.
- Modern Syntax —
.grfiles are easier to read than EBNF / ANTLR4. - Smart — Built-in linter with auto-suggestions for common grammar mistakes (including left recursion).
- Zero runtime lock-in — Generated parsers embed a tiny BaseParser helper; copy the folder and go.
Installation
# From crates.io
# From this repository
# Or build locally
# binary: target/release/rantlr
Quick Start (The .gr format)
Create a calculator.gr:
grammar Calculator;
token Num = Number;
token Ws = " " -> skip;
rule expr {
term
repeat {
match "+" | "-"
term
}
}
rule term {
Num
}
example "simple_add" {
input: `1+2`
expect: expr
}
Usage
1. Parse and validate
2. Diagnose (JSON for editors / LSP)
# or: rantlr parse calculator.gr --json # AST on success; diagnostics on failure
3. Generate code
# targets: ts | py | go | java
Project Structure
| Path | Role |
|---|---|
crates/rantlr-core |
Rust engine — Lexer, Parser, Linter, in-process runtime |
crates/rantlr-cli |
Command-line interface (crate rantlr) |
crates/rantlr-gen |
Code generation for TS / Python / Go / Java |
editors/vscode |
Visual Studio Code extension |
playground |
Tauri + React visual debugger |
examples/ |
Sample .gr / .g4 grammars |
docs/ |
Language notes (e.g. left recursion) |
VS Code Extension
# Then: F5 in VS Code, or install the extension from the folder
Features:
- TextMate syntax highlighting for
.gr - On-save diagnostics via
rantlr diagnose(red squiggles) - Quick Fix for left recursion → opens docs/left-recursion.md
Set rantlr.cliPath if the binary is not on PATH (defaults to target/debug/rantlr in the workspace).
Playground (Tauri)
- Left: Monaco editor for the
.grgrammar - Right top: test input
- Right bottom: live parse tree (or error)
- Backend command
analyze_grammarvalidates the grammar and interprets the test input in Rust
.gr vs ANTLR4
| Concept | ANTLR4 | Rantlr |
|---|---|---|
| Repetition | * / + |
repeat { … } |
| Optionality | ? |
optional { … } |
| Choice | a | b |
match a | b |
| Lexer types | Char classes | Number, QuotedString, … |
| Tests | External | example blocks |
Contributing
Rantlr is built for the community. See CONTRIBUTING.md to add new target languages, improve the linter, or extend the playground.
License
MIT — see repository metadata. Author: Roberto de Souza <rabbittrix@hotmail.com>