🐷 minipg

A Blazingly Fast Parser Generator with ANTLR4 Compatibility

✅ v0.1.0-alpha.3 📦 Published on crates.io ✅ 111 tests passing 🌍 5 Languages 🔬 E2E tested 📄 Apache-2.0

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

Key Benefits

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

Documentation

📖 User Guide

Getting started with minipg

📝 Grammar Syntax

ANTLR4 grammar reference

🔧 API Documentation

Rust API docs on docs.rs

🌐 Multi-Language

Language support plan

✅ ANTLR4 Compatibility

Compatibility status

📊 Comparison

vs other tools