🚀 Rust PEG Parser Generator
A lightning-fast Parsing Expression Grammar (PEG) parser generator implemented in Rust. This tool helps you create parsers from grammar definitions with minimal hassle.
📚 Documentation
Full API documentation is available on docs.rs
✨ Features
- Zero-Copy Parsing: Efficient parsing without unnecessary string allocations
- Rich Debugging: Detailed logging for grammar validation and parsing process
- Flexible Grammar Syntax: Supports all standard PEG operators and extensions
- Error Recovery: Robust error handling with detailed diagnostic messages
- Thread-Safe: Designed for concurrent use with thread-safe grammar structures
📦 Installation
Add this to your Cargo.toml:
[]
= "0.1.1"
🚦 Quick Start
Local testing
You must have latest Rust installed.
Go to the project directory and run cargo run --example cmaxes-test.
It will run the PEG grammar specified in src/examples/cmaxes-test.rs file against a sample input.
🔧 Grammar Syntax
The grammar supports these PEG operators:
| Operator | Description | Example |
|---|---|---|
<- |
Definition | rule <- expression |
/ |
Ordered choice | a / b |
* |
Zero or more | [0-9]* |
+ |
One or more | [a-z]+ |
? |
Optional | [A-Z]? |
& |
And-predicate | &[a-z] |
! |
Not-predicate | ![0-9] |
() |
Grouping | (a / b) |
[] |
Character range / class | [abd] and [a-zA-Z] |
. |
Any character | . |
🔍 Debugging
Enable debug logging to see detailed parsing information:
// Initialize logging (using env_logger)
builder
.filter_level
.init;
Or set the environment variable:
RUST_LOG=debug
📚 Examples
Simple Calculator Grammar
let calc_grammar = ;
JSON Parser Grammar
let json_grammar = ;
🤝 Contributing
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- Based on Bryan Ford's Parsing Expression Grammars paper
- Inspired by various PEG implementations in the Rust ecosystem
🌐 Loglan WASM Parser
A web-based interface for the Loglan parser is available in the loglan-wasm-app directory. See the Loglan WASM App README for instructions on how to build and run it.
Built with ❤️ for the Rust community