Rlex
Rlex is a simple and flexible Rust character walker built for writing lexers and parsers. It supports forward and backward stepping, position marking, peeking, and character stashing.
✨ Features
- Step forward and backward
- Walk with callbacks
- Jump to start, end, or marked positions
- Mark/reset position
- Peek forward and back
- Stash characters and flush
📦 Installation
Add this to your Cargo.toml:
[]
= { = "https://github.com/yourname/rlex" }
Replace
yournamewith your GitHub username or use a path if you're working locally.
🔧 Usage
use Rlex;
🔍 API Overview
Creation
let mut rlex = new.unwrap;
Movement
step_forward()step_back()walk_to_end(|&mut Rlex| -> bool)walk_to_start(|&mut Rlex| -> bool)walk_forward_until(char) -> boolwalk_back_until(char) -> booljump_to_start()jump_to_end()jump_to_mark()
Marking
mark_current_position()mark_reset()
Stashing
stash_current_char()stash_flush() -> Vec<char>stash_use_mark()
Peeking
peek_forward(steps: usize) -> Option<char>peek_back(steps: usize) -> Option<char>
State
at_start() -> boolat_end() -> bool
✅ Running Tests
Run the built-in tests using:
🪪 License
This project is licensed under the MIT License. See LICENSE for details.