Oak Core
The foundational parser combinator library providing core primitives for building robust parsers in Rust.
🎯 Overview
oak-core is the heart of the Pex ecosystem, offering a comprehensive set of parser combinator primitives that form the building blocks for all language parsers in the collection. It provides both high-level convenience functions and low-level control for custom parsing needs.
✨ Features
- Zero-copy Parsing: Return slices of input without unnecessary allocations
- No-std Support: Works in embedded and kernel environments
- Composable: Combine simple parsers into complex ones
- Error Recovery: Graceful handling of malformed input
- Streaming: Support for incremental parsing of large inputs
- Type Safe: Leverage Rust's type system for parser correctness
🚀 Quick Start
Basic example:
use ;
📋 Parser Combinators
Basic Parsers
any()- Parse any single characterletter()- Parse alphabetic charactersdigit()- Parse numeric digitswhitespace()- Parse whitespacestring("text")- Parse literal stringschar('c')- Parse specific characters
Combinators
parser1.and(parser2)- Sequential parsingparser1.or(parser2)- Alternative parsingmany(parser)- Zero or more repetitionssome(parser)- One or more repetitionsoptional(parser)- Optional parsingbetween(open, close)- Parse between delimiters
Advanced Features
use ;
// Custom parser with error handling
// Recursive parser for nested structures
🔧 Advanced Usage
Custom Error Types
use ;
Zero-allocation Parsing
use *;
// Return slices of input for zero-copy parsing
🏗️ Integration
oak-core is designed to integrate seamlessly with the broader Pex ecosystem:
- Language parsers built on oak-core
- Consistent error handling across all parsers
- Shared utilities and helpers
- Common parsing patterns
📊 Performance
- Zero-copy: Minimize allocations by returning slices
- Streaming: Handle large files without loading entirely into memory
- Lazy: Evaluate parsers only when needed
- Optimized: Fast path for common parsing scenarios
🔗 Related Crates
- pex - Main unified library
- oak-rust - Rust language parser
- oak-json - JSON parser
- oak-highlight - Syntax highlighter
📚 Examples
Check out the examples directory for more comprehensive usage examples:
- Basic parser combinators
- Custom error handling
- Streaming parsers
- Performance optimizations
🤝 Contributing
Contributions are welcome! Please feel free to submit issues or pull requests.
Pex Core - Building the foundation for robust parsing in Rust 🦀