Features
⚡ Fast Generation
Sub-millisecond code generation for typical grammars with linear O(n) scaling.
🔄 ANTLR4 Compatible
100% compatible with ANTLR4 grammar syntax - reuse existing grammars.
🌍 Multi-Language
Generate parsers for Rust, Python, JavaScript, TypeScript, and Go.
🚀 No Runtime Dependencies
Generates standalone, self-contained parsers with no external dependencies.
🦀 Modern Rust
Built with Rust 2024 edition, leveraging latest language features.
✅ Well Tested
111 comprehensive tests covering all core functionality with E2E coverage.
🏷️ Advanced Features
List labels, named actions, parameterized rules, and non-greedy quantifiers.
📝 Real-World Ready
Successfully parses CompleteJSON.g4 and SQL.g4 grammars.
Quick Start
Installation
cargo install minipg
Generate a Parser
# Generate Rust parser
minipg generate grammar.g4 -o output/ -l rust
# Generate Python parser
minipg generate grammar.g4 -o output/ -l python
# Generate Go parser
minipg generate grammar.g4 -o output/ -l go
Example Grammar
grammar Calculator;
expr: term (('+' | '-') term)*;
term: factor (('*' | '/') factor)*;
factor: NUMBER | '(' expr ')';
NUMBER: DIGIT+;
fragment DIGIT: '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
WS: (' ' | '\t' | '\r' | '\n')+ -> skip;
View on GitHub
View on crates.io
Architecture
minipg is organized as a single crate with modular structure for easy installation and maintenance:
Core Modules
- core: Core traits, error types, and diagnostics
- ast: Abstract Syntax Tree definitions and visitor patterns
- parser: Grammar file parser (lexer + parser)
- analysis: Semantic analysis and validation
- codegen: Code generation for Rust, Python, JS, TS, and Go
- CLI: Command-line interface with binary
Key Benefits
- Single package installation - no complex dependency management
- Fast compilation with modular organization
- Clear separation of concerns for maintainability
- Easy to integrate into your projects
Examples
Validate a Grammar
minipg validate grammar.g4
Show Grammar Info
minipg info grammar.g4
Generate with Options
minipg generate grammar.g4 \
--output ./generated \
--target-language rust \
--visitor \
--package my_parser